Skip to content

Commit af71a36

Browse files
committed
[DebugInfo] Fix AllocStackHoisting losing debug info
AllocStackHoisting was losing debug info, including at -Onone. When two alloc_stacks of the same type are merged, one of them would lose their debug variable. It is now salvaged, with an added debug_value. This case was previously only handled for noncopyable types, it is now done in all cases. (cherry picked from commit c02f663)
1 parent 005948a commit af71a36

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/IRGen/AllocStackHoisting.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ void moveAllocStackToBeginningOfBlock(
157157
// of the debug_value to the original position.
158158
if (haveMovedElt) {
159159
if (auto varInfo = AS->getVarInfo()) {
160-
SILBuilderWithScope Builder(AS);
161160
// SILBuilderWithScope skips over meta instructions when picking a scope.
162-
Builder.setCurrentDebugScope(AS->getDebugScope());
161+
SILBuilder Builder(AS, AS->getDebugScope());
163162
auto *DVI = Builder.createDebugValue(AS->getLoc(), AS, *varInfo);
164163
DVI->setUsesMoveableValueDebugInfo();
165164
DebugValueToBreakBlocksAt.push_back(DVI);
@@ -198,14 +197,14 @@ void Partition::assignStackLocation(
198197
if (AssignedLoc == AllocStack) continue;
199198
eraseDeallocStacks(AllocStack);
200199
AllocStack->replaceAllUsesWith(AssignedLoc);
201-
if (hasAtLeastOneMovedElt) {
202-
if (auto VarInfo = AllocStack->getVarInfo()) {
203-
SILBuilderWithScope Builder(AllocStack);
204-
auto *DVI = Builder.createDebugValue(AllocStack->getLoc(), AssignedLoc,
205-
*VarInfo);
200+
if (auto VarInfo = AllocStack->getVarInfo()) {
201+
SILBuilder Builder(AllocStack, AllocStack->getDebugScope());
202+
auto *DVI = Builder.createDebugValueAddr(AllocStack->getLoc(),
203+
AssignedLoc, *VarInfo);
204+
if (hasAtLeastOneMovedElt) {
206205
DVI->setUsesMoveableValueDebugInfo();
207-
DebugValueToBreakBlocksAt.push_back(DVI);
208206
}
207+
DebugValueToBreakBlocksAt.push_back(DVI);
209208
}
210209
AllocStack->eraseFromParent();
211210
}

test/SILOptimizer/allocstack_hoisting_debuginfo.sil

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,14 @@ bb4:
9898
return %9999 : $()
9999
}
100100

101-
// This case we are not moving anything so we are leaving in the default
102-
// behavior which is not breaking blocks and not inserting debug_info.
101+
// This case we are not moving anything, so we don't add the
102+
// [moveable_value_debuginfo] flag, but we still want debug info for the
103+
// second alloc_stack!
103104
//
104105
// CHECK-LABEL: sil @hoist_generic_3 :
105106
// CHECK: bb0([[ARG:%.*]] : $*T,
106107
// CHECK-NEXT: [[STACK:%.*]] = alloc_stack $T{{[ ]*}}, let, name "x"
107-
// CHECK-NOT: debug_value
108+
// CHECK: debug_value %{{.+}}, let, name "y"
108109
// CHECK: } // end sil function 'hoist_generic_3'
109110
sil @hoist_generic_3 : $@convention(thin) <T> (@in T, Builtin.Int1) -> () {
110111
bb0(%0 : $*T, %1: $Builtin.Int1):

0 commit comments

Comments
 (0)