http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58490
Bug ID: 58490 Summary: __sync_bool_compare_and_swap sign bit failure Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: erikvanderwerf at gmail dot com The following lines cause an assertion failure on my arm device: unsigned short int x=0x8000; unsigned short int y=1; // or any other number char success = __sync_bool_compare_and_swap(&x, x, y); assert( success ); // ok assert( (x==y) ); // this fails when the highest bit in x is set Using signed short int with negative numbers produces the same error. Using older versions of gcc (e.g., 4.6) or when compiling for x86 it runs without problems. I compiled using 'arm-linux-gnueabi-gcc-4.7 -Wall -static'. Here are some details: >> arm-linux-gnueabi-gcc-4.7 --version arm-linux-gnueabi-gcc-4.7 (Debian 4.7.2-4) 4.7.2