Skip to content

Commit c30eea1

Browse files
committed
Verify switch_value has int operands only
1 parent 72a9075 commit c30eea1

File tree

4 files changed

+3
-60
lines changed

4 files changed

+3
-60
lines changed

docs/SIL.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8401,7 +8401,7 @@ switch_value
84018401
// FIXME: All destination labels currently must take no arguments
84028402

84038403
Conditionally branches to one of several destination basic blocks based on a
8404-
value of builtin integer or function type. If the operand value matches one of the ``case``
8404+
value of builtin integer. If the operand value matches one of the ``case``
84058405
values of the instruction, control is transferred to the corresponding basic
84068406
block. If there is a ``default`` basic block, control is transferred to it if
84078407
the value does not match any of the ``case`` values. It is undefined behavior

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5227,9 +5227,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
52275227
void checkSwitchValueInst(SwitchValueInst *SVI) {
52285228
// TODO: Type should be either integer or function
52295229
auto Ty = SVI->getOperand()->getType();
5230-
require(Ty.is<BuiltinIntegerType>() || Ty.is<SILFunctionType>(),
5231-
"switch_value operand should be either of an integer "
5232-
"or function type");
5230+
require(Ty.is<BuiltinIntegerType>(),
5231+
"switch_value operand should be an integer");
52335232

52345233
auto ult = [](const SILValue &a, const SILValue &b) {
52355234
return a == b || a < b;

test/SIL/Parser/basic.sil

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -973,51 +973,6 @@ bb3:
973973
return %t : $()
974974
}
975975

976-
// CHECK-LABEL: sil @test_switch_value : $@convention(thin) (Builtin.Word) -> ()
977-
sil @test_switch_value : $@convention(thin) (Builtin.Word) -> () {
978-
bb0(%0 : $Builtin.Word):
979-
// CHECK: switch_value %{{.*}} : $Builtin.Word, case %1: bb1, case %2: bb2
980-
%1 = integer_literal $Builtin.Word, 1
981-
%2 = integer_literal $Builtin.Word, 2
982-
switch_value %0 : $Builtin.Word, case %1: bb1, case %2: bb2
983-
984-
bb1:
985-
%7 = function_ref @_T6switch1aFT_T_ : $@convention(thin) () -> () // CHECK: function_ref
986-
%8 = apply %7() : $@convention(thin) () -> ()
987-
br bb3
988-
989-
bb2:
990-
%12 = function_ref @_T6switch1bFT_T_ : $@convention(thin) () -> () // CHECK: function_ref
991-
%13 = apply %12() : $@convention(thin) () -> ()
992-
br bb3
993-
994-
bb3:
995-
// CHECK: [[FUNC1:%.*]] = function_ref @_T6switch1aFT_T_
996-
// CHECK: [[FUNC2:%.*]] = function_ref @_T6switch1bFT_T_
997-
// CHECK: switch_value %{{.*}} : $@convention(thin) () -> (), case [[FUNC1]]: bb4, case [[FUNC2]]: bb5
998-
%20 = function_ref @_T6switch1bFT_T_ : $@convention(thin) () -> ()
999-
%21 = function_ref @_T6switch1aFT_T_ : $@convention(thin) () -> ()
1000-
%22 = function_ref @_T6switch1bFT_T_ : $@convention(thin) () -> ()
1001-
switch_value %20 : $@convention(thin) () -> (), case %21: bb4, case %22: bb5
1002-
1003-
bb4:
1004-
// CHECK: function_ref
1005-
%37 = function_ref @_T6switch1aFT_T_ : $@convention(thin) () -> ()
1006-
%38 = apply %37() : $@convention(thin) () -> ()
1007-
br bb6
1008-
1009-
bb5:
1010-
// CHECK: function_ref
1011-
%42 = function_ref @_T6switch1bFT_T_ : $@convention(thin) () -> ()
1012-
%43 = apply %42() : $@convention(thin) () -> ()
1013-
br bb6
1014-
1015-
bb6:
1016-
%18 = tuple ()
1017-
// CHECK: return
1018-
return %18 : $()
1019-
}
1020-
1021976
class ConcreteClass : ClassP {
1022977
}
1023978
struct Spoon : Bendable {

test/SIL/Parser/undef.sil

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,6 @@ bb2:
287287
return undef : $()
288288
}
289289

290-
sil @switch_value_test : $() -> () {
291-
bb0:
292-
// CHECK: switch_value undef : $Builtin.Int1, case undef: bb1
293-
switch_value undef : $Builtin.Int1, case undef: bb1
294-
bb1:
295-
// CHECK: switch_value undef : $() -> (), case undef: bb2
296-
switch_value undef : $() -> (), case undef: bb2
297-
bb2:
298-
return undef : $()
299-
}
300-
301290
sil @switch_enum_test : $() -> () {
302291
bb0:
303292
// CHECK: switch_enum undef : $E, case #E.Case!enumelt: bb1, default bb2

0 commit comments

Comments
 (0)