[clang] [CIR] Fix 'vague' linkage globals. (PR #228586)

Kunal Dubey via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 7 01:06:24 PDT 2026


================
@@ -1262,6 +1277,26 @@ LoweringPreparePass::buildCXXGlobalVarDeclInitFunc(cir::GlobalOp op) {
   // If this is a global TLS variable (that is, declared at namespace scope), we
   // have to emit the guard variable here.
   bool needsTlsGuard = op.getTlsRefs() && op.getTlsRefs()->getGuardName();
+
+  // Non-TLS globals (such as weak/linkonce_odr/inline-ns scope variables) use
+  // the __cxa_guard_acquire/release instead of the TLS guard.
+  if (!needsTlsGuard && op.getDynamicInitGuard()) {
+    if (!op.getDynamicInitInfo()) {
+      op->emitError(
+          "guarded global with a guard is missing 'dynamic_init_info'");
+      return {};
+    }
+
+    if (op.getDynamicInitInfo()->getLocal()) {
+      op->emitError("guarded global is marked local");
+      return {};
+    }
+    emitGuardedInit(builder, op, op.getCtorRegion(), op.getDtorRegion());
----------------
xakep8 wrote:

emitGuardedInit retains the hasOneBlock() assumptions from the LocalInitOp path, but GlobalOp ctor/dtor regions are AnyRegion.

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


More information about the cfe-commits mailing list