2011-07-07 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 7 Jul 2011 14:21:21 +0000 (14:21 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 7 Jul 2011 14:21:21 +0000 (14:21 +0000)
* fold-const.c (fold_unary_loc): Do not strip sign-changes
for NEGATE_EXPR.

* gcc.dg/ftrapv-3.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@175976 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ftrapv-3.c [new file with mode: 0644]

index f3b7c11..7a7c0ec 100644 (file)
@@ -1,5 +1,10 @@
 2011-07-07  Richard Guenther  <rguenther@suse.de>
 
+       * fold-const.c (fold_unary_loc): Do not strip sign-changes
+       for NEGATE_EXPR.
+
+2011-07-07  Richard Guenther  <rguenther@suse.de>
+
        * tree-vrp.c (simplify_conversion_using_ranges): New function.
        (simplify_stmt_using_ranges): Call it.
 
index e48aae9..44a8b6f 100644 (file)
@@ -7561,7 +7561,7 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
   if (arg0)
     {
       if (CONVERT_EXPR_CODE_P (code)
-         || code == FLOAT_EXPR || code == ABS_EXPR)
+         || code == FLOAT_EXPR || code == ABS_EXPR || code == NEGATE_EXPR)
        {
          /* Don't use STRIP_NOPS, because signedness of argument type
             matters.  */
index 910a333..1800d48 100644 (file)
@@ -1,5 +1,9 @@
 2011-07-07  Richard Guenther  <rguenther@suse.de>
 
+       * gcc.dg/ftrapv-3.c: New testcase.
+
+2011-07-07  Richard Guenther  <rguenther@suse.de>
+
        * gcc.dg/tree-ssa/vrp58.c: New testcase.
        * gcc.dg/tree-ssa/scev-cast.c: Adjust.
 
diff --git a/gcc/testsuite/gcc.dg/ftrapv-3.c b/gcc/testsuite/gcc.dg/ftrapv-3.c
new file mode 100644 (file)
index 0000000..e23059a
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+/* { dg-options "-ftrapv" } */
+
+extern void abort (void);
+unsigned long
+foo (long i, long j)
+{
+  /* We may not fold this to (unsigned long)(i * j).  */
+  return -(unsigned long)(i * -j);
+}
+int main()
+{
+  if (foo (-__LONG_MAX__ - 1, -1) != -(unsigned long)(-__LONG_MAX__ - 1))
+    abort ();
+  return 0;
+}