[flang-commits] [flang] 7ece824 - [flang][debug] Improve check for global variable detection. (#118326)
via flang-commits
flang-commits at lists.llvm.org
Tue Feb 4 05:17:18 PST 2025
Author: Abid Qadeer
Date: 2025-02-04T13:17:14Z
New Revision: 7ece824b6fa943bf20162d8d653d6e5cd0722a6e
URL: https://github.com/llvm/llvm-project/commit/7ece824b6fa943bf20162d8d653d6e5cd0722a6e
DIFF: https://github.com/llvm/llvm-project/commit/7ece824b6fa943bf20162d8d653d6e5cd0722a6e.diff
LOG: [flang][debug] Improve check for global variable detection. (#118326)
When a global variable is used in the OpenMP target region, it is passed
as an argument to the function that implements target region. But the
`DeclareOp` for this incarnation still have the original name of the
variable. As some of our checks to decide if a variable is global or nor
are based on the name, this can result in a local variable being treated
as global. This PR hardens the check a bit. We now also check that
memory ref is actually an `AddrOfOp` before looking at the name.
Added:
Modified:
flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
index 3e1209c9ccd547..69915741a88f62 100644
--- a/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
+++ b/flang/lib/Optimizer/Transforms/AddDebugInfo.cpp
@@ -183,15 +183,15 @@ void AddDebugInfoPass::handleDeclareOp(fir::cg::XDeclareOp declOp,
return;
// If this DeclareOp actually represents a global then treat it as such.
- if (auto global = symbolTable->lookup<fir::GlobalOp>(declOp.getUniqName())) {
- handleGlobalOp(global, fileAttr, scopeAttr, typeGen, symbolTable, declOp);
- return;
+ mlir::Operation *defOp = declOp.getMemref().getDefiningOp();
+ if (defOp && llvm::isa<fir::AddrOfOp>(defOp)) {
+ if (auto global =
+ symbolTable->lookup<fir::GlobalOp>(declOp.getUniqName())) {
+ handleGlobalOp(global, fileAttr, scopeAttr, typeGen, symbolTable, declOp);
+ return;
+ }
}
- // Only accept local variables.
- if (result.second.procs.empty())
- return;
-
// FIXME: There may be cases where an argument is processed a bit before
// DeclareOp is generated. In that case, DeclareOp may point to an
// intermediate op and not to BlockArgument.
More information about the flang-commits
mailing list