Skip to content

Commit 01f46b3

Browse files
Merge pull request #28615 from aschwaighofer/dynamic_cast_crash_fix
DynamicCasts: Use the lowered type to construct a SIL type
2 parents 5d2f3e5 + a288540 commit 01f46b3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/SIL/DynamicCasts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ namespace {
874874
}
875875
auto targetFormalTy = target.FormalType;
876876
auto targetLoweredTy =
877-
SILType::getPrimitiveObjectType(targetFormalTy);
877+
SILType::getPrimitiveObjectType(target.LoweredType.getASTType());
878878
if (isCFBridgingConversion(SwiftModule,
879879
source.FormalType,
880880
targetFormalTy)) {

test/SILOptimizer/constant_propagation.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,3 +1046,28 @@ bb0(%0 : $@thin T.Type):
10461046
%1 = builtin "isConcrete"(%0 : $@thin T.Type) : $Builtin.Int1
10471047
return %1 : $Builtin.Int1
10481048
}
1049+
1050+
class AClass {}
1051+
class BClass : AClass {}
1052+
1053+
// CHECK-LABEL: sil @test_checked_cast_br_thick_class_type
1054+
// CHECK: [[METATYPE:%.*]] = metatype $@thick BClass.Type
1055+
// CHECK: [[SUPER:%.*]] = upcast [[METATYPE]] : $@thick BClass.Type to $@thick AClass.Type
1056+
// CHECK: br bb1([[SUPER]] : $@thick AClass.Type)
1057+
sil @test_checked_cast_br_thick_class_type : $@convention(thin) (@thin P.Protocol) -> Builtin.Int1 {
1058+
bb0(%0 : $@thin P.Protocol):
1059+
%2 = metatype $@thick BClass.Type
1060+
checked_cast_br %2 : $@thick BClass.Type to AClass.Type, bb1, bb2
1061+
1062+
bb1(%5 : $@thick AClass.Type):
1063+
debug_value %5 : $@thick AClass.Type, let, name "type"
1064+
%6 = integer_literal $Builtin.Int1, -1
1065+
br bb3(%6 : $Builtin.Int1)
1066+
1067+
bb2:
1068+
%9 = integer_literal $Builtin.Int1, 0
1069+
br bb3(%9 : $Builtin.Int1)
1070+
1071+
bb3(%11 : $Builtin.Int1):
1072+
return %11 : $Builtin.Int1
1073+
}

0 commit comments

Comments
 (0)