[clang] [CIR] Keep CIR global types visible across lowering replacements (PR #238698)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 5 17:34:33 PST 2026


================
@@ -1079,7 +1082,15 @@ CIRAttrToValue::getAddressOfSymbol(mlir::FlatSymbolRefAttr symbol) {
   mlir::Operation *sourceSymbol =
       symbolTables.lookupSymbolIn(parentModule, symbol);
   if (auto llvmSymbol = dyn_cast<mlir::LLVM::GlobalOp>(sourceSymbol)) {
-    sourceType = llvmSymbol.getType();
+    // Prefer the pre-conversion type: the LLVM global's type may have been
+    // adjusted (split rows, flexible array).
+    if (mlir::Type preType =
+            preConversionTypes.lookup(llvmSymbol.getSymName())) {
+      originalType = preType;
+      sourceType = convertTypeForMemory(*converter, dataLayout, originalType);
----------------
bcardosolopes wrote:

They're cached. TypeConverter::convertType consults cachedDirectConversions first, so after the first conversion of a type every lookup is a hash lookup plus the dyn_cast checks in convertTypeForMemory. Storing converted types in the map would duplicate that cache and convert types for symbols that are never looked up, so the map keeps CIR types and converts lazily.

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


More information about the cfe-commits mailing list