Skip to content

Commit 37bbfbf

Browse files
authored
Merge pull request #34493 from guitard0g/reachable_local_type
2 parents bfe219f + 45b670c commit 37bbfbf

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lib/SILGen/SILGenStmt.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ void StmtEmitter::visitBraceStmt(BraceStmt *S) {
326326
// Ignore all other implicit expressions.
327327
continue;
328328
}
329+
} else if (auto D = ESD.dyn_cast<Decl*>()) {
330+
// Local type declarations are not unreachable because they can appear
331+
// after the declared type has already been used.
332+
if (isa<TypeDecl>(D))
333+
continue;
329334
}
330335

331336
if (StmtType != UnknownStmtType) {

test/SILGen/local_types.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
func function1() {
55
return
66

7-
class UnreachableClass {} // expected-warning {{code after 'return' will never be executed}}
7+
class LocalClass {}
88
}
99

1010
func function2() {
@@ -19,4 +19,4 @@ func function2() {
1919

2020
// CHECK-LABEL: sil private [transparent] [ossa] @$s11local_types9function2yyFyycfU_1SL_V1xSivpfi : $@convention(thin) () -> Int
2121

22-
// CHECK-LABEL: sil_vtable UnreachableClass
22+
// CHECK-LABEL: sil_vtable LocalClass

test/SILGen/unreachable_code.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-sil %s -o /dev/null -verify
1+
// RUN: %target-swift-emit-sil %s -verify | %FileCheck %s
22

33
func testUnreachableAfterReturn() -> Int {
44
var x: Int = 3
@@ -146,3 +146,12 @@ func testUnreachableCatchClause() {
146146
print("some error")
147147
}
148148
}
149+
150+
func sr13639() -> Int {
151+
return Foo.bar
152+
struct Foo { // no-warning
153+
static var bar = 0
154+
// CHECK: sil private @$s16unreachable_code7sr13639SiyF3FooL_V7fooFuncyyF : $@convention(method) (Foo) -> ()
155+
func fooFunc() {}
156+
}
157+
}

0 commit comments

Comments
 (0)