]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/34130 (the builtin abs() gives wrong result when used...
authorMatthias Klose <doko@ubuntu.com>
Thu, 29 Nov 2007 00:32:58 +0000 (00:32 +0000)
committerMatthias Klose <doko@gcc.gnu.org>
Thu, 29 Nov 2007 00:32:58 +0000 (00:32 +0000)
gcc/
2007-11-29  Matthias Klose  <doko@ubuntu.com>

       Backport from mainline:
       2007-11-17  Richard Guenther  <rguenther@suse.de>

       PR middle-end/34130
       * fold-const.c (extract_muldiv_1): Do not move negative
       constants inside ABS_EXPR.

gcc/testsuite/

2007-11-29  Matthias Klose  <doko@ubuntu.com>

       Backport from mainline:
       2007-11-17  Richard Guenther  <rguenther@suse.de>

       PR middle-end/34130
       * gcc.c-torture/execute/pr34130.c: New testcase.

From-SVN: r130507

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr34130.c [new file with mode: 0644]

index 8de09945cf25c643d7b7c968bed66d394273848d..004fe65d80534e62dba34db50be8861e9ea2471f 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-29  Matthias Klose  <doko@ubuntu.com>
+
+       Backport from mainline:
+       2007-11-17  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/34130
+       * fold-const.c (extract_muldiv_1): Do not move negative
+       constants inside ABS_EXPR.
+
 2007-11-16  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/34030
index f031825f7bab7f820f580f153fd387304cc27041..f9e58d27591061608ca96afd400696c9cb481061 100644 (file)
@@ -5340,6 +5340,9 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type)
             }
           break;
         }
+      /* If the constant is negative, we cannot simplify this.  */
+      if (tree_int_cst_sgn (c) == -1)
+        break;
       /* FALLTHROUGH */
     case NEGATE_EXPR:
       if ((t1 = extract_muldiv (op0, c, code, wide_type)) != 0)
index 7efd5b698d96ae42a96407d053bb450ebd976474..7b78678753e6fec0a8d4574fa3441c3688ced853 100644 (file)
@@ -1,3 +1,11 @@
+2007-11-29  Matthias Klose  <doko@ubuntu.com>
+
+       Backport from mainline:
+       2007-11-17  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/34130
+       * gcc.c-torture/execute/pr34130.c: New testcase.
+
 2007-11-16  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/34030
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr34130.c b/gcc/testsuite/gcc.c-torture/execute/pr34130.c
new file mode 100644 (file)
index 0000000..b528ff2
--- /dev/null
@@ -0,0 +1,12 @@
+extern void abort (void);
+int foo (int i)
+{
+  return -2 * __builtin_abs(i - 2);
+}
+int main()
+{
+  if (foo(1) != -2
+      || foo(3) != -2)
+    abort ();
+  return 0;
+}