Swift Calling Convention: Fix out of bounds access

Use iterator instead of address of element in vector

It is not valid to access one after the last element.

rdar://28759508

llvm-svn: 284150
This commit is contained in:
Arnold Schwaighofer 2016-10-13 19:19:37 +00:00
parent a17d23eaa7
commit 3d01ad116c
2 changed files with 20 additions and 1 deletions

View File

@ -384,7 +384,7 @@ void SwiftAggLowering::splitVectorEntry(unsigned index) {
auto eltTy = split.first;
CharUnits eltSize = getTypeStoreSize(CGM, eltTy);
auto numElts = split.second;
Entries.insert(&Entries[index + 1], numElts - 1, StorageEntry());
Entries.insert(Entries.begin() + index + 1, numElts - 1, StorageEntry());
CharUnits begin = Entries[index].Begin;
for (unsigned i = 0; i != numElts; ++i) {

View File

@ -694,3 +694,22 @@ typedef struct {
TEST(struct_l5)
// CHECK: define swiftcc void @return_struct_l5([[STRUCT5:%.*]]* noalias sret
// CHECK: define swiftcc void @take_struct_l5([[STRUCT5]]*
// Don't crash.
typedef union {
int4 v[2];
struct {
int LSW;
int d7;
int d6;
int d5;
int d4;
int d3;
int d2;
int MSW;
} s;
} union_het_vecint;
TEST(union_het_vecint)
// CHECK: define swiftcc void @return_union_het_vecint([[UNION:%.*]]* noalias sret
// CHECK: define swiftcc void @take_union_het_vecint([[UNION]]*