aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorJessica Clarke <jrtc27@jrtc27.com>2025-05-14 21:51:56 +0100
committerGitHub <noreply@github.com>2025-05-14 21:51:56 +0100
commit864f0ff4efc220609764a3075c289b395dc9b907 (patch)
treeaaef12f61e23f9431d3ab1e672cf027eb8af6154 /clang
parent0ab67ec191673a148d84f3819f5c97aaa5b84364 (diff)
downloadllvm-864f0ff4efc220609764a3075c289b395dc9b907.zip
llvm-864f0ff4efc220609764a3075c289b395dc9b907.tar.gz
llvm-864f0ff4efc220609764a3075c289b395dc9b907.tar.bz2
[clang][IR] Overload @llvm.thread.pointer to support non-AS0 targets (#132489)
Thread-local globals live, by default, in the default globals address space, which may not be 0, so we need to overload @llvm.thread.pointer to support other address spaces, and use the default globals address space in Clang.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp5
-rw-r--r--clang/test/CodeGen/builtins-arm64.c2
-rw-r--r--clang/test/CodeGen/builtins-wasm.c2
3 files changed, 5 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4fdf211..48cfbda 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6115,8 +6115,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__builtin_thread_pointer: {
if (!getContext().getTargetInfo().isTLSSupported())
CGM.ErrorUnsupported(E, "__builtin_thread_pointer");
- // Fall through - it's already mapped to the intrinsic by ClangBuiltin.
- break;
+
+ return RValue::get(Builder.CreateIntrinsic(llvm::Intrinsic::thread_pointer,
+ {GlobalsInt8PtrTy}, {}));
}
case Builtin::BI__builtin_os_log_format:
return emitBuiltinOSLogFormat(*E);
diff --git a/clang/test/CodeGen/builtins-arm64.c b/clang/test/CodeGen/builtins-arm64.c
index 0913295..86c2812 100644
--- a/clang/test/CodeGen/builtins-arm64.c
+++ b/clang/test/CodeGen/builtins-arm64.c
@@ -10,7 +10,7 @@ void f0(void *a, void *b) {
void *tp (void) {
return __builtin_thread_pointer ();
-// CHECK-LINUX: call {{.*}} @llvm.thread.pointer()
+// CHECK-LINUX: call {{.*}} @llvm.thread.pointer.p0()
}
// CHECK: call {{.*}} @llvm.bitreverse.i32(i32 %a)
diff --git a/clang/test/CodeGen/builtins-wasm.c b/clang/test/CodeGen/builtins-wasm.c
index 4a44a9a..d8aff82 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -749,5 +749,5 @@ int externref_is_null(__externref_t arg) {
void *tp (void) {
return __builtin_thread_pointer ();
- // WEBASSEMBLY: call {{.*}} @llvm.thread.pointer()
+ // WEBASSEMBLY: call {{.*}} @llvm.thread.pointer.p0()
}