Skip to content

Commit 7ece824

Browse files
authored
[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.
1 parent 69f202b commit 7ece824

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

flang/lib/Optimizer/Transforms/AddDebugInfo.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ void AddDebugInfoPass::handleDeclareOp(fir::cg::XDeclareOp declOp,
183183
return;
184184

185185
// If this DeclareOp actually represents a global then treat it as such.
186-
if (auto global = symbolTable->lookup<fir::GlobalOp>(declOp.getUniqName())) {
187-
handleGlobalOp(global, fileAttr, scopeAttr, typeGen, symbolTable, declOp);
188-
return;
186+
mlir::Operation *defOp = declOp.getMemref().getDefiningOp();
187+
if (defOp && llvm::isa<fir::AddrOfOp>(defOp)) {
188+
if (auto global =
189+
symbolTable->lookup<fir::GlobalOp>(declOp.getUniqName())) {
190+
handleGlobalOp(global, fileAttr, scopeAttr, typeGen, symbolTable, declOp);
191+
return;
192+
}
189193
}
190194

191-
// Only accept local variables.
192-
if (result.second.procs.empty())
193-
return;
194-
195195
// FIXME: There may be cases where an argument is processed a bit before
196196
// DeclareOp is generated. In that case, DeclareOp may point to an
197197
// intermediate op and not to BlockArgument.

0 commit comments

Comments
 (0)