https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98656
Bug ID: 98656 Summary: switchlower_O0 drops line number of switch Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: vries at gcc dot gnu.org Target Milestone: --- [ Originally filed as gdb PR at https://sourceware.org/bugzilla/show_bug.cgi?id=27179 ] Consider test-case small.c. ... $ cat -n small.c 1 #include <stdio.h> 2 3 void foo (int x, int y) 4 { 5 switch (x) { 6 case 0: break; 7 case 1: break; 8 case 2: break; 9 case 3: 10 for (int z = 0; z < ({ if (y) break; 5; }); z++) 11 break; 12 case 4: break; 13 default: break; 14 } 15 } 16 17 int main () 18 { 19 foo (1, 1); // L1 20 foo (2, 1); // L2 21 printf("hello world!"); // L3 22 return 0; 23 } ... With gcc-8, we have a .loc with line number 5 representing the switch statement: ... $ gcc-8 -O0 -g small.c -save-temps $ cat small.s foo: .LFB0: .file 1 "small.c" .loc 1 4 1 .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl %edi, -20(%rbp) movl %esi, -24(%rbp) .loc 1 5 3 cmpl $4, -20(%rbp) ja .L13 ... With gcc-9 that .loc disappeared: ... foo: .LFB0: .file 1 "small.c" .loc 1 4 1 .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl %edi, -20(%rbp) movl %esi, -24(%rbp) cmpl $4, -20(%rbp) ja .L13 ... and that's still the case with gcc-11. Culprit is switchlower_O0. With this compilation: ... $ rm -f *.c.*; gcc-11 -O0 -g small.c -fdump-tree-all-lineno -save-temps ... we have at a-small.c.234t.cplxlower0: ... <bb 2> : [small.c:5:3] switch (x_1(D)) <[small.c:13:2] default: <L10> [INV], [small.c:6:5] case 0: <L0> [INV], [small.c:7:5] case 1: <L1> [INV], [small.c:8:5] case 2: <L2> [INV], [small.c:9:5] case 3: <L3> [INV], [small.c:12:5] case 4: <L8> [INV]> ... and at a-small.c.236t.switchlower_O0: ... <bb 2> : switch (x_1(D)) <[small.c:13:2] default: <L10> [0.00%], [small.c:6:5] case 0: <L0> [20.00%], [small.c:7:5] case 1: <L1> [20.00%], [small.c:8:5] case 2: <L2> [20.00%], [small.c:9:5] case 3: <L3> [20.00%], [small.c:12:5] case 4: <L8> [20.00%]> ... Note the dropped "[small.c:5:3]" in front of "switch".