From 6ea1c6c267e6a543c663599798770c1df09c17c5 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Thu, 13 Oct 2016 19:19:37 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284150 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SwiftCallingConv.cpp | 2 +- test/CodeGen/64bit-swiftcall.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/SwiftCallingConv.cpp b/lib/CodeGen/SwiftCallingConv.cpp index a79ddf94bc..1629c44365 100644 --- a/lib/CodeGen/SwiftCallingConv.cpp +++ b/lib/CodeGen/SwiftCallingConv.cpp @@ -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) { diff --git a/test/CodeGen/64bit-swiftcall.c b/test/CodeGen/64bit-swiftcall.c index f5e63fe4d8..6167436157 100644 --- a/test/CodeGen/64bit-swiftcall.c +++ b/test/CodeGen/64bit-swiftcall.c @@ -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]]* -- 2.40.0