http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52291
Bug #: 52291
Summary: __sync_fetch_and_add and friends poorly specified for
pointer types
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected]
Host: powerpc64-unknown-linux-gnu
Target: powerpc64-unknown-linux-gnu
The documentation states, regarding the __sync_fetch_and_X builtins:
These builtins perform the operation suggested by the name, and returns the
value that had previously been in memory. That is,
{ tmp = *ptr; *ptr op= value; return tmp; }
{ tmp = *ptr; *ptr = ~(tmp & value); return tmp; } // nand
For pointer types (which GCC accepts for these builtins) the "operation
suggested by the name" leans toward pointer arithmetic; however, the pointer
types are not suitable for these operations in C/C++.