[flang-commits] [flang] [fir][AddAliasTags] allow usage of AddAliasTag pass after FirToMemref (PR #219493)

via flang-commits flang-commits at lists.llvm.org
Mon Aug 31 02:05:19 PDT 2026


================
@@ -817,15 +817,28 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
   } else if (enableLocalAllocs &&
              source.kind == fir::AliasAnalysis::SourceKind::Allocate) {
     std::optional<llvm::StringRef> name;
-    mlir::Operation *sourceOp =
-        llvm::cast<mlir::Value>(source.origin.u).getDefiningOp();
+    mlir::Value sourceVal = llvm::cast<mlir::Value>(source.origin.u);
+    mlir::Operation *sourceOp = sourceVal.getDefiningOp();
     bool unknownAllocOp = false;
     if (auto alloc = mlir::dyn_cast_or_null<fir::AllocaOp>(sourceOp))
       name = alloc.getUniqName();
     else if (auto alloc = mlir::dyn_cast_or_null<fir::AllocMemOp>(sourceOp))
       name = alloc.getUniqName();
-    else
+    else if (mlir::StringAttr nameAttr =
+                 sourceOp ? sourceOp->getAttrOfType<mlir::StringAttr>(
+                                fir::AllocaOp::getUniqNameAttrName())
+                          : mlir::StringAttr{}) {
+      // Keep a view into the StringAttr storage; str() returns a temporary.
+      name = nameAttr.getValue();
+    } else if (!fir::isNewAllocationResult(
+                    mlir::dyn_cast<mlir::OpResult>(sourceVal))
+                    .value_or(false)) {
+      // Anonymous allocations of other dialects (e.g. memref.alloca for
+      // a compiler generated temporary) are still recognizable as allocations
+      // through their memory effects, and can use the unnamed
+      // "allocated data" tag below.
       unknownAllocOp = true;
----------------
jeanPerier wrote:

Good point. I refactored this code a bit anyway to address Caroline's comment to check for the allocation effect before gathering the uniq_name, so this comment is moved to the place where we are adding the "allocated data" tag below (when "unknownAllocOp" is false and there is no name).

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


More information about the flang-commits mailing list