<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/70951>70951</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect debug info generated at clang-17 -O3 (clang-16 -O3 is correct)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hemangdash
</td>
</tr>
</table>
<pre>
```
$ clang-16 --version
clang version 16.0.4
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
$ clang-17 --version
clang version 17.0.3
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
```
```
$ cat abc.c
int a, b, c, e, l, n, p, q;
char d, g, h, i, j, k, r;
static char f = 5;
char m[6][1];
short o;
int s() {
a++;
for (;;) {
short t[1];
n = 0;
t[n];
k = p = f;
for (; e < 6; e = 8)
g ^= c = 1 & g;
i--;
r = b ^= r;
char l_1566 = 1;
++j;
q = l_1566 = h = l = i;
if (i)
return 0;
f = 0;
o = t[0];
if (o)
(c = 1) ^ m[5][a] || (d = 1);
if (c)
for (;;)
;
}
}
void main() { s(); }
```
```
$ clang-16 abc.c -g -O3
$ lldb ./a.out -s cmds
(lldb) target create "./a.out"
Current executable set to '/data2/hemang/test5/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/data2/hemang/test5/cmds'.
(lldb) b 18
Breakpoint 1: where = a.out`s + 105 at abc.c:18:5, address = 0x0000000000001199
(lldb) r
Process 2808175 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x0000555555555199 a.out`s at abc.c:18:5
15 i--;
16 r = b ^= r;
17 char l_1566 = 1;
-> 18 ++j;
19 q = l_1566 = h = l = i;
20 if (i)
21 return 0;
Process 2808175 launched: '/data2/hemang/test5/a.out' (x86_64)
(lldb) p l_1566
(char) $0 = '\x01'
(lldb) kill
Process 2808175 exited with status = 9 (0x00000009)
(lldb) q
```
```
$ lldb ./a.out -s cmds
(lldb) target create "./a.out"
Current executable set to '/data2/hemang/test5/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/data2/hemang/test5/cmds'.
(lldb) b 18
Breakpoint 1: 2 locations.
(lldb) r
Process 2886988 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.2
frame #0: 0x000055555555532b a.out`main at abc.c:18:5
15 i--;
16 r = b ^= r;
17 char l_1566 = 1;
-> 18 ++j;
19 q = l_1566 = h = l = i;
20 if (i)
21 return 0;
Process 2886988 launched: '/data2/hemang/test5/a.out' (x86_64)
(lldb) p l_1566
(char) $0 = '\xff'
(lldb) kill
Process 2886988 exited with status = 9 (0x00000009)
(lldb) q
```
```
$ cat cmds
b 18
r
p l_1566
kill
q
```
The value printed using lldb in clang-16 -O3 ('\x01') and clang-17 -O3 ('\xff') are different.
By using git bisection, we find that this issue was introduced in the following commit:
commit 43436993f48b1d75d9d80796cb0889ce7d191888
Author: Nikita Popov <npopov@redhat.com> @nikic
Date: Tue Apr 25 10:04:49 2023 +0200
[LICM] Don't try to constant fold instructions
This was introduced in 030f02021b6359ec5641622cf1aa63d873ecf55a as
an alleged compile-time optimization. In reality, trying to constant
fold instructions is more expensive than just hoisting them. In a
standard pipeline, LICM tends to run either after a run of
LoopInstSimplify or InstCombine, so LICM doesn't really see constant
foldable instructions in the first place, and the attempted fold
is futile.
This makes for a very minor compile-time improvement.
Differential Revision: https://reviews.llvm.org/D149134
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWEtv4zjy_zTMpWBDpN4HH5K4DTQw__8Mdvs-oMSSxY4kqknKSfbTL4qS35mZ7sXOzGWNgLHrXcWqn1yWzun9gLhh6RNLtw9y8q2xmxZ7OeyVdO1DZdT7hmXR8hdtWfTIRAJ1J4f9imewWh3QOm2GmRfosJCAZ-toncycL9Lu0bP4Ed6K7NcsWU3Dy2Beh1Wnh-lttR-mRa61KBX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