llvm / llvm/llvm-project

[flang][debug] debug info for procedure arguments is not accessible during whole procedure lifetime

Open
#185,432 6 comments 0 reactions 1 assignee Claimed by @timsmith78 View on GitHub
debuginfo flang:ir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Debug info for procedure arguments may be unvalidated before the procedure lifetime leading to`` answer after the first few lines inside the procedures even at O0.

I think this is because dbg.declare emitted for procedure arguments are using the argument register as the base address (of the data or descriptor), and LLVM will not try to extend the lifetime of those registers just because they are used in a dbg.declare. So they will typically be invalidated by the first call inside the procedures that is using those passing registers.

Reproducer:

In the code below, it is possible to inquire about `nvar` in the first two lines of `foo`, but after the call to something, the register is invalidated and later query fails with `` . This is not the case at O0 with other Fortran compilers like gfortran, or ifx (nvfortran/classic flang seem to have the issue) and is likely pretty inconvenient for users trying to debug programs.

```fortran
subroutine foo(nvar)
integer :: nvar
integer :: jvar = 2
call something(jvar)
print *, "hello"
end subroutine

subroutine something(n)
integer :: n
print *, n
end subroutine

call foo(1)
end
```

```
flang -g -O0 repro.f90
gdb --quiet -ex "set confirm off" -ex "b 4" -ex "r" -ex "p nvar" -ex "n" -ex "p nvar" -ex "q" ./a.out
```

```
Breakpoint 1, foo (nvar=1) at repro.f90:4
4 call something(jvar)
$1 = 1
2
5 print *, "hello"
$2 =
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.