Seemingly incorrect behaviour with atomic ops on PowerPC

David Daney ddaney@avtrex.com
Tue May 27 18:14:00 GMT 2008


James Molloy wrote:
> Hi,
>
> I've noticed behaviour which doesn't match that described in the GCC 
> manual for the __sync_bool_compare_and_swap builtin, when operating on 
> objects of type 'bool'.
>
> Take the following test program as an example, tested on a PowerPC 
> ibook with GCC 4.3.0:
>
> int main(int argc, char **argv)
> {
>  bool a = true;
>  // Swap the value 'true' with 'false' and return true on success.
>  bool b = __sync_bool_compare_and_swap(&a, true, false);
>
>  return (b) 2 : 1;
> }
>
> This returns '1' - that is, the compare and swap failed - even there 
> is no reason for it to fail. Interesting to note is that this 
> behaviour is /not/ exhibited on x86, x86_64 or mips32 (the only other 
> platforms I was able to test on), and neither is it exhibited if 
> swapping false with true, for example:
It sounds like a bug.  Please file a bug report as indicated here:
http://gcc.gnu.org/bugs.html

Thanks,
David Daney



More information about the Gcc-help mailing list