Skip to content

Commit 4e08643

Browse files
authored
Merge pull request #38917 from mshockwave/dev-fix-81709398
[SILOptimizer] Remove auxiliary debug scope in SILDebugInfoGenerator
2 parents a32dbb4 + ffd1bcb commit 4e08643

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/SILOptimizer/UtilityPasses/SILDebugInfoGenerator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ class SILDebugInfoGenerator : public SILModuleTransform {
150150
I->eraseFromParent();
151151
continue;
152152
}
153+
if (auto *ASI = dyn_cast<AllocStackInst>(I))
154+
// Remove the debug variable scope enclosed
155+
// within the SILDebugVariable such that we won't
156+
// trigger a verification error.
157+
ASI->setDebugVarScope(nullptr);
158+
153159
SILLocation Loc = I->getLoc();
154160
auto *filePos = SILLocation::FilenameAndLocation::alloc(
155161
Ctx.LineNums[I], 1, FileNameBuf, *M);

test/DebugInfo/sil_based_dbg.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,25 @@ public func testit() {
1515
print("Hello")
1616
}
1717

18+
// We need to remove the debug scope within alloc_stack's auxiliary debug var info
19+
// in sil-based-dbg mode.
20+
// To create something like `alloc_stack ..., (name "foo", loc ..., scope 0)...`
21+
// as our testing input, we're only running SROA over the input swift code.
22+
// RUN: %target-swift-frontend %s -disable-debugger-shadow-copies -emit-sil -g -o %t/stage1.sil
23+
// RUN: %target-sil-opt -sil-print-debuginfo -access-marker-elim -sroa %t/stage1.sil -o %t/stage2.sil
24+
// The verification shouldn't fail
25+
// RUN: %target-swift-frontend %t/stage2.sil -sil-verify-all -sil-based-debuginfo -g -emit-sil -o %t/out.sil
26+
// RUN: %FileCheck %s --check-prefix=CHECK_DBG_SCOPE < %t/out.sil
27+
struct TheStruct {
28+
var the_member : Int
29+
}
30+
// CHECK_DBG_SCOPE-LABEL: sil {{.*}}test_debug_scope
31+
public func test_debug_scope(val : Int) -> Int {
32+
// CHECK_DBG_SCOPE: alloc_stack $Builtin.Int{{[0-9]+}}, var, (name "the_struct",
33+
// CHECK_DBG_SCOPE-SAME: loc
34+
// The auxiliary debug scope should be removed
35+
// CHECK_DBG_SCOPE-NOT: scope {{[0-9]+}})
36+
var the_struct = TheStruct(the_member: 0)
37+
the_struct.the_member = val + 13
38+
return the_struct.the_member
39+
}

0 commit comments

Comments
 (0)