summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-06-25 01:32:37 +0000
committerJohn McCall <rjmccall@apple.com>2011-06-25 01:32:37 +0000
commit77527a8e652e3cef5887db8923743c9f89950234 (patch)
tree4c7ad96bbc4876b79fdb447876ee7509fbfd93bd /clang/lib/CodeGen/CGExpr.cpp
parentc15b0cfc1f89cb8d9779189892d733e2d23d8866 (diff)
downloadbcm5719-llvm-77527a8e652e3cef5887db8923743c9f89950234.tar.gz
bcm5719-llvm-77527a8e652e3cef5887db8923743c9f89950234.zip
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. llvm-svn: 133855
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index e8d156ea64d..8852ea185bb 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/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 =
OpenPOWER on IntegriCloud