Skip to content

Commit 09b26e8

Browse files
committed
SILParser: don't accept instructions after "unreachable"
All instructions after an "unreachable" were not added to the function anyway and were leaking.
1 parent 5f1b008 commit 09b26e8

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5277,6 +5277,11 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
52775277
return true;
52785278
}
52795279

5280+
if (!B.hasValidInsertionPoint()) {
5281+
P.diagnose(P.Tok, diag::expected_sil_block_name);
5282+
return true;
5283+
}
5284+
52805285
SmallVector<Located<StringRef>, 4> resultNames;
52815286
SourceLoc resultClauseBegin;
52825287

test/SIL/Parser/errors.sil

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ sil @test_formal_substituted_type : $@convention(thin) <X> (@owned Array<@substi
5656
entry(%0 : $Array<X>):
5757
return undef : $()
5858
}
59+
60+
sil @instructions_after_terminator : $@convention(thin) () -> () {
61+
bb0:
62+
unreachable
63+
%0 = tuple () // expected-error {{expected basic block name or '}'}}
64+
return %0 : $()
65+
}
66+

test/SILOptimizer/sil_combine.sil

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,19 +2413,6 @@ bb0:
24132413
}
24142414

24152415

2416-
// CHECK-LABEL: sil @remove_dead_code_after_unreachable
2417-
// CHECK-NEXT: bb0
2418-
// CHECK-NEXT: unreachable
2419-
// CHECK-NEXT: } // end sil function 'remove_dead_code_after_unreachable'
2420-
sil @remove_dead_code_after_unreachable : $@convention(thin) () -> (Int32) {
2421-
bb0:
2422-
unreachable
2423-
%2 = integer_literal $Builtin.Int32, -2
2424-
%3 = struct $Int32 (%2 : $Builtin.Int32)
2425-
return %3 : $Int32
2426-
}
2427-
2428-
24292416
// CHECK-LABEL: sil @dont_remove_code_after_cond_fail
24302417
// CHECK: bb0([[Cond:%.*]] : $Builtin.Int1):
24312418
// CHECK-NEXT: [[Ref:%.*]] = integer_literal $Builtin.Int32, -2

0 commit comments

Comments
 (0)