llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.12k stars 12.01k forks source link

[flang][debug] Wrong function signature with CHARACTER arguments. #112886

Open abidh opened 4 weeks ago

abidh commented 4 weeks ago

Consider the following example code.

subroutine foo(str1)
  character(len=5) :: str1
  print *, str1
end subroutine

program test
  integer(8) :: length
  length = 5
  call foo('flang')
end program test

When stopped at line 3 (print *, str1), here is what GDB shows

(gdb) info args
No arguments.
(gdb) ptype foo
type = void (void)
(gdb) info locals
str1 = 'flang'

The debug info is describing str1 as local and not argument. This makes function type wrong too.

This seems to happen because our detection of arguments depends on the memRef of the fir.declare being directly pointing at the BlockArgument. If there is any intermediate nodes like in this case (fir.unboxchar, fir.emboxchar) then this detection fails.

abidh commented 4 weeks ago

@jeanPerier this is the problem which I mentioned in the comments in https://github.com/llvm/llvm-project/pull/112398#issuecomment-2422162240 where having argument number on DeclareOp would save us from pattern matching IR.

llvmbot commented 4 weeks ago

@llvm/issue-subscribers-flang-ir

Author: Abid Qadeer (abidh)

Consider the following example code. ``` subroutine foo(str1) character(len=5) :: str1 print *, str1 end subroutine program test integer(8) :: length length = 5 call foo('flang') end program test ``` When stopped at line 3 (print *, str1), here is what GDB shows ``` (gdb) info args No arguments. (gdb) ptype foo type = void (void) (gdb) info locals str1 = 'flang' ``` The debug info is describing `str1` as local and not argument. This makes function type wrong too. This seems to happen because our detection of arguments depends on the `memRef` of the fir.declare being directly pointing at the `BlockArgument`. If there is any intermediate nodes like in this case (`fir.unboxchar, fir.emboxchar`) then this detection fails.
llvmbot commented 4 weeks ago

@llvm/issue-subscribers-debuginfo

Author: Abid Qadeer (abidh)

Consider the following example code. ``` subroutine foo(str1) character(len=5) :: str1 print *, str1 end subroutine program test integer(8) :: length length = 5 call foo('flang') end program test ``` When stopped at line 3 (print *, str1), here is what GDB shows ``` (gdb) info args No arguments. (gdb) ptype foo type = void (void) (gdb) info locals str1 = 'flang' ``` The debug info is describing `str1` as local and not argument. This makes function type wrong too. This seems to happen because our detection of arguments depends on the `memRef` of the fir.declare being directly pointing at the `BlockArgument`. If there is any intermediate nodes like in this case (`fir.unboxchar, fir.emboxchar`) then this detection fails.