summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2011-03-02 01:49:12 +0000
committerEli Friedman <eli.friedman@gmail.com>2011-03-02 01:49:12 +0000
commit846ded2e53c77b43aae86a6ed60772ae46647e63 (patch)
treeb31225bcb8b950b1ac932b6501263ab34c57014f /clang/lib
parent68faa2dbbeb141e6db360bcebb4aff2e97a28c73 (diff)
downloadbcm5719-llvm-846ded2e53c77b43aae86a6ed60772ae46647e63.tar.gz
bcm5719-llvm-846ded2e53c77b43aae86a6ed60772ae46647e63.zip
PR9350: increment/decrement of char (and anything else narrower than int)
can't overflow due to promotion rules; emit a wrapping add for those cases. llvm-svn: 126816
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index c4ff8df3815..b11236a97f8 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1278,10 +1278,12 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
llvm::Value *amt = llvm::ConstantInt::get(value->getType(), amount);
- if (type->isSignedIntegerType())
+ // Note that signed integer inc/dec with width less than int can't
+ // overflow because of promotion rules; we're just eliding a few steps here.
+ if (type->isSignedIntegerType() &&
+ value->getType()->getPrimitiveSizeInBits() >=
+ CGF.CGM.IntTy->getBitWidth())
value = EmitAddConsiderOverflowBehavior(E, value, amt, isInc);
-
- // Unsigned integer inc is always two's complement.
else
value = Builder.CreateAdd(value, amt, isInc ? "inc" : "dec");
OpenPOWER on IntegriCloud