@@ -370,3 +370,42 @@ bb0:
370
370
%v = tuple ()
371
371
return %v : $()
372
372
}
373
+
374
+ //===----------------------------------------------------------------------===//
375
+ // testWitnessCopiedSelfWithIndirectResult: Call to a witness method
376
+ // with an existential self that can be type-propagated. Exercise
377
+ // `SILCombiner::canReplaceArg` when `self` is not in argument position zero.
378
+ //
379
+ // rdar://45415719 Assertion failed: (Index < Length && "Invalid index!")
380
+ // ===----------------------------------------------------------------------===//
381
+
382
+ protocol AnyP {
383
+ func returnsSelf() -> Self
384
+ }
385
+
386
+ struct StructOfAnyP : AnyP {
387
+ func returnsSelf() -> StructOfAnyP
388
+ }
389
+
390
+ // CHECK-LABEL: sil @testWitnessCopiedSelfWithIndirectResult : $@convention(thin) () -> () {
391
+ // CHECK: [[IN:%[0-9]+]] = alloc_stack $StructOfAnyP
392
+ // CHECK: [[OUT:%[0-9]+]] = alloc_stack $StructOfAnyP
393
+ // CHECK: witness_method $StructOfAnyP, #AnyP.returnsSelf!1 : <Self where Self : AnyP> (Self) -> () -> @dynamic_self Self : $@convention(witness_method: AnyP) <τ_0_0 where τ_0_0 : AnyP> (@in_guaranteed τ_0_0) -> @out StructOfAnyP
394
+ // CHECK: apply %{{.*}}<StructOfAnyP>([[OUT]], [[IN]]) : $@convention(witness_method: AnyP) <τ_0_0 where τ_0_0 : AnyP> (@in_guaranteed τ_0_0) -> @out StructOfAnyP
395
+ // CHECK-LABEL: } // end sil function 'testWitnessCopiedSelfWithIndirectResult'
396
+ sil @testWitnessCopiedSelfWithIndirectResult : $() -> () {
397
+ bb0:
398
+ %a0 = alloc_stack $AnyP
399
+ %ie0 = init_existential_addr %a0 : $*AnyP, $StructOfAnyP
400
+ %a1 = alloc_stack $AnyP
401
+ copy_addr %a0 to [initialization] %a1 : $*AnyP
402
+ %o0 = open_existential_addr immutable_access %a1 : $*AnyP to $*@opened("7C4DAF8E-D722-11E8-920A-D0817AD9F6DD") AnyP
403
+ %a2 = alloc_stack $StructOfAnyP
404
+ %w0 = witness_method $@opened("7C4DAF8E-D722-11E8-920A-D0817AD9F6DD") AnyP, #AnyP.returnsSelf!1 : <Self where Self : AnyP> (Self) -> () -> @dynamic_self Self, %o0 : $*@opened("7C4DAF8E-D722-11E8-920A-D0817AD9F6DD") AnyP : $@convention(witness_method: AnyP) <τ_0_0 where τ_0_0 : AnyP> (@in_guaranteed τ_0_0) -> @out StructOfAnyP
405
+ %c0 = apply %w0<@opened("7C4DAF8E-D722-11E8-920A-D0817AD9F6DD") AnyP>(%a2, %o0) : $@convention(witness_method: AnyP) <τ_0_0 where τ_0_0 : AnyP> (@in_guaranteed τ_0_0) -> @out StructOfAnyP
406
+ dealloc_stack %a2 : $*StructOfAnyP
407
+ dealloc_stack %a1 : $*AnyP
408
+ dealloc_stack %a0 : $*AnyP
409
+ %v = tuple ()
410
+ return %v : $()
411
+ }
0 commit comments