From: LLVM Packaging Team Date: Fri, 13 Oct 2017 19:20:24 +0000 (+0100) Subject: clang-fix-cmpxchg8-detection-on-i386 X-Git-Tag: archive/raspbian/1%5.0.1-2+rpi1^2^2^2~8 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=e1c30c1b691fba798b076e57a183d890e84a0e0e;p=llvm-toolchain-5.0.git clang-fix-cmpxchg8-detection-on-i386 libcxx atomic tests for old i386 fail with wrong Atomic inline width. cmpxchg8b instruction is required for 8 byte atomics that clang was assuming. Too bad _GCC_ATOMIC_LLONG_LOCK_FREE 2 isn't supported even with this change because llvm doesn't support unaligned atomic compare and exchange operation. Fallback calls to libatomic.so should handle long long lock free but clang can't tell program if libatomic is always lock free. Related bug: https://llvm.org/bugs/show_bug.cgi?id=19355 Gbp-Pq: Name clang-fix-cmpxchg8-detection-on-i386.patch --- diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 35d02379c..e9965e1f0 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -2952,7 +2952,10 @@ class X86TargetInfo : public TargetInfo { FP_SSE, FP_387 } FPMath = FP_Default; - +protected: + bool isCmpXChg8Supported() const { + return CPU >= CK_i586; + } public: X86TargetInfo(const llvm::Triple &Triple, const TargetOptions &) : TargetInfo(Triple) { @@ -3073,6 +3076,8 @@ public: // acceptable. // FIXME: This results in terrible diagnostics. Clang just says the CPU is // invalid without explaining *why*. + if (!isCmpXChg8Supported()) + MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32; switch (CPU) { case CK_Generic: // No processor selected! @@ -4232,7 +4237,7 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2"); Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4"); } - if (CPU >= CK_i586) + if (isCmpXChg8Supported()) Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8"); if (HasFloat128) @@ -4538,8 +4543,6 @@ public: (1 << TargetInfo::LongDouble)); // x86-32 has atomics up to 8 bytes - // FIXME: Check that we actually have cmpxchg8b before setting - // MaxAtomicInlineWidth. (cmpxchg8b is an i586 instruction.) MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; } BuiltinVaListKind getBuiltinVaListKind() const override {