Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/SILGen/SILGenPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3007,6 +3007,10 @@ void SILGenFunction::emitCatchDispatch(DoCatchStmt *S, ManagedValue exn,
// If we don't have a multi-pattern 'catch', we can emit the
// body inline. Emit the statement here and bail early.
if (clause->getCaseLabelItems().size() == 1) {
// Debug values for catch clause variables must be nested within a scope for
// the catch block to avoid name conflicts.
DebugScope scope(*this, CleanupLocation(clause));

// If we have case body vars, set them up to point at the matching var
// decls.
if (clause->hasCaseBodyVariables()) {
Expand All @@ -3027,6 +3031,11 @@ void SILGenFunction::emitCatchDispatch(DoCatchStmt *S, ManagedValue exn,
// Ok, we found a match. Update the VarLocs for the case block.
auto v = VarLocs[vd];
VarLocs[expected] = v;

// Emit a debug description of the incoming arg, nested within the scope
// for the pattern match.
SILDebugVariable dbgVar(vd->isLet(), /*ArgNo=*/0);
B.emitDebugDescription(vd, v.value, dbgVar);
}
}
}
Expand Down
39 changes: 35 additions & 4 deletions test/DebugInfo/catch_let.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,45 @@ func throwing() throws -> () {

func use<T>(_ t: T) {}

public func foo() {
// CHECK-LABEL: define {{.*}}explicitBinding{{.*}}
public func explicitBinding() {
do {
try throwing()
}
catch let error {
// CHECK: call void @llvm.dbg.declare(metadata %swift.error** %{{.*}}, metadata ![[ERROR:[0-9]+]],
// CHECK: ![[ERROR]] = !DILocalVariable(name: "error"
// CHECK: call void @llvm.dbg.declare(metadata %swift.error** %{{.*}}, metadata ![[EXPLICIT_ERROR:[0-9]+]],
use(error)
}
}
foo();
explicitBinding()

// CHECK-LABEL: define {{.*}}implicitBinding{{.*}}
public func implicitBinding() {
do {
try throwing()
}
catch {
// CHECK: call void @llvm.dbg.declare(metadata %swift.error** %{{.*}}, metadata ![[IMPLICIT_ERROR:[0-9]+]],
use(error)
}
}
implicitBinding()

// CHECK-LABEL: define {{.*}}multiBinding{{.*}}
public func multiBinding() {
do {
try throwing()
}
catch let error as MyError, let error as MyError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why multiple/duplicate bindings isn't an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// CHECK: call void @llvm.dbg.declare(metadata %swift.error** %{{.*}}, metadata ![[MULTI_BINDING_ERROR:[0-9]+]],
// CHECK-NOT: call void @llvm.dbg.declare(metadata %swift.error** %{{.*}}
use(error)
} catch {
use(error)
}
}
multiBinding()

// CHECK: ![[EXPLICIT_ERROR]] = !DILocalVariable(name: "error"
// CHECK: ![[IMPLICIT_ERROR]] = !DILocalVariable(name: "error"
// CHECK: ![[MULTI_BINDING_ERROR]] = !DILocalVariable(name: "error"
1 change: 1 addition & 0 deletions test/SILGen/errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func dont_return<T>(_ argument: T) throws -> T {
// Catch HomeworkError.CatAteIt.
// CHECK: [[MATCH]]([[T0:%.*]] : @owned $Cat):
// CHECK-NEXT: [[BORROWED_T0:%.*]] = begin_borrow [lexical] [[T0]]
// CHECK-NEXT: debug_value [[BORROWED_T0]] : $Cat
// CHECK-NEXT: [[T0_COPY:%.*]] = copy_value [[BORROWED_T0]]
// CHECK-NEXT: end_borrow [[BORROWED_T0]]
// CHECK-NEXT: destroy_value [[T0]]
Expand Down