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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Incorrect debug locations in lowering of literal argument allocas
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:ir,
            flang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          inaki-amatria
      </td>
    </tr>
</table>

<pre>
    - `flang` version is: `flang version 20.0.0 (https://github.com/llvm/llvm-project.git 88c18da37dfb10d570414bcb92ad075241f1b7c3)`
- Reduced test case:
```f90
subroutine foo(x)
  x = y(1)
end
```
- `flang` invocation is: `flang -O0 -g -S -emit-llvm foo.f90`
- Expected behavior is: Flang assigns debug locations that accurately reflect the source-level expressions.
- Actual behavior: Flang generates incorrect and ambiguous debug locations during lowering for fictional allocas created to represent literal expressions passed as arguments in function calls. This leads to multiple unrelated instructions sharing the same debug location, causing ambiguity in debug information.
```llvm
define void @foo_(ptr %0) #0 !dbg !6 {
  %2 = alloca i32, i64 1, align 4, !dbg !10
    #dbg_declare(ptr %0, !11, !DIExpression(), !12)
  store i32 1, ptr %2, align 4, !dbg !10
  %3 = call contract float @y_(ptr %2), !dbg !10
  store float %3, ptr %0, align 4, !dbg !10
  ret void, !dbg !13
}

; ...
!10 = !DILocation(line: 2, column: 3, scope: !6)
```
- Additional info: The following test case also reproduces the issue:
```f90
subroutine foo(x)
 dimension :: x(1, 1, 1)
 x = y(1)
end
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVd2O4ygTfRpyU4oF2I6di1xkpifSSJ_0SbtzP8JQdtjFEAHOdL_9qnCS_tmVWiNFNoGqOqd-fFAp2ckjHlj7hbVPG7Xkc4gH69XfdqtmlaNVmyGYl8MW2I6PTvmJ7ThcMSYbPNjE6uPj5LEtecUrDkz255wvZMPkicnTZPN5GSodZ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