@@ -767,3 +767,82 @@ bb0(%x : $*ResilientInt, %y : $SwiftClass):
767
767
%t = tuple()
768
768
return %t : $()
769
769
}
770
+
771
+ protocol Proto1 {}
772
+ protocol Proto2 {}
773
+ struct EmptyType : Proto1 { }
774
+
775
+ struct SomeType : Proto2 {
776
+ var d : ResilientInt // some resilient type
777
+ var x : Int
778
+ }
779
+
780
+ sil @foo : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Proto1, τ_0_1 : Proto2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1) -> ()
781
+
782
+ // CHECK-64-LABEL: define{{.*}} swiftcc void @empty_followed_by_non_fixed(%T13partial_apply8SomeTypeV* noalias nocapture %0)
783
+ // CHECK-64: [[FLAGS:%.*]] = load i32, i32*
784
+ // CHECK-64: [[FLAGS2:%.*]] = zext i32 [[FLAGS]] to i64
785
+ // CHECK-64: [[ALIGNMASK:%.*]] = and i64 [[FLAGS2]], 255
786
+ // CHECK-64: [[NOTALIGNMASK:%.*]] = xor i64 [[ALIGNMASK]], -1
787
+ // Make sure we take the header offset (16) into account.
788
+ // CHECK-64: [[TMP:%.*]] = add i64 16, [[ALIGNMASK]]
789
+ // CHECK-64: [[OFFSET:%.*]] = and i64 [[TMP]], [[NOTALIGNMASK]]
790
+ // CHECK-64: [[CONTEXT:%.*]] = call noalias %swift.refcounted* @swift_allocObject
791
+ // CHECK-64: [[CAST:%.*]] = bitcast %swift.refcounted* [[CONTEXT]] to <{ %swift.refcounted }>*
792
+ // CHECK-64: [[CAST2:%.*]] = bitcast <{ %swift.refcounted }>* [[CAST]] to i8*
793
+ // CHECK-64: [[GEP:%.*]] = getelementptr inbounds i8, i8* [[CAST2]], i64 [[OFFSET]]
794
+ // CHECK-64: [[CAST3:%.*]] = bitcast i8* [[GEP]] to %T13partial_apply8SomeTypeV*
795
+ // CHECK-64: call %T13partial_apply8SomeTypeV* @"$s13partial_apply8SomeTypeVWOb"(%T13partial_apply8SomeTypeV* {{.*}}, %T13partial_apply8SomeTypeV* [[CAST3]])
796
+
797
+ sil @empty_followed_by_non_fixed : $@convention(thin) (EmptyType, @in_guaranteed SomeType) -> () {
798
+ entry(%0 : $EmptyType, %1: $*SomeType):
799
+ %5 = alloc_stack $EmptyType
800
+ store %0 to %5 : $*EmptyType
801
+ %31 = function_ref @foo : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Proto1, τ_0_1 : Proto2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1) -> ()
802
+ %32 = alloc_stack $EmptyType
803
+ copy_addr %5 to [initialization] %32 : $*EmptyType
804
+ %34 = alloc_stack $SomeType
805
+ copy_addr %1 to [initialization] %34 : $*SomeType // id: %35
806
+ %36 = partial_apply [callee_guaranteed] %31<EmptyType, SomeType>(%32, %34) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_0 : Proto1, τ_0_1 : Proto2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1) -> ()
807
+ release_value %36: $@callee_guaranteed () ->()
808
+ dealloc_stack %34 : $*SomeType
809
+ dealloc_stack %32 : $*EmptyType
810
+ dealloc_stack %5 : $*EmptyType
811
+ %40 = tuple()
812
+ return %40 : $()
813
+ }
814
+
815
+ struct FixedType {
816
+ var f: Int32
817
+ }
818
+ // CHECK-64-LABEL: define{{.*}} swiftcc void @fixed_followed_by_empty_followed_by_non_fixed
819
+ // CHECK-64-NOT: ret
820
+ // CHECK-64: [[FLAGS:%.*]] = load i32, i32*
821
+ // CHECK-64: [[FLAGS2:%.*]] = zext i32 [[FLAGS]] to i64
822
+ // CHECK-64: [[ALIGNMASK:%.*]] = and i64 [[FLAGS2]], 255
823
+ // CHECK-64: [[NOTALIGNMASK:%.*]] = xor i64 [[ALIGNMASK]], -1
824
+ // Make sure we compute the correct offset of the non-fixed field.
825
+ // CHECK-64: [[TMP:%.*]] = add i64 20, [[ALIGNMASK]]
826
+ // CHECK-64: ret
827
+
828
+ sil @foo2 : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1, @in_guaranteed τ_0_2) -> ()
829
+ sil @fixed_followed_by_empty_followed_by_non_fixed : $@convention(thin) (EmptyType, @in_guaranteed SomeType, FixedType) -> () {
830
+ entry(%0 : $EmptyType, %1: $*SomeType, %3: $FixedType):
831
+ %5 = alloc_stack $EmptyType
832
+ store %0 to %5 : $*EmptyType
833
+ %7 = alloc_stack $FixedType
834
+ store %3 to %7 : $*FixedType
835
+ %31 = function_ref @foo2 : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1, @in_guaranteed τ_0_2) -> ()
836
+ %32 = alloc_stack $EmptyType
837
+ copy_addr %5 to [initialization] %32 : $*EmptyType
838
+ %34 = alloc_stack $SomeType
839
+ copy_addr %1 to [initialization] %34 : $*SomeType // id: %35
840
+ %36 = partial_apply [callee_guaranteed] %31<FixedType, EmptyType, SomeType>(%7, %32, %34) : $@convention(thin) <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_1, @in_guaranteed τ_0_2) -> ()
841
+ release_value %36: $@callee_guaranteed () ->()
842
+ dealloc_stack %34 : $*SomeType
843
+ dealloc_stack %32 : $*EmptyType
844
+ dealloc_stack %7 : $*FixedType
845
+ dealloc_stack %5 : $*EmptyType
846
+ %40 = tuple()
847
+ return %40 : $()
848
+ }
0 commit comments