<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/104531>104531</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Inaccurate debug information: Lines that are outside the loop's body are incorrectly being treated as part of the loop body.
</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>
We notice that lines outside the loop are mistakenly considered part of the loop body. Specifically, lines following the loop are inaccurately included in the loop’s execution context, which undermines the precision of the debugging process. Line 51 is included within the loop that spans from line 35 to line 45.
Reproduce in LLVM18.18 context:
```
clang -g -O3 379.c -o 379_O3.out
lldb 379_O2.out
(lldb) b 35
(lldb) r
[...]
frame #0: 0x000055555555517c 379_O2.out`main [inlined] func_1 at 379.c:35:33
32 if (l_8)
33 break;
34 }
-> 35 for (l_5.f1 = (-1); (l_5.f1 != 54); l_5.f1 = l_5.f1 + 1)
36 {
37 int32_t *l_11 = (void*)0;
38 int32_t *l_12[9] = {(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0};
(lldb) n
Process 55034 stopped
* thread #1, name = '379_O2.out', stop reason = step over
frame #0: 0x0000555555555181 379_O2.out`main [inlined] func_1 at 379.c:43:13
40 union U2 **l_17 = &l_18;
41 union U2 *l_21 = &g_19;
42 union U2 **l_20 = &l_21;
-> 43 g_14++;
44 (*g_22) = ((*l_20) = ((*l_17) = (void*)0));
45 }
46 return l_5;
(lldb) n
Process 55034 stopped
* thread #1, name = '379_O2.out', stop reason = step over
frame #0: 0x0000555555555187 379_O2.out`main [inlined] func_1 at 379.c:44:11
41 union U2 *l_21 = &g_19;
42 union U2 **l_20 = &l_21;
43 g_14++;
-> 44 (*g_22) = ((*l_20) = ((*l_17) = (void*)0));
45 }
46 return l_5;
47 }
(lldb) n
Process 55034 stopped
* thread #1, name = '379_O2.out', stop reason = step over
frame #0: 0x0000555555555140 379_O2.out`main at 379.c:51:18
48
49 int main (void)
50 {
-> 51 union U5 a = func_1();
52 return 0;
53 }
54
(lldb) fr v
(U5) a = <variable not available>
(lldb) n
Process 55034 stopped
* thread #1, name = '379_O2.out', stop reason = breakpoint 1.1
frame #0: 0x000055555555517c 379_O2.out`main [inlined] func_1 at 379.c:35:33
32 if (l_8)
33 break;
34 }
-> 35 for (l_5.f1 = (-1); (l_5.f1 != 54); l_5.f1 = l_5.f1 + 1)
36 {
37 int32_t *l_11 = (void*)0;
38 int32_t *l_12[9] = {(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0};
(lldb)
clang -g -O1 379.c -o 379_O1.out
lldb 379_O1.out
(lldb) b 35
(lldb) r
[...]
* thread #1, name = '379_O1.out', stop reason = breakpoint 1.1
frame #0: 0x0000555555555154 379_O1.out`main [inlined] func_1 at 379.c:35:33
32 if (l_8)
33 break;
34 }
-> 35 for (l_5.f1 = (-1); (l_5.f1 != 54); l_5.f1 = l_5.f1 + 1)
36 {
37 int32_t *l_11 = (void*)0;
38 int32_t *l_12[9] = {(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0};
(lldb) n
Process 55362 stopped
* thread #1, name = '379_O1.out', stop reason = step over
frame #0: 0x0000555555555140 379_O1.out`main at 379.c:51:18
48
49 int main (void)
50 {
-> 51 union U5 a = func_1();
52 return 0;
53 }
54
(lldb) n
Process 55362 stopped
* thread #1, name = '379_O1.out', stop reason = breakpoint 1.1
frame #0: 0x0000555555555154 379_O1.out`main [inlined] func_1 at 379.c:35:33
32 if (l_8)
33 break;
34 }
-> 35 for (l_5.f1 = (-1); (l_5.f1 != 54); l_5.f1 = l_5.f1 + 1)
36 {
37 int32_t *l_11 = (void*)0;
38 int32_t *l_12[9] = {(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0};
(lldb) n
Process 55362 stopped
* thread #1, name = '379_O1.out', stop reason = step over
frame #0: 0x0000555555555140 379_O1.out`main at 379.c:51:18
48
49 int main (void)
50 {
-> 51 union U5 a = func_1();
52 return 0;
53 }
54
(lldb)
```
`cat 379.c`
```
#include "stdint.h"
union U2 {
volatile int32_t f0;
volatile int32_t f1;
};
union U5 {
const uint32_t f0;
uint64_t f1;
};
static int32_t g_2 = (-1L);
static volatile uint32_t g_14 = 0x36FC75DFL;
static union U2 g_19 = {-7L};
static union U2 *g_23 = &g_19;
static union U2 ** volatile g_22 = &g_23;
static union U5 func_1(void)
{
union U5 l_5 = {4294967295UL};
int32_t l_13[3];
for (int i = 0; i < 3; i++)
l_13[i] = 0xE836EA0EL;
for (g_2 = 14; (g_2 <= 10); g_2 = g_2 - 5)
{
return l_5;
}
for (l_5.f1 = 24; (l_5.f1 > 57); l_5.f1++)
{
int32_t l_8 = 4L;
if (l_8)
break;
}
for (l_5.f1 = (-1); (l_5.f1 != 54); l_5.f1 = l_5.f1 + 1)
{
int32_t *l_11 = (void*)0;
int32_t *l_12[9] = {(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0};
union U2 *l_18 = &g_19;
union U2 **l_17 = &l_18;
union U2 *l_21 = &g_19;
union U2 **l_20 = &l_21;
g_14++;
(*g_22) = ((*l_20) = ((*l_17) = (void*)0));
}
return l_5;
}
int main (void)
{
union U5 a = func_1();
return 0;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWVtv47oR_jX0y8ACL6IuD36w4wQo4GKLFts-GpRE2-zSoiFRTvLvC0qyLo6cpDm75-w5G8GQpeGQc-E3HGooylLtcykXiK8QX89EZQ-mWMisOhpjZ4nJnhf_kZAbq1IJ9iAsaJXLEkxlS5U5kgRtzAlEIeGoSiu-yVw_Q2py117IDE6isGB2Pasb1YN_nWSqdioVWj8jeteOuzNam0eV78cjq1ykaVUIK_UzqDzVVSYzUHnHhe4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