From fa0b409ef81f1f70edfa72857c4e211ff50998d5 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 2 Mar 2011 01:49:12 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126816 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprScalar.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/CodeGen/CGExprScalar.cpp') diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index c4ff8df381..b11236a97f 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/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"); -- cgit v1.2.3