diff options
author | John McCall <rjmccall@apple.com> | 2011-06-25 01:32:37 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-06-25 01:32:37 +0000 |
commit | 913dab2525cc705e5238023a446f5371fa411883 (patch) | |
tree | e8d23d18339ceac16f106cbb3d04d26d4efefd44 /lib/CodeGen/CGExpr.cpp | |
parent | 555f57e3549fb5cc963a2ce38180c4f3643a6f95 (diff) |
Mark the multiply which occurs as part of performing pointer
arithmetic on a VLA as 'nsw', per discussion with djg, and
implement pointer arithmetic (other than array accesses) and
pointer subtraction for VLA types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133855 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index e8d156ea64..8852ea185b 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1589,12 +1589,17 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { // The element count here is the total number of non-VLA elements. llvm::Value *numElements = getVLASize(vla).first; - Idx = Builder.CreateMul(Idx, numElements); - - if (getContext().getLangOptions().isSignedOverflowDefined()) + // Effectively, the multiply by the VLA size is part of the GEP. + // GEP indexes are signed, and scaling an index isn't permitted to + // signed-overflow, so we use the same semantics for our explicit + // multiply. We suppress this if overflow is not undefined behavior. + if (getLangOptions().isSignedOverflowDefined()) { + Idx = Builder.CreateMul(Idx, numElements); Address = Builder.CreateGEP(Address, Idx, "arrayidx"); - else + } else { + Idx = Builder.CreateNSWMul(Idx, numElements); Address = Builder.CreateInBoundsGEP(Address, Idx, "arrayidx"); + } } else if (const ObjCObjectType *OIT = E->getType()->getAs<ObjCObjectType>()){ // Indexing over an interface, as in "NSString *P; P[4];" llvm::Value *InterfaceSize = |