<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/112886>112886</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang][debug] Wrong function signature with CHARACTER arguments.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            abidh
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          abidh
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VEFv6zYM_jXKhXiGLceuffAhbZZtlx2KAu8sS7StVZYMiW5e__0g2WmzdhgQWBEl8vs-kqIIQY8WsWPVI-Nc9FpNjHNWnQ9ipcn5LpkOvVPv3ZOzQSv0QBPC4IxxV21HwF9iXgyCdAozlp9Zftq_db7_0jasvXcraRudHeNNIF8w3m6nICfhhST0jDcGLSvPFeMtsPLEyhOku9tFWLy2BIyfGH-6O0Cr4BPjnsji3ejFDISBbkG0JRwTWHMHY9CONN3ubDtg5Rmqm00KY3b-jD8MRtiR8YcPGZHEd7gvmfg5oYVAbllQgSAwMSclMN58l8bb-HdCj6ADXCdB8Pv5EcLkrgH-J9uMN6PqozRtBwfCj2E7-Ctt1hkthezr3YXel6086SDtovw3p1XkF9cPrV8gjJPC7CCRenK8z9F_0kzflwlBYb-OWyQdQGGQXvexv1idp0zUOYiwoYCwCqyjDyUZvEw6wCxeMcCwWknaWUj0r97ZEci5DP4NqQMExDkAOZjEsqCFHqVYA4JbPSgk3MK44TNjoHBBqwLE8BNGcjPOzzhEem7Ynob2mUJphEfoMUpQ2qMk8w6L05aiRdDN_dE4-Xra47M6z-DPFGYruLDvqVX9jEoLQrBOYQCjXxF0pKADSBEwFofVeYRebe9-xdcUGycacL4Z6jxWi2L7Jc9PjYPQJmQH1ZWqLVtxwK544C2veHGsD1OnjnUj5SD4sZVtJYq2VlIpiWVeVqU84kF3POfHIi-aoji2eZ1h04phUMUgiodaVMiOOc5Cm8yYtzlzfjzoEFbsioI3TX0wokcT9jG0d0waQ76LDj_6dQzsmBsdKHyGIE0mza7Nozqz6jH1EavO8DMV_qMZ4qATtHqEq6YJnv44PZ-eXn57vnsNh9WbbiJaQhwH_ML4ZdQ0rX0m3cz4JeLuy4_Fu79REuOXpCMwftmlvHX8nwAAAP__oI-qDw">