<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84435>84435</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DebugInfo][GVN] Misleading single-stepping caused by presering old debug location to hoisted LoadInst
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Apochens
</td>
</tr>
</table>
<pre>
Hi, It seems I found another misleading debug location caused by the conflict btw proper debug location updates and backtrace quality. The newly created LoadInst `NewLoad` is inserted into the predecessor of the old LoadInst `Load`, however `NewLoad` preserves the debug location of `Load`. The debug location update site is here. According to the comments in my previous PR, I think this is the same situation as the StoreInst in the loop. The load should drop the location, but we need to keep a location for memory access instruction to track it.
So, I just report this issue and leave it as a reminder (or a reference) for future improvement. @jmorse @SLTozer
The source code:
```C
int func(int *a, int b) {
if (b) {
} else {
*a = 0;
}
b = 1;
return *a;
}
int main() {
int a;
func(&a, 1);
return 0;
}
```
The compilation command:
```Bash
$ clang -S -emit-llvm -Xclang -disable-O0-optnone main.c -o main.ll -g
$ opt -S -passes=mem2reg,gvn -enable-load-pre main.ll -o main_opt.ll && clang main_opt.ll -o main
```
The misleading single-stepping behavior:
```Bash
$ lldb a.out
(lldb) target create "a.out"
Current executable set to '/home/linuxbrew/llvm-debug/a.out' (x86_64).
(lldb) b func
Breakpoint 1: where = a.out`func + 8 at main.c:2:9, address = 0x0000000000001138
(lldb) r
Process 6323 launched: '/home/linuxbrew/llvm-debug/a.out' (x86_64)
Process 6323 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x0000555555555138 a.out`func(a=0x00007fffffffe07c, b=1) at main.c:2:9
1 int func(int *a, int b) {
-> 2 if (b) {
3 } else {
4 *a = 0;
5 }
6 b = 1;
7 return *a;
(lldb) s
Process 6323 stopped
* thread #1, name = 'a.out', stop reason = step in
frame #0: 0x0000555555555145 a.out`func(a=0x00007fffffffe07c, b=1) at main.c:7:12
4 *a = 0;
5 }
6 b = 1;
-> 7 return *a;
8 }
9
10 int main() {
(lldb) s
Process 6323 stopped
* thread #1, name = 'a.out', stop reason = step in
frame #0: 0x000055555555514a a.out`func(a=0x00007fffffffe07c, b=1) at main.c:3:5
1 int func(int *a, int b) {
2 if (b) {
-> 3 } else {
4 *a = 0;
5 }
6 b = 1;
7 return *a;
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV1-PozYQ_zTOyygRmEDIQx6ym2670vV66p6qvp0MDMG3xqa2SXb76asxcMlt0t2216pWFMGMPf7Nv5-xcE7uNeKGpTcs3c1E7xtjN9vOlA1qNytM9bz5QTJ-C_ceHGLr4B5q0-sKhDa-QQutdApFJfUeKiz6PShTCi-NhlL0DisonsE3CKXRtZKlh8IfobOmQ_tyQd9VwqMDoSsoRPnorSgRfuuFkv55AR8bBI1H9QylReGxgndGVPfaeWBZ9B6P9MqyCKQDqR1amiK1N2H_zmKFJTpnLJg6iIz62sS4ntxtzBEPaF8Y7iw6tAd0YfkL9KY-szGgveofOOmRMDZocQHbsjQ2hG8EWpq2Re3JB2ifac-DNL2DDz-HPIBvpH6kf0dGaIUTbbDaD9uIQfrgjcXgmtRBoIzpBlzKiApcY3pVQWVNN6oHmLRL0Xs4UrSxIliPiB2IkyO1sdBia-wziJJiSvH2ti-DlvywonwE6Rcs2rFoO_w_mMGBz73zYLEz1k9uuB5D1hWKA4L05IMAi63UFWWB58YGQY0WdYmMrwOIuve9RZBtZ80BKWwLYMvoc2usQ3p6ePfR_E4WznBQBJzpbUmxrpAlo5xSH363w7vUHupel4zn9Mj4VpAD9FwQALa6GSYCAMiaUF7K2WoHqAjMuTRo-FYAS3YQsWRSsdXuNKkI2vikBQCLvrd6wDLJvyw6wW6F1Iznlyi1B_GVwdFBxrPgXMz4-tqG0ZXdpnC9jG1p2k6qkQNM2wpdXcb4RrhmFPEllEroPcwfYI6t9HOlDi3M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