Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NonRecursiveRWLock::unlockWriter is broken with gcc-11 #13

Open
kirbyzhou opened this issue Jul 21, 2022 · 1 comment
Open

NonRecursiveRWLock::unlockWriter is broken with gcc-11 #13

kirbyzhou opened this issue Jul 21, 2022 · 1 comment

Comments

@kirbyzhou
Copy link

As It mentiond in https://bugzilla.redhat.com/show_bug.cgi?id=2109065

            assert(oldStatus.readers == 0);
            newStatus = oldStatus;
            newStatus.writers--;
            waitToRead = oldStatus.waitToRead;
            if (waitToRead > 0)
            {
                newStatus.waitToRead = 0;
                newStatus.readers = waitToRead;
            }

This code fragment will become wrong assembly with "gcc -O2".

The buggy assembly like:

mov    %eax,%edx
lea    -0x100000(%rax),%ecx
and    $0xfff00000,%eax
shr    $0xa,%edx
and    $0x3ff,%edx
or     %edx,%eax
test   %edx,%edx
cmove  %ecx,%eax

So if waitToRead>0 then newStatus.writers will not be changed.

Somebody said "so this union(Status) has 4 members. [class.union] says that "At most one of the
non-static data members of an object of union type can be active at any time,
that is, the value of at most one of the non-static data members can be stored
in a union at any time."

@kirbyzhou
Copy link
Author

I suggest just drop the bitfield wrappers to avoid the trouble of the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant