[flang-commits] [flang] [flang][AA] Relax TARGET handling in getCallModRef for local variables (PR #199869)

via flang-commits flang-commits at lists.llvm.org
Wed May 27 08:46:08 PDT 2026


================
@@ -806,6 +806,73 @@ static bool isSavedLocal(const fir::AliasAnalysis::Source &src) {
   return false;
 }
 
+bool AliasAnalysis::mayBeCapturedBefore(mlir::Operation *declareOp,
+                                        mlir::Operation *op) {
+  if (!declareOp || !op)
+    return true;
+  auto funcOp = op->getParentOfType<mlir::FunctionOpInterface>();
+  if (!funcOp)
+    return true;
+  mlir::Operation *callAnchor = op;
+  while (callAnchor->getParentOp() && callAnchor->getParentOp() != funcOp)
+    callAnchor = callAnchor->getParentOp();
+
+  llvm::SmallVector<mlir::Value, 8> worklist;
+  llvm::SmallPtrSet<mlir::Value, 8> seen;
+  for (mlir::Value res : declareOp->getResults())
----------------
jeanPerier wrote:

Which declare is it? The first or the last one?
In a chain of association, we should start from the first one since a TARGET may be passed to TARGET argument and so on after inlining.
I think the safest should be to start from the allocation operation itself.

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


More information about the flang-commits mailing list