]> granicus.if.org Git - clang/commitdiff
Swift Calling Convention: Fix out of bounds access
authorArnold Schwaighofer <aschwaighofer@apple.com>
Thu, 13 Oct 2016 19:19:37 +0000 (19:19 +0000)
committerArnold Schwaighofer <aschwaighofer@apple.com>
Thu, 13 Oct 2016 19:19:37 +0000 (19:19 +0000)
Use iterator instead of address of element in vector

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

rdar://28759508

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284150 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SwiftCallingConv.cpp
test/CodeGen/64bit-swiftcall.c

index a79ddf94bc8992883e71bf86d4da107f52e00c57..1629c443652d3f3b58391e7cf59a5e5bfacff0eb 100644 (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) {
index f5e63fe4d8dff5ed5d5eabeabf665704f0b12370..616743615716cb56db9684447aa1d2f8c34891e3 100644 (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]]*