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."
As It mentiond in https://bugzilla.redhat.com/show_bug.cgi?id=2109065
This code fragment will become wrong assembly with "gcc -O2".
The buggy assembly like:
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."