[commit: ghc] master: ghc-prim: Reduce scope of Clang sync_fetch_and_nand workaround (ed6f9fb)

git at git.haskell.org git at git.haskell.org
Thu Mar 8 22:05:40 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/ed6f9fb9d5a684d2159c29633159c3254cf04deb/ghc

>---------------------------------------------------------------

commit ed6f9fb9d5a684d2159c29633159c3254cf04deb
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Thu Mar 8 13:22:22 2018 -0500

    ghc-prim: Reduce scope of Clang sync_fetch_and_nand workaround
    
    As described in https://bugs.llvm.org/show_bug.cgi?id=8842, Clang
    removed the __sync_fetch_and_nand builtins due to inconsistency in GCC's
    behavior in 2010.  However, GCC has since clarified the behavior of
    their builtins and consequently Clang re-added them in 2014.
    Consequently this workaround should no longer be necessary.
    
    Test Plan: Validate building with Clang
    
    Subscribers: rwbarton, thomie, carter
    
    Differential Revision: https://phabricator.haskell.org/D4480


>---------------------------------------------------------------

ed6f9fb9d5a684d2159c29633159c3254cf04deb
 libraries/ghc-prim/cbits/atomic.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libraries/ghc-prim/cbits/atomic.c b/libraries/ghc-prim/cbits/atomic.c
index 2ded465..722d261 100644
--- a/libraries/ghc-prim/cbits/atomic.c
+++ b/libraries/ghc-prim/cbits/atomic.c
@@ -117,11 +117,16 @@ hs_atomic_and64(StgWord x, StgWord64 val)
     return tmp;                                                     \
   }
 
+// This is only provided by clang
+#if !defined(__has_builtin)
+#define __has_builtin(x) 0
+#endif
+
 extern StgWord hs_atomic_nand8(StgWord x, StgWord val);
 StgWord
 hs_atomic_nand8(StgWord x, StgWord val)
 {
-#ifdef __clang__
+#if defined(__clang__) && __has_builtin(__sync_fetch_and_nand)
   CAS_NAND((volatile StgWord8 *) x, (StgWord8) val)
 #else
   return __sync_fetch_and_nand((volatile StgWord8 *) x, (StgWord8) val);
@@ -132,7 +137,7 @@ extern StgWord hs_atomic_nand16(StgWord x, StgWord val);
 StgWord
 hs_atomic_nand16(StgWord x, StgWord val)
 {
-#ifdef __clang__
+#if defined(__clang__) && __has_builtin(__sync_fetch_and_nand)
   CAS_NAND((volatile StgWord16 *) x, (StgWord16) val);
 #else
   return __sync_fetch_and_nand((volatile StgWord16 *) x, (StgWord16) val);
@@ -143,7 +148,7 @@ extern StgWord hs_atomic_nand32(StgWord x, StgWord val);
 StgWord
 hs_atomic_nand32(StgWord x, StgWord val)
 {
-#ifdef __clang__
+#if defined(__clang__) && __has_builtin(__sync_fetch_and_nand)
   CAS_NAND((volatile StgWord32 *) x, (StgWord32) val);
 #else
   return __sync_fetch_and_nand((volatile StgWord32 *) x, (StgWord32) val);
@@ -155,7 +160,7 @@ extern StgWord64 hs_atomic_nand64(StgWord x, StgWord64 val);
 StgWord64
 hs_atomic_nand64(StgWord x, StgWord64 val)
 {
-#ifdef __clang__
+#if defined(__clang__) && __has_builtin(__sync_fetch_and_nand)
   CAS_NAND((volatile StgWord64 *) x, val);
 #else
   return __sync_fetch_and_nand((volatile StgWord64 *) x, val);



More information about the ghc-commits mailing list