[PATCH] Add __sync_fetch_and_nand (again)

hfinkel at anl.gov hfinkel at anl.gov
Sun Sep 21 10:00:02 PDT 2014


Hi rsmith,

Prior to GCC 4.4, __sync_fetch_and_nand was implemented as:
  { tmp = *ptr; *ptr = ~tmp & value; return tmp; }
but this was changed in GCC 4.4 to be:
  { tmp = *ptr; *ptr = ~(tmp & value); return tmp; }

in response to this change, support for __sync_fetch_and_nand (and __sync_nand_and_fetch) was removed in r99522 in order to avoid miscompiling code depending on the old semantics. However, at this point:
 1. Many years have passed, and the amount of code relying on the old semantics is likely smaller
 2. Through the work of many contributors, all LLVM backends have been updated such that "atomicrmw nand" provides the newer GCC 4.4+ semantics (this process was complete July of 2014 (added to the release notes in r212635).
 3. The lack of this intrinsic is now a needless impediment to porting codes from GCC to Clang (I've now seen several examples of this).

It is true, however, that we still set __GNUC_MINOR__ to 2 (corresponding to GCC 4.2). To compensate for this, and to address the original concern regarding code relying on the old semantics, I've added a warning in this patch that specifically details the fact that the semantics have changed and that we provide the newer semantics.

Fixes PR8842.

Please review and thanks again!

http://reviews.llvm.org/D5429

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/Atomics.c
  test/CodeGen/atomic.c
  test/Sema/builtins.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5429.13911.patch
Type: text/x-patch
Size: 15934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140921/a4b43c7f/attachment.bin>


More information about the cfe-commits mailing list