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 switch #2255

Open JohanEngelen opened 7 years ago

JohanEngelen commented 7 years ago

Note the wrong debug line info on the switch's expression i+666. It says line 6, instead of line 2.

int foo(int i) {
    switch (i+666) {  // line 2
        case 10:
            return 42;
        default:
            return 5;   // line 6
    }
}
; [#uses = 0] [display name = switchdebug.foo]
; Function Attrs: uwtable
define i32 @_D11switchdebug3fooFiZi(i32 %i_arg) #0 !dbg !5 {
  %i = alloca i32, align 4                        ; [#uses = 2, size/byte = 4]
  store i32 %i_arg, i32* %i, !dbg !11             ; [debug line = 1:5]
  call void @llvm.dbg.declare(metadata i32* %i, metadata !10, metadata !12), !dbg !11 ; [debug line = 1:5] [debug variable = i]
  %1 = load i32, i32* %i, !dbg !13                ; [#uses = 1] [debug line = 6:13]
  %2 = add i32 %1, 666, !dbg !13                  ; [#uses = 1] [debug line = 6:13]
  switch i32 %2, label %defaultcntr [
    i32 10, label %casecntr
  ]
...
JohanEngelen commented 5 years ago

This is closely related to https://github.com/ldc-developers/ldc/issues/2090