Fix PR13704

- The increment needs to be signed value to preserve the original value when
  its data type is larger than 64-bit integer.

llvm-svn: 162766
This commit is contained in:
Michael Liao 2012-08-28 16:55:13 +00:00
parent 2a226a61da
commit 48f498fccf
2 changed files with 10 additions and 1 deletions

View File

@ -1306,7 +1306,7 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
// Most common case by far: integer increment.
} else if (type->isIntegerType()) {
llvm::Value *amt = llvm::ConstantInt::get(value->getType(), amount);
llvm::Value *amt = llvm::ConstantInt::get(value->getType(), amount, true);
// 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.

View File

@ -0,0 +1,9 @@
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
extern void foo(__int128);
void bar() {
__int128 x = 2;
x--;
foo(x);
// CHECK: add nsw i128 %0, -1
}