<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71065>71065</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect debug info generated at clang-trunk -O3 (clang-17 -O3 is correct)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hemangdash
</td>
</tr>
</table>
<pre>
```
$ clang-trunk --version
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 1964118ace4926f4d103aa0538db1f1f5baa343a)
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;
int d(int e) { return e; }
void main() {
int l_4516;
c = d(1);
l_4516 = 1 && c;
b = l_4516 & a
;
}
```
```
$ clang-17 abc.c -g -O3
$ lldb ./a.out -s cmds
(lldb) target create "./a.out"
Current executable set to '<datapath>/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '<datapath>/cmds'.
(lldb) b 7
Breakpoint 1: where = a.out`main + 10 at abc.c:7:16, address = 0x000000000000114a
(lldb) r
Process 2161844 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x000055555555514a a.out`main at abc.c:7:16
4 int l_4516;
5 c = d(1);
6 l_4516 = 1 && c;
-> 7 b = l_4516 & a
8 ;
9 }
Process 2161844 launched: '<datapath>/a.out' (x86_64)
(lldb) p l_4516
(int) $0 = 1
(lldb) kill
Process 2161844 exited with status = 9 (0x00000009)
(lldb) q
```
```
$ clang-trunk abc.c -g -O3
$ lldb ./a.out -s cmds
(lldb) target create "./a.out"
Current executable set to '<datapath>/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '<datapath>/cmds'.
(lldb) b 7
Breakpoint 1: where = a.out`main + 10 at abc.c:7:16, address = 0x000000000000114a
(lldb) r
Process 2162193 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x000055555555514a a.out`main at abc.c:7:16
4 int l_4516;
5 c = d(1);
6 l_4516 = 1 && c;
-> 7 b = l_4516 & a
8 ;
9 }
Process 2162193 launched: '<datapath>/a.out' (x86_64)
(lldb) p l_4516
(int) $0 = 0
(lldb) kill
Process 2162193 exited with status = 9 (0x00000009)
(lldb) q
```
```
$ cat cmds
b 7
r
p l_4516
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 a7f962c00745c8e28991379985fcd6b51ac0d671
Author: Yingwei Zheng <dtcxzyw2333@gmail.com> @dtcxzyw
Date: Fri Sep 29 02:51:58 2023 +0800
```
[InstCombine] Canonicalize `and(zext(A), B)` into `select A, B & 1, 0` (#66740)
This patch canonicalizes the pattern `and(zext(A), B)` into `select A, B
& 1, 0`. Thus, we can reuse transforms `select B == even, B & 1, 0 -> 0`
and `select B == odd, B & 1, 0 -> zext(B == odd)` in `InstCombine`.
It is an alternative to #66676.
Alive2: https://alive2.llvm.org/ce/z/598phE
Fixes #66733.
Fixes #66606.
Fixes #28612.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWEuP274R_zT0ZWCBD4mSDj7Yu2sgpxZoLu0loKiRxUamXJJaO_n0BSm_dtdN0wBNUeAvLNYA5z3zm58pK-_NziKuSLEhxfNCTaEf3arHvbK7Vvl-0YzttxWR9PxHnwldE56DHpTdLYOb7FdYLl_ReTPaWZxEcD4CVmU0o0B41Ydw8ESsCd8Svt2Z0E9Npsc94dtheL18LA9u_DvqkO1MAFbLnLFKacxrLru8ZVQoRQtRtQ3rWFc0SolcKMLrOfZn5XYYiFjDqZJfZL6c7Fc7Hu1yMHY6LXd2Ouv1DlUL-7HFIWofRm9Os-iT9UENA7bPxkUR4dvJu5jdq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