Skip to content

Commit f7420a9

Browse files
authored
[flang][debug] Fix issue with argument numbering. (#120726)
Currently fir::isDummyArgument is being used to check if a DeclareOp represents a dummy argument. The argument passed to the function is declOp.getMemref(). This bypasses the code in isDummyArgument that checks for dummy_scope because the `Value` returned by the getMemref() may not have DeclareOp as its defining op. This bypassing mean that sometime a variable will be marked as argument when it should not. This happened in this case where same arg was being used for 2 different result variables with use of `entry` in the function. The solution is to check directly if the declOp has a dummy_scope. If yes, we know this is dummy argument. We can now check if the memref points to the BlockArgument and use its number. This will still miss arguments where memref does not directly point to a BlockArgument but that is missed currently too. Note that we can still evaluate those variable in debugger. It is just that they are not marked as arguments. Fixes #116525.
1 parent cb2eafe commit f7420a9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

flang/lib/Optimizer/Transforms/AddDebugInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ void AddDebugInfoPass::handleDeclareOp(fir::cg::XDeclareOp declOp,
121121
// constant attribute of [hl]fir.declare/fircg.ext_declare operation that has
122122
// a dummy_scope operand).
123123
unsigned argNo = 0;
124-
if (fir::isDummyArgument(declOp.getMemref())) {
125-
auto arg = llvm::cast<mlir::BlockArgument>(declOp.getMemref());
126-
argNo = arg.getArgNumber() + 1;
124+
if (declOp.getDummyScope()) {
125+
if (auto arg = llvm::dyn_cast<mlir::BlockArgument>(declOp.getMemref()))
126+
argNo = arg.getArgNumber() + 1;
127127
}
128128

129129
auto tyAttr = typeGen.convertType(fir::unwrapRefType(declOp.getType()),
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! RUN: %flang_fc1 -fopenmp -emit-llvm -debug-info-kind=standalone %s -o -
2+
3+
! Test that this does not cause build failure.
4+
function s(x)
5+
character(len=2) :: x, s, ss
6+
7+
s = x
8+
9+
entry ss()
10+
11+
end function s
12+

0 commit comments

Comments
 (0)