Skip to content

Commit 08e9c46

Browse files
SwiftCallingConv: Fix the splitVectorEntry function (#69953)
When splitting an entry into multiple entries, the indices of the split entries are a combination of the original split entry's and the number of elements we split that entry to. Failure to do so resulted in non-sensical entries leading e.g to assertion failures in `getCoerceAndExpandTypes` and runtime failures in Swift programs.
1 parent 138e6c1 commit 08e9c46

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

clang/lib/CodeGen/SwiftCallingConv.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,10 @@ void SwiftAggLowering::splitVectorEntry(unsigned index) {
409409

410410
CharUnits begin = Entries[index].Begin;
411411
for (unsigned i = 0; i != numElts; ++i) {
412-
Entries[index].Type = eltTy;
413-
Entries[index].Begin = begin;
414-
Entries[index].End = begin + eltSize;
412+
unsigned idx = index + i;
413+
Entries[idx].Type = eltTy;
414+
Entries[idx].Begin = begin;
415+
Entries[idx].End = begin + eltSize;
415416
begin += eltSize;
416417
}
417418
}

clang/test/CodeGen/64bit-swiftcall.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,8 @@ struct {
985985
} s;
986986
} union_het_vecint;
987987
TEST(union_het_vecint)
988-
// CHECK: define{{.*}} swiftcc void @return_union_het_vecint(ptr noalias sret([[UNION:.+]])
989-
// CHECK: define{{.*}} swiftcc void @take_union_het_vecint(ptr
988+
// CHECK: define{{.*}} swiftcc { i64, i64, i64, i64 } @return_union_het_vecint()
989+
// CHECK: define{{.*}} swiftcc void @take_union_het_vecint(i64 %0, i64 %1, i64 %2, i64 %3)
990990

991991
typedef struct {
992992
float3 f3;
@@ -1044,3 +1044,20 @@ typedef struct {
10441044

10451045
// CHECK-LABEL: use_atomic_padded(i64 %0, i64 %1)
10461046
SWIFTCALL void use_atomic_padded(atomic_padded a) {}
1047+
1048+
1049+
typedef union {
1050+
float4 v;
1051+
float3 v2;
1052+
struct {
1053+
float a;
1054+
float b;
1055+
float c;
1056+
float d;
1057+
};
1058+
} vector_union;
1059+
1060+
TEST(vector_union)
1061+
1062+
// CHECK-LABEL: define swiftcc { float, float, float, float } @return_vector_union()
1063+
// CHECK-LABEL: define swiftcc void @take_vector_union(float %0, float %1, float %2, float %3)

0 commit comments

Comments
 (0)