[clang] [CIR] Materialize AST-derived facts as CIR attributes (PR #215921)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 13 16:48:47 PDT 2026


================
@@ -265,7 +265,18 @@ void CIRGenModule::emitCXXSpecialVarDeclInit(const VarDecl *varDecl,
   // expects "this" in the "generic" address space.
   assert(!cir::MissingFeatures::addressSpace());
 
-  addr.setAstAttr(cir::ASTVarDeclAttr::get(&getMLIRContext(), varDecl));
+  // LoweringPrepare reads VarDecl facts back through ASTVarDeclInterface, but
+  // only for static-local guarded globals. For those, emit the materialized
+  // StaticLocalInfoAttr so the facts survive without a live ASTContext (e.g.
+  // serialized CIR in split-compilation flows). Other globals keep the
+  // AST-backed attribute; their $ast is never queried after CIRGen.
+  if (addr.getStaticLocalGuard().has_value())
+    addr.setAstAttr(cir::StaticLocalInfoAttr::get(
+        &getMLIRContext(), varDecl->isLocalVarDecl(),
+        static_cast<uint32_t>(varDecl->getTLSKind()), varDecl->isInline(),
+        static_cast<uint32_t>(varDecl->getTemplateSpecializationKind())));
+  else
+    addr.setAstAttr(cir::ASTVarDeclAttr::get(&getMLIRContext(), varDecl));
----------------
bcardosolopes wrote:

This should be set anyways, we have a new attribute that is now orthogonal on whether the AST is attached (other users might want to look at other AST properties you didn't add in the new attribute).

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


More information about the cfe-commits mailing list