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

via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 00:48:30 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()))
----------------
nikola-tesic-ns wrote:

There is a code pattern where this "guarded initialization" is done for non-TLS var ([partitions.cpp test](https://github.com/nextsilicon/next-llvm-project/blob/b36811cc9baf1c72de2fa1c8b5d8fc30bae9a15c/clang/test/CodeGenCXX/partitions.cpp)). That's the reason I've introduced these checks.

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


More information about the cfe-commits mailing list