[Mlir-commits] [mlir] [mlir][LLVM] Preserve !associated and !absolute_symbol on llvm.mlir.global (PR #218839)

Tobias Gysi llvmlistbot at llvm.org
Sat Aug 29 23:22:09 PDT 2026


================
@@ -1701,10 +1701,17 @@ LogicalResult ModuleImport::convertGlobal(llvm::GlobalVariable *globalVar) {
 
   if (llvm::MDNode *associatedMD =
           globalVar->getMetadata(llvm::LLVMContext::MD_associated)) {
-    if (associatedMD->getNumOperands() == 1) {
-      if (FlatSymbolRefAttr symbolRef =
-              getMetadataOperandSymbolRef(associatedMD->getOperand(0).get()))
-        globalOp.setAssociatedAttr(symbolRef);
+    FlatSymbolRefAttr symbolRef;
+    if (associatedMD->getNumOperands() == 1)
+      symbolRef =
+          getMetadataOperandSymbolRef(associatedMD->getOperand(0).get());
+    if (symbolRef) {
----------------
gysit wrote:

nit: normally we prefer early return, i.e.
```
if (!symbolRef)
  emitWarning
  return
globalOp.setAssociatedAttr
```
to avoid the else block.

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


More information about the Mlir-commits mailing list