[clang] [Clang] Access tls_guard via llvm.threadlocal.address (PR #96633)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 10:14:42 PDT 2024


================
@@ -1059,9 +1059,15 @@ CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
     if (Guard.isValid()) {
       // If we have a guard variable, check whether we've already performed
       // these initializations. This happens for TLS initialization functions.
-      llvm::Value *GuardVal = Builder.CreateLoad(Guard);
-      llvm::Value *Uninit = Builder.CreateIsNull(GuardVal,
-                                                 "guard.uninitialized");
+      Address GuardAddr = Guard;
+      if (auto *GV = dyn_cast<llvm::GlobalValue>(Guard.getPointer()))
----------------
rjmccall wrote:

Then you should pass down whether this is for TLS.

What I'm trying to avoid is some situation where we silently don't emit the intrinsic for a thread local because the guard address we pass in is not directly a `GlobalValue`.

https://github.com/llvm/llvm-project/pull/96633


More information about the cfe-commits mailing list