@@ -1055,3 +1055,59 @@ bb0:
10551055 // CHECK: bb0
10561056 // CHECK: alloc_stack $OSLogInterpolationDCEStub
10571057}
1058+
1059+ // The following tests are for checking that constant folding doesn't
1060+ // cause a crash when evaulating the instructions of an animation signpost.
1061+
1062+ // Protocol stub for CVarArgStub
1063+ protocol CVarArgStub {}
1064+
1065+ // Ensure that Int conforms to our protocol stub
1066+ extension Int64 : CVarArgStub {}
1067+
1068+ // _finalizeUninitializedArray<A>(_:)
1069+ sil shared_external [serialized] [_semantics "array.finalize_intrinsic"] @$ss27_finalizeUninitializedArrayySayxGABnlF : $@convention(thin) <Element> (@owned Array<Element>) -> @owned Array<Element>
1070+
1071+ // Test that the OSLogOptimization does not fail while attempting to
1072+ // fold CVarArgStubs in animation signposts.
1073+ // CHECK-LABEL: @testFoldingOfCVarArgStubConstruction
1074+ sil [ossa] @testFoldingOfCVarArgStubConstruction : $@convention(thin) () -> () {
1075+ bb0:
1076+ // Construct an OSLogMessageStub instance.
1077+ %0 = string_literal utf8 "animation begins here %d"
1078+ %1 = integer_literal $Builtin.Word, 24
1079+ %2 = integer_literal $Builtin.Int1, -1
1080+ %3 = metatype $@thin String.Type
1081+ // function_ref String.init(_builtinStringLiteral:utf8CodeUnitCount:isASCII:)
1082+ %4 = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String
1083+ %5 = apply %4(%0, %1, %2, %3) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // users: %60, %47
1084+ %6 = function_ref @oslogMessageInit : $@convention(thin) (@owned String) -> @owned OSLogMessageStub
1085+ %7 = apply %6(%5) : $@convention(thin) (@owned String) -> @owned OSLogMessageStub
1086+
1087+ // Begin chain of evaluated instructions
1088+ %8 = begin_borrow %7 : $OSLogMessageStub
1089+
1090+ // Construct CVarArgStub
1091+ %11 = integer_literal $Builtin.Word, 1
1092+ // function_ref _allocateUninitializedArray<A>(_:)
1093+ %12 = function_ref @$ss27_allocateUninitializedArrayySayxG_BptBwlF : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
1094+ %13 = apply %12<CVarArgStub>(%11) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
1095+ (%14, %15) = destructure_tuple %13 : $(Array<CVarArgStub>, Builtin.RawPointer)
1096+ %16 = pointer_to_address %15 : $Builtin.RawPointer to [strict] $*CVarArgStub
1097+ %17 = integer_literal $Builtin.IntLiteral, 42
1098+ %18 = builtin "s_to_s_checked_trunc_IntLiteral_Int64"(%17 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1)
1099+ (%19, %20) = destructure_tuple %18 : $(Builtin.Int64, Builtin.Int1)
1100+ %21 = struct $Int64 (%19 : $Builtin.Int64)
1101+ %22 = init_existential_addr %16 : $*CVarArgStub, $Int64
1102+ store %21 to [trivial] %22 : $*Int64
1103+ // function_ref _finalizeUninitializedArray<A>(_:)
1104+ %23 = function_ref @$ss27_finalizeUninitializedArrayySayxGABnlF : $@convention(thin) <τ_0_0> (@owned Array<τ_0_0>) -> @owned Array<τ_0_0>
1105+ %24 = apply %23<CVarArgStub>(%14) : $@convention(thin) <τ_0_0> (@owned Array<τ_0_0>) -> @owned Array<τ_0_0>
1106+ destroy_value %24 : $Array<CVarArgStub>
1107+
1108+ // End chain of evaluated instructions
1109+ end_borrow %8 : $OSLogMessageStub
1110+ destroy_value %7 : $OSLogMessageStub
1111+ %25 = tuple ()
1112+ return %25 : $()
1113+ }
0 commit comments