[flang][debug] Debugger shows the wrong variable for same-named submodule entities
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
A variable that is private to a submodule is described in the debug information
as belonging to the submodule's ancestor module. Two submodules of the same
module may each declare a variable of the same name, and both then land in that
one module. A debugger cannot tell them apart and silently reports the value of
whichever it finds first, with no error or ambiguity warning.
## Reproducer
`repro.f90`:
```fortran
module m
interface
module subroutine one()
end subroutine
module subroutine two()
end subroutine
end interface
end module
submodule (m) s1
integer :: counter = 111
contains
module subroutine one()
print *, counter
end subroutine
end submodule
submodule (m) s2
integer :: counter = 222
contains
module subroutine two()
print *, counter
end subroutine
end submodule
program p
use m
call one()
call two()
end program p
```
## Steps to reproduce
```
flang -g -O0 repro.f90 -o repro
gdb -q -batch -ex "break two" -ex run -ex "print counter" ./repro
```
## Expected
`two` is defined in submodule `s2`, whose `counter` is 222, so the debugger
should print 222. Running the program confirms the value is 222: the program
prints `111` then `222`.
```
$1 = 222
```
## Actual
The debugger prints the `counter` of submodule `s1` instead.
```
Breakpoint 1, m::two () at repro.f90:22
$1 = 111
```
Breaking in `one` also prints 111, which happens to be correct there, so the
same expression silently means different things depending on nothing the user
can see.
Contributor guide
Assessment
This issue has not been assessed yet.