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

    <tr>
        <th>Summary</th>
        <td>
            The sequence of step commands in LLDB is incorrect for a binary compiled with "-g -O1"
        </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>
    The execution sequence of step commands is inaccurate. Initially, a breakpoint is set at line 26, and after executing the step command, it skips to line 58. When the step command is run again, it jumps back to line 32.

In LLVM18.1.8, we can reproduce with:
```
clang -g -O1 310.c -o 310_O1.out
lldb 310_O1.out
(lldb) b 26
(lldb) r
[...]
* thread #1, name = '310_O1.out', stop reason = breakpoint 1.1
    frame #0: 0x000055555555516c 310_O1.out`main [inlined] func_1 at 310.c:26:44
   23       int16_t l_56 = 0x3218L;
   24    for (int i = 0; i < 9; i++)
   25           l_2[i] = 1L;
-> 26         for (g_3[0] = 5; (g_3[0] >= 2); g_3[0] -= 1)
   27       { 
   28    uint8_t l_34 = 255UL;
   29           uint32_t l_35[1];
(lldb) s
Process 87168 stopped
* thread #1, name = '310_O1.out', stop reason = step in
    frame #0: 0x0000555555555140 310_O1.out`main at 310.c:58
 55     }
   56   
   57   int main (void)
-> 58        {   int i = 0;
   59       union U1 a = func_1();
   60       return i;
   61   }
(lldb) s
Process 87168 stopped
* thread #1, name = '310_O1.out', stop reason = step in
    frame #0: 0x0000555555555144 310_O1.out`main [inlined] func_1 at 310.c:32:16
   29           uint32_t l_35[1];
 30             for (int i = 0; i < 1; i++)
   31               l_35[i] = 2UL;
-> 32                l_56 = func_6(func_17(l_2[g_3[0] + 3], g_3[2]), l_34, l_35[0], l_56, l_28);        
   33       }
   34       (*g_39) ^= l_56;
   35       return g_58;
(lldb) s
Process 87168 stopped
* thread #1, name = '310_O1.out', stop reason = step in
 frame #0: 0x0000555555555144 310_O1.out`main [inlined] func_6(p_7=<unavailable>, p_8=<unavailable>, p_9=-25, p_10=<unavailable>, p_11=<unavailable>) at 310.c:58
   55   }
   56   
   57   int main (void)
-> 58        {   int i = 0;
   59       union U1 a = func_1();
   60       return i;
   61   }

```


`cat 310.c`
```
#include "stdint.h"

union U1 {
   uint32_t f0;
   int8_t  f1;
};

static int32_t g_3[10] = {1L,0L,(-10L),(-10L),0L,1L,0L,(-10L),(-10L),0L};
static int32_t g_5 = 8L;
static int32_t g_40 = 1L;
static int32_t * volatile g_39 = &g_40;
static union U1 g_58 = {18446744073709551615UL};

static union U1  func_1(void);
static uint8_t  func_6(uint32_t  p_7, uint8_t p_8, int16_t  p_9, int16_t  p_10, uint32_t  p_11);
static int16_t func_17(int32_t  p_18, int32_t  p_19);

static union U1 func_1(void)

    int8_t l_2[9];
    int32_t l_28 = 0x1F4A1AB7L;
    int64_t l_55 = 0xE56B76AF746A6ECCLL;
    int16_t l_56 = 0x3218L;
    for (int i = 0; i < 9; i++)
        l_2[i] = 1L;
 for (g_3[0] = 5; (g_3[0] >= 2); g_3[0] -= 1)
    { 
        uint8_t l_34 = 255UL;
        uint32_t l_35[1];
        for (int i = 0; i < 1; i++)
            l_35[i] = 2UL;
        l_56 = func_6(func_17(l_2[g_3[0] + 3], g_3[2]), l_34, l_35[0], l_56, l_28); 
    }
    (*g_39) ^= l_56;
    return g_58;
}

static uint8_t  func_6(uint32_t  p_7, uint8_t  p_8, int16_t  p_9, int16_t  p_10, uint32_t  p_11)

    int8_t l_44 = 0x88L;
    for (p_9 = (-25); (p_9 < (-23)); ++p_9)
    { 
        int16_t l_38 = (-8L);
 int32_t *l_45 = &g_40;
        (*g_39) = l_38;
        (*l_45) = func_17(l_38, *l_45);
    }
    return l_44;
}

static int16_t func_17(int32_t  p_18, int32_t  p_19)

    uint8_t l_21[5] = {0UL,0UL,0UL,0UL,0UL};
    return l_21[3];
}

int main (void)
{   int i = 0;
    i =func_1().f1;
    return i;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWEtv2z4S_zT0ZWCBD1GiDj5YdgIU8KJ72OweDVqibbYy5ZWotP32C1Jvx0mzaRfbf2DYIjkPcuY3w18k61qfjFIrxFPEtwvZ2HNZrVTeXMrSLg5l_mP1j7MC9V1ljdWlgVr9u1EmU1AeobbqCll5uUiT16Br0EZmWVNJqwL4ZLTVsih-ILoBCYdKya_XUhvrBGtlQVootFFAIy9hcpBHq6relzmBPauZDyenLdRf9bUGW7bqXATwr7MyL6Sdn6oxIE9Sm071S3O51nCQ2ddBn9EA4S3C6_b7k4Hd7p9_IyIggXBa3xRk0kClrlWZN5mCb9qeEevEUYS7jx9mhTQnWJ5g-ZkAIzjIYFm6h_1nEpSNbaWKIj-8mERUuHlEEzi4mNxOVt0MT4MgQHzbC6zBnislc0CUEbdhIy8KENsCovHECY3dYm3LK1RK1qXxMpO0kIC0NgEAjpW3QhlGbA34O8YY8_6PRNl0-xG-SG0A8VQbF9Ic8S0cG5PtiUuyDwNiaxohtg7DwQdlAAgnzps2lkR7C8WeR35b-DujROwQS0fxsBU_lhUgKjyQWlnEUv-4gcQ_Ipr6TzLq8sGV-yv21G3WbdMZIKOfJWIPQKOZp9OeIZ7iXpo7H7fTD26FOpcshcnK0tufbSUetoLiFMZ50c432ljhQ8FC749y_jQPRDI7jFNgtNXgiKfEYaMXn-Cnbmf-XpWZqmsQMYmEh8NV5b8HS774tHkviEJ8B0QTvHDRWeJt9lC8HUzzNkXjuI2qA0WLRSqeS50Pgfd55aKzk7aQm-BnNDQGtzGu3z0RkF6sBTSios3yoBHhQaNStqkM6Nkyme39j05I-IGqZhSxNYk-hE5geCb8VmmTV0qbkZmJtry9q6G-6dNNgTN60w66ruNPFyEq2mPGLlm-VUxrnabA3CHopit06keJm3BF2_3yTqEd8qj97dHTux6PwSZtYcQ5C8dpp7s-7VniwIO4bzne8gRtjN-C8bTn4k9oB78Hei45132M2BaxTWP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