================
@@ -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()))
+        // Get the thread-local address via intrinsic.
+        if (GV->isThreadLocal())
+          GuardAddr = GuardAddr.withPointer(
+              Builder.CreateThreadLocalAddress(GV), NotKnownNonNull);
+      llvm::Value *GuardVal = Builder.CreateLoad(GuardAddr);
----------------
ChuanqiXu9 wrote:

These lines are not changed. So we'd better to not touch them.

https://github.com/llvm/llvm-project/pull/96633
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to