[flang-commits] [flang] [flang][debug] Keep the bounds of variables in stack slots at -O0. (PR #229876)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Fri Oct 9 04:01:44 PDT 2026


abidh wrote:

> Do you know which LLVM passes are dropping the fake.use nodes?
None, as far as I can tell. The fake uses survive into the final MIR and they do keep a value alive. The problem is that the DBG_VALUE and the FAKE_USE end up naming different virtual registers. For example, in the https://github.com/llvm/llvm-project/issues/229434 case, here is how the MIR looks like. 

```
%2:gr64 = COPY $rsi                 ; the hidden length argument
%3:gr64 = COPY killed %2
...
%4:gr64 = COPY %3, debug-location !13   ; exported copy of the length
DBG_VALUE %3, $noreg, !14, ...                  ; the length variable names %3
...
FAKE_USE %4                             ; the fake use names %4
```
The fake use keeps %4 alive, but that is not the register the DBG_VALUE names. %3's only use is the copy that defines %4, so it is dead on the next instruction, and RegAllocFast rewrites the record to DBG_VALUE $noreg. The length ends up with no location at all. This one happens because of where FastISel bails out and SelectionDAG takes over. Other examples have a similar problem but arrive at it through a different path.

> 
> One question about the patch, do you know if it would be possible to generate the debug use slot late in AddDebugInfo.cpp instead of having them in the IR for the whole MLIR pipeline where we do not really need them?

I put it in the lowering because I thought we may want same code for with and without -g. In comments above, both @jiel-nv and @timsmith78 have asked this question. So you also think this should be done under -g then I can move the changes to AddDebugInfo which may actually simplify the code.

https://github.com/llvm/llvm-project/pull/229876


More information about the flang-commits mailing list