https://github.com/aokblast created 
https://github.com/llvm/llvm-project/pull/235229

OSes like FreeBSD support clang-rapl but doesn't provide emutls implementation. 
In this case, the test fails to run. To fix it, we detect thread local and set 
a new flag.

>From 7f43291c07d7b322c1bf9cfaa13bd43ded295e9e Mon Sep 17 00:00:00 2001
From: ShengYi Hung <[email protected]>
Date: Sat, 24 Oct 2026 13:56:22 +0800
Subject: [PATCH] [Clang] Detect emutls separately

OSes like FreeBSD support clang-rapl but doesn't provide emutls
implementation. In this case, the test fails to run. To fix it, we
detect thread local and set a new flag.
---
 clang/test/Interpreter/emulated-tls.cpp |  4 ++++
 clang/test/lit.cfg.py                   | 32 +++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/clang/test/Interpreter/emulated-tls.cpp 
b/clang/test/Interpreter/emulated-tls.cpp
index bd80b65957ee39..f258864494b1a1 100644
--- a/clang/test/Interpreter/emulated-tls.cpp
+++ b/clang/test/Interpreter/emulated-tls.cpp
@@ -4,6 +4,10 @@
 // Emulated TLS is not supported by the LoongArch backend.
 // UNSUPPORTED: target=loongarch{{.*}}
 //
+// Some hosts have no __emutls_get_address at all (its compiler runtime does 
not
+// ship one), so no thread_local can execute in clang-repl there.
+// REQUIRES: host-supports-jit-thread-local
+//
 // An inline function that odr-uses a non-zero-initialized thread_local is
 // emitted as a weak (linkonce_odr) definition into every 
PartialTranslationUnit
 // that references it. With emulated TLS that set includes an __emutls_t.<var>
diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index af3144f3ddcf93..d4942471baa439 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -194,6 +194,34 @@ def run_clang_repl(args):
 def have_host_jit_feature_support(feature_name):
     return "true" in run_clang_repl("--host-supports-" + feature_name)
 
+
+def have_host_clang_repl_thread_local():
+    clang_repl_exe = lit.util.which("clang-repl", config.clang_tools_dir)
+
+    if not clang_repl_exe:
+        return False
+
+    testcode = b"\n".join(
+        [
+            b'extern "C" int puts(const char *s);',
+            b"thread_local int tl = 42;",
+            b'puts(tl == 42 ? "success" : "failure");',
+            b"%quit",
+        ]
+    )
+    try:
+        clang_repl_cmd = subprocess.run(
+            [clang_repl_exe],
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+            input=testcode,
+        )
+    except OSError:
+        return False
+
+    return clang_repl_cmd.returncode == 0 and b"success" in 
clang_repl_cmd.stdout
+
+
 def have_host_clang_repl_cuda():
     clang_repl_exe = lit.util.which('clang-repl', config.clang_tools_dir)
 
@@ -234,6 +262,10 @@ def have_host_clang_repl_cuda():
 
     if have_host_clang_repl_cuda():
         config.available_features.add('host-supports-cuda')
+
+    if have_host_clang_repl_thread_local():
+        config.available_features.add("host-supports-jit-thread-local")
+
     hosttriple = run_clang_repl("--host-jit-triple")
     config.available_features.add("host-jit-triple=" + hosttriple.strip())
     config.substitutions.append(("%host-jit-triple", hosttriple.strip()))

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to