[llvm] [coroutines] Use DILocation from new storage for hoisted dbg.declare (PR #75104)
Wei Wang via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 13:55:35 PST 2023
apolloww wrote:
This is to fix an issue we saw internally where the lldb can't see local variable (lives on frame) in the ramp function. Is it because after hoisting, we have something like
```llvm
define dso_local ptr @_Z3fooi(i32 noundef %arg) !dbg !1455 {
... ...
coro.init: ; preds = %coro.init.from.entry, %coro.init.from.coro.alloc
%0 = phi ptr [ %.coro.init, %coro.init.from.entry ], [ %call.coro.init, %coro.init.from.coro.alloc ], !dbg !1489
call void @llvm.dbg.declare(metadata ptr %0, metadata !1491, metadata !DIExpression(DW_OP_plus_uconst, 24)), !dbg !1492
call void @llvm.dbg.declare(metadata ptr %0, metadata !1493, metadata !DIExpression(DW_OP_plus_uconst, 16)), !dbg !1494
call void @llvm.dbg.declare(metadata ptr %0, metadata !1484, metadata !DIExpression(DW_OP_plus_uconst, 20)), !dbg !1494
call void @llvm.dbg.declare(metadata ptr %0, metadata !1459, metadata !DIExpression()), !dbg !1494
... ...
!1455 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !19, file: !19, line: 20, type: !1456, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !18, retainedNodes: !1458)
!1489 = !DILocation(line: 20, column: 19, scope: !1455)
!1487 = distinct !DILexicalBlock(scope: !1455, file: !19, line: 20, column: 19)
!1492 = !DILocation(line: 21, column: 7, scope: !1487)
!1494 = !DILocation(line: 0, scope: !1455)
```
Because `!1492` is a smaller scope than `!1489`, `LiveDebugValues` kills the `dbg.declare` at the end of `coro.init` block. This change makes `dbg.declare` take `!1489`.
The same issue also happens to `.resume`, `.destory|cleanup` functions:
```llvm
define internal fastcc void @_Z3fooi.resume(ptr noundef nonnull align 8 dereferenceable(32) %0) !dbg !1779 {
entry.resume:
%.debug = alloca ptr, align 8
call void @llvm.dbg.declare(metadata ptr %.debug, metadata !1782, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 24)), !dbg !1784
call void @llvm.dbg.declare(metadata ptr %.debug, metadata !1785, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 16)), !dbg !1786
call void @llvm.dbg.declare(metadata ptr %.debug, metadata !1787, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 20)), !dbg !1786
call void @llvm.dbg.declare(metadata ptr %.debug, metadata !1781, metadata !DIExpression(DW_OP_deref)), !dbg !1786
.... ....
!1779 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !19, file: !19, line: 20, type: !1456, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !18, retainedNodes: !1780)
!1783 = distinct !DILexicalBlock(scope: !1779, file: !19, line: 20, column: 19)
!1784 = !DILocation(line: 21, column: 7, scope: !1783)
!1786 = !DILocation(line: 0, scope: !1779)
```
but we've got lucky because `LiveDebugValues` assumes everything in the entry block always live. Would probably fix this as well later.
https://github.com/llvm/llvm-project/pull/75104
More information about the llvm-commits
mailing list