Skip to content

[DebugInfo] Misleading debug location at O1/2/3/g/s in inlined code #135937

Open
@Apochens

Description

@Apochens

Clang version

Ubuntu clang version 21.0.0 (++20250415033808+d0e4af8a88dc-1~exp1~20250415153924.2354)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-21/bin

LLDB version

lldb version 21.0.0

Bug-triggering program

 1  int printf(const char *, ...);
 2  int a, c;
 3  unsigned b = 5;
 4  int d() {
 5    if (b)
 6      return b;
 7    c = 8;  // Dead code here
 8  }
 9  int main() {
10    d();
11    printf("%X\n", a);
12  }

After the mid-end optimizations, the debug locations are fine: https://godbolt.org/z/f6e1qbdaM.

When debugging, LLDB stops at the dead line:

Process 37755 stopped
* thread #1, name = 'origin', stop reason = step in
    frame #0: 0x0000555555555165 origin`main at origin.proc.c:7:5
   4    int d() {
   5      if (b)
   6        return b;
-> 7      c = 8;
   8    }
   9    int main() {
   10     d();

I suspect that this bug is caused by function inlining. cc @SLTozer @jryans

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions