llvm-project
8efc412a - [flang][debug] Place prologue_end on the first executable statement (#232025)

Commit
1 day ago
[flang][debug] Place prologue_end on the first executable statement (#232025) Consider this program: subroutine sub(a, n) integer :: n integer :: a(n) a(1) = 1 end subroutine program main integer :: a(5) a = 7 call sub(a, 5) end program A breakpoint on 'sub' stops on the declaration of 'a', before the code that computes its bounds has run. The variable is not merely described with the wrong extent there, it cannot be read at all: (gdb) break sub Breakpoint 1 at 0x21e534: file ex.f90, line 3. (gdb) run Breakpoint 1, sub (a=..., n=5) at ex.f90:3 3 integer :: a(n) (gdb) print a $1 = <optimized out> (gdb) print size(a) failed to find array bounds Nothing has been optimized away at -O0. gdb says '<optimized out>' because no location entry for 'a' covers that address: the location only opens once the hidden variable that holds the extent has been written, and that store is the instruction right before the first executable statement. LLVM places prologue_end, where a breakpoint on a procedure resolves, on the first instruction after the frame setup that has a non zero line. Compiler generated code was taking the line of the declaration in two places and so becoming that instruction: 1. The code lowering generates before the execution part, which computes the bounds and lengths of the variables, allocates the automatic ones, binds the host associated ones and holds the alternate return selector. 2. The code the conversion of hlfir.declare to FIR generates to materialize the HLFIR base, such as the descriptor of an array with declared lower bounds. Both now get line 0, while the declarations keep their location so that the debug info still gives the line of the variable. Line 0 and not an unknown location, which would drop the dbg.declare that CodeGen locates at the definition of the storage. The breakpoint then lands on the first executable statement: (gdb) break sub Breakpoint 1 at 0x21e544: file ex.f90, line 4. (gdb) run Breakpoint 1, sub (a=..., n=5) at ex.f90:4 4 a(1) = 1 (gdb) print a $1 = (7, 7, 7, 7, 7) (gdb) print size(a) $2 = 5 Assissted By: Cursor Co-authored-by: Cursor <cursoragent@cursor.com>
Author
Parents
Loading