Skip to content

Commit 7eddf85

Browse files
committed
[flang][debug] Improve check for global variable.
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 c5cd1e9 commit 7eddf85

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
@@ -102,15 +102,15 @@ void AddDebugInfoPass::handleDeclareOp(fir::cg::XDeclareOp declOp,
102102
if (result.first != fir::NameUniquer::NameKind::VARIABLE)
103103
return;
104104
// If this DeclareOp actually represents a global then treat it as such.
105-
if (auto global = symbolTable->lookup<fir::GlobalOp>(declOp.getUniqName())) {
106-
handleGlobalOp(global, fileAttr, scopeAttr, typeGen, symbolTable, declOp);
107-
return;
105+
mlir::Operation *defOp = declOp.getMemref().getDefiningOp();
106+
if (defOp && llvm::isa<fir::AddrOfOp>(defOp)) {
107+
if (auto global =
108+
symbolTable->lookup<fir::GlobalOp>(declOp.getUniqName())) {
109+
handleGlobalOp(global, fileAttr, scopeAttr, typeGen, symbolTable, declOp);
110+
return;
111+
}
108112
}
109113

110-
// Only accept local variables.
111-
if (result.second.procs.empty())
112-
return;
113-
114114
// FIXME: There may be cases where an argument is processed a bit before
115115
// DeclareOp is generated. In that case, DeclareOp may point to an
116116
// intermediate op and not to BlockArgument.

0 commit comments

Comments
 (0)