Skip to content

Commit 8baf933

Browse files
[DebugInfo][SILGen] Ensure "guard let" is lowered with a non-implicit location
Prior to this patch, a "guard let" was being lowered with an implicit debug location, causing it to be dropped in later stages of the compiler, and making it impossible to set a breakpoint in that line. This was tracked down to a piece of code in `SILGenFunction::emitExprInto`, which takes an optional Location parameter that was being ignored in one code path.
1 parent 2f8d9e5 commit 8baf933

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ void SILGenFunction::emitExprInto(Expr *E, Initialization *I,
405405
FormalEvaluationScope writeback(*this);
406406
auto lv = emitLValue(load->getSubExpr(),
407407
SGFAccessKind::BorrowedAddressRead);
408-
emitCopyLValueInto(E, std::move(lv), I);
408+
emitCopyLValueInto(L ? *L : E, std::move(lv), I);
409409
return;
410410
}
411411

test/SILGen/guardlet_debuginfo.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-emit-silgen -g -Xllvm -sil-print-debuginfo %s | %FileCheck %s
2+
3+
class A {
4+
func foo() {
5+
{ [weak self] in
6+
// Check that column 14 -- the start "guard" -- is used as the debug location,
7+
// as other locations are considered implicit.
8+
// CHECK: switch_enum
9+
// CHECK-SAME: guardlet_debuginfo.swift":[[@LINE+1]]:13
10+
guard let self else { return }
11+
print(self)
12+
}()
13+
}
14+
}
15+
16+
let a = A()
17+
a.foo()

0 commit comments

Comments
 (0)