Commit ed6f9fb9 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

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
parent bc95fedc
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment