[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:20 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();
----------------
jeanPerier wrote:

That is a good point. While I think it should be OK to add tags to these ops, I prefer doing what you suggest for the generic fallback and requiring the operation we gather the the uniq_name from to have an allocation effect on the source val (which could maybe be added to the hlfir.associate op, although this is not currently relevant since TBAA tags are added late, way after the HLFIR to FIR codegen).

Refactored the code to always check compute `unkownAllocOp` based on `!isNewAllocationResult` and to only gather the uniq_name on ops that are recognized as allocation operations.

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


More information about the flang-commits mailing list