[compiler-rt] [tsan] Enable __TSAN_HAS_INT128 on s390x and mips64 (PR #197319)

Mauri de Souza Meneguzzo via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 06:30:02 PDT 2026


https://github.com/mauri870 updated https://github.com/llvm/llvm-project/pull/197319

>From f7a2fb7f7cda6424dfe2fb67682f469e56dc7e67 Mon Sep 17 00:00:00 2001
From: Mauri de Souza Meneguzzo <mauri870 at gmail.com>
Date: Tue, 12 May 2026 19:27:09 -0300
Subject: [PATCH 1/2] [tsan] Enable __TSAN_HAS_INT128 on s390x and mips64

The s390x exclusion was added in b17673816d7f (https://reviews.llvm.org/D105629)
citing lack of hardware 128-bit atomics. s390x does have the CDSG instruction,
but alignof(__int128) == 8 on the s390x psABI while CDSG requires 16-byte
alignment, so Clang does not define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 for
this target. The mips64 exclusion has been present since __TSAN_HAS_INT128 was
introduced in 06bbca9ec4bb (https://reviews.llvm.org/D18543) with no documented
rationale. Clang similarly does not define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
for mips64.

Both exclusions are unnecessary. When __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 is
not defined, all a128 operations use the SpinMutex-based emulation path, which
serializes 128-bit accesses under a global lock without requiring any hardware
CAS16 support.

Verified with Clang (targets: s390x-linux-gnu, mips64-linux-gnuabi64,
mips64el-linux-gnuabi64): all three produce the full set of 12
__tsan_atomic128_* symbols with zero __sync_*_16 / __atomic_*_16
libcall references.

Runtime testing has not been performed as I lack access to these architectures.
---
 compiler-rt/lib/tsan/rtl/tsan_interface.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/compiler-rt/lib/tsan/rtl/tsan_interface.h b/compiler-rt/lib/tsan/rtl/tsan_interface.h
index db94cf48f9c2d..b44f873406700 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interface.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_interface.h
@@ -209,8 +209,7 @@ typedef unsigned int a32;
 typedef unsigned long long a64;
 #if !SANITIZER_GO &&                                      \
     (defined(__SIZEOF_INT128__) ||                        \
-     (__clang_major__ * 100 + __clang_minor__ >= 302)) && \
-    !defined(__mips64) && !defined(__s390x__)
+     (__clang_major__ * 100 + __clang_minor__ >= 302))
 __extension__ typedef __int128 a128;
 #  define __TSAN_HAS_INT128 1
 #else

>From 836536a4fefebfc1a58dc5a0d25ed314e5d3b4c3 Mon Sep 17 00:00:00 2001
From: Mauri de Souza Meneguzzo <mauri870 at gmail.com>
Date: Tue, 12 May 2026 19:41:23 -0300
Subject: [PATCH 2/2] linter changes

---
 compiler-rt/lib/tsan/rtl/tsan_interface.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/tsan/rtl/tsan_interface.h b/compiler-rt/lib/tsan/rtl/tsan_interface.h
index b44f873406700..36cf080079554 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interface.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_interface.h
@@ -207,9 +207,8 @@ typedef unsigned char a8;
 typedef unsigned short a16;
 typedef unsigned int a32;
 typedef unsigned long long a64;
-#if !SANITIZER_GO &&                                      \
-    (defined(__SIZEOF_INT128__) ||                        \
-     (__clang_major__ * 100 + __clang_minor__ >= 302))
+#if !SANITIZER_GO && (defined(__SIZEOF_INT128__) || \
+                      (__clang_major__ * 100 + __clang_minor__ >= 302))
 __extension__ typedef __int128 a128;
 #  define __TSAN_HAS_INT128 1
 #else



More information about the llvm-commits mailing list