]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/8224 (Incorrect joining of signed and unsigned division)
authorMark Mitchell <mmitchel@gcc.gnu.org>
Sun, 23 Mar 2003 22:57:26 +0000 (22:57 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sun, 23 Mar 2003 22:57:26 +0000 (22:57 +0000)
PR c/8224
* fold-const.c (extract_muldiv_1): Don't pass through type conversions
when signedness changes for division or modulus.

PR c/8224
* gcc.dg/20030323-1.c: New test.

From-SVN: r64760

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

index fc8f41838f794a4fac533052f6a619acc726b23d..596e91e09848b6f356eabcf6adca6d16a8d3c26e 100644 (file)
@@ -1,3 +1,9 @@
+2003-03-23  Glen Nakamura <glen@imodulo.com>
+
+       PR c/8224
+       * fold-const.c (extract_muldiv_1): Don't pass through type conversions
+       when signedness changes for division or modulus.
+
 2003-03-24  Alan Modra  <amodra@bigpond.net.au>
 
        * config/rs6000/sysv4.h (ASM_OUTPUT_ALIGNED_BSS): Remove unnecessary
index 7b051fa8a6ebfcf73b99a8904351e3bcbea84cc3..0f9f3d419a57074e4bd8eb59dfea0859e744b71c 100644 (file)
@@ -4170,7 +4170,12 @@ extract_muldiv_1 (t, c, code, wide_type)
              /* ... or its type is larger than ctype,
                 then we cannot pass through this truncation.  */
              || (GET_MODE_SIZE (TYPE_MODE (ctype))
-                 < GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0))))))
+                 < GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0))))
+             /* ... or signedness changes for division or modulus,
+                then we cannot pass through this conversion.  */
+             || (code != MULT_EXPR
+                 && (TREE_UNSIGNED (ctype)
+                     != TREE_UNSIGNED (TREE_TYPE (op0))))))
        break;
 
       /* Pass the constant down and see if we can make a simplification.  If
index 05b170ca1850e14202d605da3f792d03b81b2e98..9db85358f04b0a911712d65c19eb72b6384edd6d 100644 (file)
@@ -1,3 +1,8 @@
+2003-03-23  Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
+
+       PR c/8224
+       * gcc.dg/20030323-1.c: New test.
+
 2003-03-23  Roger Sayle  <roger@eyesopen.com>
 
        * gcc.c-torture/compile/20030323-1.c: New test case.
diff --git a/gcc/testsuite/gcc.dg/20030323-1.c b/gcc/testsuite/gcc.dg/20030323-1.c
new file mode 100644 (file)
index 0000000..8a563ec
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+
+/* PR c/8224 */
+/* Contributed by Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz> */
+
+extern void abort (void);
+
+unsigned f (int x)
+{
+  return (unsigned) (x / 2) / 2;
+}
+
+unsigned f1 (int x)
+{
+  unsigned xx = x / 2;
+  return xx / 2;
+}
+
+int main ()
+{
+  if (f1 (-5) != f (-5))
+    abort ();
+  return 0;
+}