Skip to content

Commit 3c51d03

Browse files
committed
Merge remote-tracking branch 'origin/main' into next
2 parents d068b53 + 7c63b8a commit 3c51d03

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

lib/SILGen/SILGenStmt.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,27 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
296296
SGF.LocalAuxiliaryDecls.clear();
297297
}
298298

299+
bool didDiagnoseUnreachableElements = false;
299300
for (auto &ESD : S->getElements()) {
300301

301-
if (auto D = ESD.dyn_cast<Decl*>())
302+
if (auto D = ESD.dyn_cast<Decl*>()) {
302303
if (isa<IfConfigDecl>(D))
303304
continue;
305+
306+
// Hoisted declarations are emitted at the top level by emitSourceFile().
307+
if (D->isHoisted())
308+
continue;
309+
310+
// PatternBindingBecls represent local variable bindings that execute
311+
// as part of the function's execution.
312+
if (!isa<PatternBindingDecl>(D)) {
313+
// Other decls define entities that may be used by the program, such as
314+
// local function declarations. So handle them here, before checking for
315+
// reachability, and then continue looping.
316+
SGF.visit(D);
317+
continue;
318+
}
319+
}
304320

305321
// If we ever reach an unreachable point, stop emitting statements and issue
306322
// an unreachable code diagnostic.
@@ -350,6 +366,10 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
350366
continue;
351367
}
352368

369+
if (didDiagnoseUnreachableElements)
370+
continue;
371+
didDiagnoseUnreachableElements = true;
372+
353373
if (StmtType != UnknownStmtType) {
354374
diagnose(getASTContext(), ESD.getStartLoc(),
355375
diag::unreachable_code_after_stmt, StmtType);
@@ -376,7 +396,7 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
376396
}
377397
}
378398
}
379-
return;
399+
continue;
380400
}
381401

382402
// Process children.
@@ -395,11 +415,11 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
395415
} else {
396416
auto *D = ESD.get<Decl*>();
397417

398-
// Hoisted declarations are emitted at the top level by emitSourceFile().
399-
if (D->isHoisted())
400-
continue;
418+
// Only PatternBindingDecls should be emitted here.
419+
// Other decls were handled above.
420+
auto PBD = cast<PatternBindingDecl>(D);
401421

402-
SGF.visit(D);
422+
SGF.visit(PBD);
403423
}
404424
}
405425
}

stdlib/cmake/modules/StdlibOptions.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include_guard(GLOBAL)
22

33
include(${CMAKE_CURRENT_LIST_DIR}/../../../cmake/modules/SwiftUtils.cmake)
44
precondition(SWIFT_HOST_VARIANT_SDK)
5+
precondition(SWIFT_DARWIN_PLATFORMS)
56

67
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "CYGWIN")
78
set(SWIFT_STDLIB_SUPPORTS_BACKTRACE_REPORTING_default FALSE)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
3+
4+
// CHECK-LABEL: sil {{.*}} @${{.*}}3foo{{.*}}F : {{.*}} {
5+
func foo() {
6+
return bar(Baz())
7+
8+
struct Baz {
9+
// CHECK-LABEL: sil {{.*}} @{{.*}}3foo{{.*}}3Baz{{.*}}C : {{.*}} {
10+
init() {}
11+
}
12+
13+
// CHECK-LABEL: sil {{.*}} @{{.*}}3foo{{.*}}3bar{{.*}}F : {{.*}} {
14+
func bar(_: Any) {}
15+
16+
}

0 commit comments

Comments
 (0)