Hi The attached patch fixes PR13704 which is caused by the missing sign when increments (1 or -1) are created for types larger than 64-bit integer.
Yours - Michael
>From 571eb6bf648b9acf897f9b0476b2b1d7d2007c3f Mon Sep 17 00:00:00 2001 From: Michael Liao <[email protected]> Date: Mon, 27 Aug 2012 15:26:07 -0700 Subject: [PATCH] fix PR13704 - the increment needs to be signed value to preserve the original when the original type is larger than 64-bit integer --- lib/CodeGen/CGExprScalar.cpp | 2 +- test/CodeGen/pr13704.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/pr13704.c 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 @@ 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. diff --git a/test/CodeGen/pr13704.c b/test/CodeGen/pr13704.c new file mode 100644 index 0000000..fc161c0 --- /dev/null +++ b/test/CodeGen/pr13704.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s +int main() { + __int128 x = 2; + x--; + printf("%lx %lx\n", ((long*)(&x))[0], ((long*)(&x))[1]); +// CHECK: add nsw i128 %0, -1 +} -- 1.7.9.5
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
