<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/116886>116886</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Inconsistency in the debug line information for a binary compiled with -g -O3
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          edumoot
      </td>
    </tr>
</table>

<pre>
     In the context of LLVM19.1.3, there's an inconsistency between what the line table reports and what's observed during actual debugging:

- The line table indicates that line 20 of the source code corresponds to two machine instructions

- However, when stepping through the code, three machine instructions are actually executed for that same line

1. The line table shows two entries for line 20:

- At address 0x1140 (line 20, column 7)
- At address 0x1147 (line 20, column 23)
```
Address            Line   Column File   ISA Discriminator OpIndex Flags
------------------ ------ ------ ------ --- ------------- ------- -------------
...
0x0000000000001138     34 5      0   0             0       0  epilogue_begin
0x0000000000001140 20      7      0   0             0       0  is_stmt prologue_end
0x0000000000001147     20     23      0   0             0 0 
0x0000000000001151     25     20      0   0             0       0 is_stmt
```

2. The LLDB debugger dump reveals the same mapping:

- 0x1140 maps to line 20, column 7
- 0x1147 maps to line 20, column 23
```
(lldb) image dump line-table 420.c
...
0x0000000000001138: /home/ad/Downloads/Loop/line_table/420.c:34:5
0x0000000000001140: /home/ad/Downloads/Loop/line_table/420.c:20:7
0x0000000000001147: /home/ad/Downloads/Loop/line_table/420.c:20:23
0x0000000000001151: /home/ad/Downloads/Loop/line_table/420.c:25:20
...
```

3.However, while debugging, three machine instructions are encountered at line 20:

-  0x555555555140 <+0>:   movq   0x2ee9(%rip), %rax ; global_ptr_ref

-  0x555555555147 <+7>:   leaq   0x2eda(%rip), %rcx ; global_var

- 0x55555555514e <+14>:  movq   %rcx, (%rax)

```
(lldb) file 420_O3.out
(lldb) b 420.c:20:7
Breakpoint 1: where = 420_O3.out`func_1 at 420.c:20:7, address = 0x0000000000001140
(lldb) r
* thread #1, name = '420_O3.out', stop reason = breakpoint 1.1
    frame #0: 0x0000555555555140 420_O3.out`func_1 at 420.c:20:7
   17   static union U1 func_1(void)
   18   {
   19       int *local_var_ptr = &global_var;
-> 20            (*global_ptr_ref) = local_var_ptr;
   21       
   22       for (global_var = 4; global_var != 9; ++global_var)
   23       {
(lldb) disassemble
420_O3.out`func_1:
->  0x555555555140 <+0>:   movq 0x2ee9(%rip), %rax ; global_ptr_ref
    0x555555555147 <+7>:   leaq 0x2eda(%rip), %rcx ; global_var
    0x55555555514e <+14>:  movq   %rcx, (%rax)

(lldb) stepi
* thread #1, name = '420_O3.out', stop reason = instruction step into
    frame #0: 0x0000555555555147 420_O3.out`func_1 at 420.c:20:23
   17   static union U1 func_1(void)
   18   {
 19         int *local_var_ptr = &global_var;
-> 20            (*global_ptr_ref) = local_var_ptr;
   21       
   22       for (global_var = 4; global_var != 9; ++global_var)
   23       {

(lldb) stepi
* thread #1, name = '420_O3.out', stop reason = instruction step into
 frame #0: 0x000055555555514e 420_O3.out`func_1 at 420.c:20:23
   17   static union U1 func_1(void)
   18   {
   19       int *local_var_ptr = &global_var;
-> 20            (*global_ptr_ref) = local_var_ptr;
   21       
   22       for (global_var = 4; global_var != 9; ++global_var)
   23       {

(lldb) di
420_O3.out`func_1:
    0x555555555140 <+0>:   movq   0x2ee9(%rip), %rax ; global_ptr_ref
    0x555555555147 <+7>:   leaq   0x2eda(%rip), %rcx ; global_var
->  0x55555555514e <+14>:  movq   %rcx, (%rax)

```

The test case comes from  #107322
`cat 420.c`
```
union U1 {
    short short_val;
    volatile int int_val;
    unsigned int uint_val;
    short another_short;
 volatile int another_int;
};

static int global_var = 0x1C0F8067;
static int *global_ptr = &global_var;
static int **volatile global_ptr_ref = &global_ptr;
static int global_counter = 0x95751CF;
static volatile unsigned char global_flag = 9;
static unsigned int global_shift = 0;
static union U1 global_union = {-4};

static union U1 func_1(void)
{
    int *local_var_ptr = &global_var;
    (*global_ptr_ref) = local_var_ptr;
    
    for (global_var = 4; global_var != 9; ++global_var)
    {
        unsigned char shift_val = 254;
        global_flag++;
        global_shift |= (0xF1BB << (*local_var_ptr)) | ((shift_val << 15) * ((*local_var_ptr << global_flag) >= (*global_ptr)));
    }
    return global_union;
}

int main (void)
{
    func_1();
    return 0;
}
```



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWE2P4jwS_jXmUgLFNunAgQMfg3akXs1hP67IJAV4N7FZ2wHm369sB0ggPd3vdEt72DfqDiSpeqpcfp6yibBW7hXijKQLkq4GonYHbWZY1JXWbrDVxc8ZfFfgDgi5Vg4vDvQOXl__-Vc6HdERJ2zpHxokLLMgFEiVa2Wldajyn7BFd0ZUcD4IF0BKqRCc2JYIBo_aOO9UhOcBQW8tmhMWUNRGqj2I3NWihAK39X4v1Z7wOUlWJGnOQ_h7F1SqQubCoQXnQ4YnLPE5--hW1yb3Iyn8yRi0R60KC06DO2uoRH7wDlJZZ-rcSa1sN9pf9BlPaPyozwdUYB0ejz5PdzC63h-aQhUY62IQe0FBGGyGVv4EvGBeOyxgp01M24oqjqodnY4eB2sP-mxD5qickWgDQjPmp0rNHYiiMGgtJBdKxwkQNrkasyXkuqwrBRlh07dcsn4Xxm8-5CVp_sLlvPFuHa_eHWAZXdey9Fff_zaHlbS5kZVUwmkDP47fVYEXWJdi30zC8OmAtz6gz-zhbgQdjUbxS3JJWgelfBLS5WNIY-JJ838_kvsnHmWp9zVutriXqh9xnHgqhiP7AKS0G-sqB0ejIzSq4g3gCNeAM_42eAL9CCmNrmkb6JfpNdn1zno8s8jX19fVotEvGijq6ggGTyhKGyXpqV6JoKInyjY8rcQxaLSPrG3L7BeWjPenyiZlWWwJm4KsxB5jgt59GDU2Zskof5cqhM-BsPVBV0jYWhSErVf6rEotCkvY-lXrI2FrD7sJsIStIzCf8zHh8_QtxnwCOLSA7C3GfBb4Ws9nJn0GOY3w3XL3souPOr3Yt5H7IvF-80WV61o5NFjAfZ14IiAkl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