Issue |
95343
|
Summary |
[DebugInfo][Reassociate] Missing debug location drop for the moved instruction
|
Labels |
new issue
|
Assignees |
|
Reporter |
Apochens
|
Missing debug location drop for the moved [`TheNeg`](https://github.com/llvm/llvm-project/blob/78ee473784e5ef6f0b19ce4cb111fb6e4d23c6b2/llvm/lib/Transforms/Scalar/Reassociate.cpp#L847).
Here is the testcase (main.c):
```c
void func(int a, int c, int *ptr) {
int d = 1;
while (c) {
int sub1 = a - d;
int dead1 = sub1 + 1;
int dead2 = dead1 * 3;
int dead3 = dead2 * sub1;
int sub2 = 0 - d;
*ptr = sub2;
d = 2;
}
}
int main() {
int p = 0;
func(12, 0, &p);
}
```
Compilation:
```
$ clang -S -emit-llvm -Xclang -disable-O0-optnone main.c -o main.ll
$ opt -S -passes=mem2reg,reassociate main.ll -o opted.ll
$ clang opted.ll
```
Debugging:
```
$ lldb a.out
(lldb) b func
(lldb) r
(lldb) s
Process 35731 stopped
* thread #1, name = 'a.out', stop reason = step in
frame #0: 0x000055555555514e a.out`func(a=12, c=0, ptr=0x00007fffffffe14c) at main.c:8:22
5 int dead1 = sub1 + 1;
6 int dead2 = dead1 * 3;
7 int dead3 = dead2 * sub1;
-> 8 int sub2 = 0 - d;
9 *ptr = sub2;
10 d = 2;
11 }
(lldb) v c
(int) c = 0
```
Root cause: Moving the `%sub3` into the preheader of the loop without dropping its debug location
```
while.cond: ; preds = %while.body, %entry
%d.0 = phi i32 [ 1, %entry ], [ 2, %while.body ], !dbg !17
->%sub3 = sub i32 0, %d.0, !dbg !22
%tobool = icmp ne i32 %c, 0, !dbg !21
br i1 %tobool, label %while.body, label %while.end, !dbg !21
while.body: ; preds = %while.cond
%sub = add i32 %a, 1, !dbg !26
%add = add i32 %sub, %sub3, !dbg !27
%mul = mul nsw i32 %add, 3, !dbg !29
store i32 %sub3, ptr %ptr, align 4, !dbg !33
br label %while.cond, !dbg !21, !llvm.loop !34
```
The regression tests in `llvm/test/` that can also reproduce this misleading debug location: `2003-08-12-InfiniteLoop.ll` and `pr28367.ll`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs