Fix PR13704
- The increment needs to be signed value to preserve the original value when
its data type is larger than 64-bit integer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162766 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index f304317..58692f5 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -1306,7 +1306,7 @@
// 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.
diff --git a/test/CodeGen/pr13704.c b/test/CodeGen/pr13704.c
new file mode 100644
index 0000000..41b8b2c
--- /dev/null
+++ b/test/CodeGen/pr13704.c
@@ -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
+}