Skip to content

[6.0] SILGen: ignore unreachable var decls #74355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
11 changes: 4 additions & 7 deletions lib/SILGen/SILGenStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {

// PatternBindingBecls represent local variable bindings that execute
// as part of the function's execution.
if (!isa<PatternBindingDecl>(D)) {
if (!isa<PatternBindingDecl>(D) && !isa<VarDecl>(D)) {
// Other decls define entities that may be used by the program, such as
// local function declarations. So handle them here, before checking for
// reachability, and then continue looping.
Expand Down Expand Up @@ -428,12 +428,9 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
SGF.emitIgnoredExpr(E);
} else {
auto *D = ESD.get<Decl*>();

// Only PatternBindingDecls should be emitted here.
// Other decls were handled above.
auto PBD = cast<PatternBindingDecl>(D);

SGF.visit(PBD);
assert((isa<PatternBindingDecl>(D) || isa<VarDecl>(D)) &&
"other decls should be handled before the reachability check");
SGF.visit(D);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/SILGen/local_decl_after_unreachable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ func foo() {
// CHECK-LABEL: sil {{.*}} @{{.*}}3foo{{.*}}3bar{{.*}}F : {{.*}} {
func bar(_: Any) {}

// Check that we don't crash here
lazy var v = 42
}