Skip to content

Commit 70389c6

Browse files
committed
[flang][debug] Improve check for global variable detection.
PR llvm#118326
1 parent b531fb6 commit 70389c6

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+
auto 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)