[clang] [CIR] Implement 'referenced-by-subobject' static-local lowering (PR #194070)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 24 19:01:38 PDT 2026


================
@@ -1008,10 +1008,20 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
     auto iter = localDeclMap.find(vd);
     if (iter != localDeclMap.end()) {
       addr = iter->second;
-    } else {
+
+    } else if (vd->isStaticLocal()) {
       // Otherwise, it might be static local we haven't emitted yet for some
       // reason; most likely, because it's in an outer function.
-      cgm.errorNYI(e->getSourceRange(), "emitDeclRefLValue: static local");
+      cir::GlobalOp var =
+          cgm.getOrCreateStaticVarDecl(*vd, cgm.getCIRLinkageVarDefinition(vd));
+      mlir::Value getGlobVal = builder.createGetGlobal(var);
+      auto getGlob = getGlobVal.getDefiningOp<cir::GetGlobalOp>();
+      getGlob.setStaticLocal(true);
----------------
erichkeane wrote:

Oh, hrmph... i shoulda used that repro as well, I'll add that one, and set that correctly.

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


More information about the cfe-commits mailing list