On Mon, 2012-08-27 at 17:07 -0700, Matt Beaumont-Gay wrote:
> This looks pretty reasonable, but the testcase probably doesn't need
> to have a printf call in it.

Test case is revised to call an external function instead of printf.
please let me know whether it's OK to commit.

Yours
- Michael

> 
> On Mon, Aug 27, 2012 at 3:57 PM, Michael Liao <[email protected]> wrote:
> > 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
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > [email protected]
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >

>From cb0697bd0103ede476d44d8d9b7eb9e6794cfd9c 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 value
  when its data type is larger than 64-bit integer
---
 lib/CodeGen/CGExprScalar.cpp |    2 +-
 test/CodeGen/pr13704.c       |    9 +++++++++
 2 files changed, 10 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..f03f668
--- /dev/null
+++ b/test/CodeGen/pr13704.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+extern void foo(long, long);
+
+void bar() {
+  __int128 x = 2;
+  x--;
+  foo(((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

Reply via email to