blob: 29422b251751a448d34e4c570c290ae359fb1cfb [file] [log] [blame]
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck %s
// REQUIRES: CPU=x86_64
// Make sure that we are able to lower unconditional_checked_cast
// addresses for the super_to_archetype case and the downcast case.
class C {}
sil_vtable C {}
class D : C {}
sil_vtable D {}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @downcast_test(%T26unconditional_checked_cast1DC** noalias nocapture sret, %T26unconditional_checked_cast1CC** nocapture dereferenceable({{.*}})) {{.*}} {
// CHECK: entry:
// CHECK-NEXT: [[INPUTPTR:%[0-9]+]] = load %T26unconditional_checked_cast1CC*, %T26unconditional_checked_cast1CC** [[INPUTPTRPTR:%[0-9]+]], align 8
// CHECK-NEXT: [[I8INPUTPTR:%[0-9]+]] = bitcast %T26unconditional_checked_cast1CC* [[INPUTPTR]] to i8*
// CHECK-NEXT: [[TMP:%.*]] = call swiftcc %swift.metadata_response @"$s26unconditional_checked_cast1DCMa"(i64 0)
// CHECK-NEXT: [[T0:%.*]] = extractvalue %swift.metadata_response [[TMP]], 0
// CHECK-NEXT: [[T1:%.*]] = bitcast %swift.type* [[T0]] to i8*
// CHECK-NEXT: [[I8RESULTPTR:%.*]] = call i8* @swift_dynamicCastClassUnconditional(i8* [[I8INPUTPTR]], i8* [[T1]], {{.*}})
// CHECK-NEXT: [[DOWNCASTINPUTPTR:%[0-9]+]] = bitcast i8* [[I8RESULTPTR]] to %T26unconditional_checked_cast1DC*
// CHECK-NEXT: store %T26unconditional_checked_cast1DC* [[DOWNCASTINPUTPTR]], %T26unconditional_checked_cast1DC** {{%[0-9]+}}, align 8
// CHECK-NEXT: ret void
sil @downcast_test : $@convention(thin) (@inout C) -> @out D {
bb0(%0 : $*D, %1 : $*C):
%a = load %1 : $*C
%2 = unconditional_checked_cast %a : $C to $D
store %2 to %0 : $*D
%33 = tuple()
return %33 : $()
}