Skip to content

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

Description

@kirbyzhou

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."

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions