ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.2k stars 259 forks source link

Bad debug line info on sub-expression #2090

Open JohanEngelen opened 7 years ago

JohanEngelen commented 7 years ago

The line info on the bar(1) call inside foo is wrong:

extern(C): // just to disable mangling
int bar(int a) { return a; }
int foo()
{  
    return 8329423
    + bar(1); // line 6
}

generates this LLVM IR:

define i32 @foo() #0 !dbg !15 {
  %1 = call i32 @bar(i32 1) #0, !dbg !16          ; [#uses = 1] [debug line = 5:5] [display name = save_optimization_record.bar]
  %2 = add i32 8329423, %1, !dbg !16              ; [#uses = 1] [debug line = 5:5]
  ret i32 %2, !dbg !16                            ; [debug line = 5:5]
}

Note the wrong debug line = 5:5 on the call. (also on the +)

JohanEngelen commented 5 years ago

@kinke while working on this I got to these changes: https://github.com/JohanEngelen/ldc/commit/654aa25d0e0e8a68148bf66fe8ad686e021ca203 But... I don't think it's the right path. Perhaps we need to add location information onto a DValue and upon loading it we need to emit the debug location. That would solve a number of issues with debug location and then we only need to make sure we tag the instructions in-between loads.

kinke commented 5 years ago

I'm not familiar with the EmitStopPoint() stuff. To be honest, I wouldn't even expect subexpressions not to be tied to the (first) LoC of their statement, but maybe that's just my experience with VS (I can't even say OTOH whether this works in VC++).