File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -670,6 +670,15 @@ bool swift::canDevirtualizeClassMethod(FullApplySite AI,
670
670
return false ;
671
671
}
672
672
673
+ // devirtualizeClassMethod below does not support this case. It currently
674
+ // assumes it can try_apply call the target.
675
+ if (!F->getLoweredFunctionType ()->hasErrorResult () &&
676
+ isa<TryApplyInst>(AI.getInstruction ())) {
677
+ LLVM_DEBUG (llvm::dbgs () << " FAIL: Trying to devirtualize a "
678
+ " try_apply but vtable entry has no error result.\n " );
679
+ return false ;
680
+ }
681
+
673
682
return true ;
674
683
}
675
684
Original file line number Diff line number Diff line change @@ -154,3 +154,64 @@ bb0(%0 : $Base):
154
154
unreachable
155
155
}
156
156
157
+ class Throw {
158
+ func mayThrow() throws
159
+ }
160
+
161
+ class S1 : Throw {
162
+ override func mayThrow()
163
+ }
164
+
165
+ class S2 : Throw {
166
+ override func mayThrow() throws
167
+ }
168
+
169
+ sil hidden [thunk] @$S4main4ThrowC8mayThrowyyKF : $@convention(method) (@guaranteed Throw) -> @error Error {
170
+ bb0(%0 : $Throw):
171
+ %1 = tuple ()
172
+ return %1 : $()
173
+ }
174
+
175
+ sil hidden @$S4main2S1C8mayThrowyyF : $@convention(method) (@guaranteed S1) -> () {
176
+ bb0(%0 : $S1):
177
+ %1 = tuple ()
178
+ return %1 : $()
179
+ }
180
+
181
+ sil hidden [thunk] [always_inline] @$S4main2S2C8mayThrowyyKF : $@convention(method) (@guaranteed S2) -> @error Error {
182
+ bb0(%0 : $S2):
183
+ %1 = tuple ()
184
+ return %1 : $()
185
+ }
186
+
187
+ // CHECK-LABEL: sil{{.*}} @test_devirt_of_throw_without_error
188
+ // CHECK-NOT: checked_cast_br [exact] %0 : $Throw to $S1
189
+ // CHECK: return
190
+
191
+ sil hidden [noinline] @test_devirt_of_throw_without_error : $@convention(thin) (@owned Throw) -> () {
192
+ bb0(%0 : $Throw):
193
+ %80 = class_method %0 : $Throw, #Throw.mayThrow!1 : (Throw) -> () throws -> (), $@convention(method) (@guaranteed Throw) -> @error Error // user: %81
194
+ try_apply %80(%0) : $@convention(method) (@guaranteed Throw) -> @error Error, normal bb7, error bb6
195
+
196
+ bb6(%82 : $Error):
197
+ br bb1
198
+
199
+ bb7(%84 : $()):
200
+ br bb1
201
+
202
+ bb1:
203
+ %3 = tuple ()
204
+ return %3 : $()
205
+ }
206
+
207
+ sil_vtable Throw {
208
+ #Throw.mayThrow!1: (Throw) -> () throws -> () : @$S4main4ThrowC8mayThrowyyKF
209
+ }
210
+
211
+ sil_vtable S1 {
212
+ #Throw.mayThrow!1: (Throw) -> () throws -> () : @$S4main2S1C8mayThrowyyF [override]
213
+ }
214
+
215
+ sil_vtable S2 {
216
+ #Throw.mayThrow!1: (Throw) -> () throws -> () : @$S4main2S2C8mayThrowyyKF [override]
217
+ }
You can’t perform that action at this time.
0 commit comments