@@ -21,15 +21,22 @@ import Swift
2121// CHECK: [[STRUCT:%.*]] = struct $Int32 ({{%.*}} : $Builtin.Int32)
2222// CHECK: return [[STRUCT]] : $Int32
2323
24+ protocol P {
25+ func boo() -> Int64
26+ }
27+
2428class Bar {
29+ func boo() -> Int64
2530 func foo()
2631 @objc func foo_objc()
2732}
2833
2934sil @_TFC4main3Bar3foofS0_FT_T_ : $@convention(method) (@guaranteed Bar) -> ()
35+ sil @_TFC4main3Bar3boofS0_FT_T_ : $@convention(method) (@guaranteed Bar) -> Int64
3036sil @_TFC4main3Bar3foo_objcfS0_FT_T_ : $@convention(objc_method) (Bar) -> ()
3137
3238sil_vtable Bar {
39+ #Bar.boo!1: _TFC4main3Bar3boofS0_FT_T_
3340 #Bar.foo!1: _TFC4main3Bar3foofS0_FT_T_
3441 #Bar.foo_objc!1: _TFC4main3Bar3foofS0_FT_T_
3542}
@@ -104,6 +111,45 @@ bb3 (%23 : $Builtin.Int32) :
104111 return %24 : $Int32
105112}
106113
114+ // The following function used to crash the compiler, because loop rotate
115+ // could not properly handle the reference from witness_method to the
116+ // archetype opened by open_existential_addr
117+ // CHECK-LABEL: sil @looprotate_with_opened_archetype
118+ // CHECK: return
119+ sil @looprotate_with_opened_archetype : $@convention(thin) (Int32, @in P) -> Int32 {
120+ bb0(%0 : $Int32, %25: $*P):
121+ %1 = struct_extract %0 : $Int32, #Int32._value
122+ %2 = integer_literal $Builtin.Int32, 0
123+ %30 = alloc_box $Bool
124+ %30a = project_box %30 : $@box Bool
125+ %40 = open_existential_addr %25 : $*P to $*@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P
126+ br bb1(%1 : $Builtin.Int32, %2 : $Builtin.Int32, %25: $*P, %30 : $@box Bool, %30a : $*Bool)
127+
128+ bb1(%4 : $Builtin.Int32, %5 : $Builtin.Int32, %26: $*P, %31 : $@box Bool, %32 : $*Bool):
129+ %111 = witness_method $@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P, #P.boo!1, %40 : $*@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64
130+ %122 = apply %111<@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P>(%40) : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64
131+ %6 = struct $Int32 (%5 : $Builtin.Int32)
132+ %8 = builtin "cmp_eq_Word"(%5 : $Builtin.Int32, %1 : $Builtin.Int32) : $Builtin.Int1
133+ cond_br %8, bb3, bb2
134+
135+ bb2:
136+ %10 = integer_literal $Builtin.Int32, 1
137+ %12 = integer_literal $Builtin.Int1, -1
138+ %13 = builtin "sadd_with_overflow_Word"(%5 : $Builtin.Int32, %10 : $Builtin.Int32, %12 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1)
139+ %14 = tuple_extract %13 : $(Builtin.Int32, Builtin.Int1), 0
140+ %15 = enum $Optional<Int32>, #Optional.some!enumelt.1, %6 : $Int32
141+ %16 = unchecked_enum_data %15 : $Optional<Int32>, #Optional.some!enumelt.1
142+ %17 = struct_extract %16 : $Int32, #Int32._value
143+ %19 = integer_literal $Builtin.Int1, -1
144+ %20 = builtin "sadd_with_overflow_Word"(%4 : $Builtin.Int32, %17 : $Builtin.Int32, %19 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1)
145+ %21 = tuple_extract %20 : $(Builtin.Int32, Builtin.Int1), 0
146+ br bb1(%21 : $Builtin.Int32, %14 : $Builtin.Int32, %26: $*P, %31 : $@box Bool, %32 : $*Bool)
147+
148+ bb3:
149+ %23 = struct $Int32 (%4 : $Builtin.Int32)
150+ return %23 : $Int32
151+ }
152+
107153// Don't assert on this loop. bb2 is bb1 loop's new header after rotation but
108154// also bb2 loop's header.
109155
0 commit comments