This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR43017, another -fwrapv strict-overflow miscompile
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 10 Feb 2010 17:50:28 +0100 (CET)
- Subject: [PATCH] Fix PR43017, another -fwrapv strict-overflow miscompile
If we're not interested in special handling we shouldn't process it
as if we were.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
This fixes another python miscompile.
Richard.
2010-02-10 Richard Guenther <rguenther@suse.de>
PR tree-optimization/43017
* tree-vrp.c (vrp_int_const_binop): Trust int_const_binop
for wrapping signed arithmetic.
* gcc.dg/torture/pr43017.c: New testcase.
Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c (revision 156652)
--- gcc/tree-vrp.c (working copy)
*************** vrp_int_const_binop (enum tree_code code
*** 1937,1942 ****
--- 1937,1946 ----
}
}
+ else if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (val1)))
+ /* If the singed operation wraps then int_const_binop has done
+ everything we want. */
+ ;
else if ((TREE_OVERFLOW (res)
&& !TREE_OVERFLOW (val1)
&& !TREE_OVERFLOW (val2))
Index: gcc/testsuite/gcc.dg/torture/pr43017.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr43017.c (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr43017.c (revision 0)
***************
*** 0 ****
--- 1,99 ----
+ /* { dg-do run } */
+ /* { dg-options "-fwrapv" } */
+
+ signed char foo(unsigned char c2)
+ {
+ signed char c2_22;
+
+ if (c2 <= 63 || c2 == 127)
+ goto bb43;
+ else
+ goto bb20;
+
+ bb20:
+ if (c2 > 252)
+ goto bb43;
+ else
+ goto bb21;
+
+ bb21:
+ /*...*/;
+
+ bb24:
+ c2_22 = (signed char)c2;
+ if (c2_22 >= 0)
+ goto bb25;
+ else
+ goto bb26;
+
+ bb25:
+ c2 = (unsigned char)(c2_22 - 64);
+ goto bb27;
+
+ bb26:
+ c2 = (unsigned char)(c2_22 - 65);
+
+ bb27:
+ if (c2 <= 93)
+ goto bb28;
+ else
+ goto bb29;
+
+ bb28:
+ c2 = c2 + 33;
+ goto bb30;
+
+ bb29:
+ c2 = (unsigned char)((signed char)c2 - 61);
+
+ bb30:
+ return c2;
+
+ bb43:
+ return -1;
+ }
+ extern void abort (void);
+ int main()
+ {
+ signed char res[256] = {
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 52, 53, 54, 55, 56,
+ 57, 58, 59, 60, 61, 62, 63, 64,
+ 65, 66, 67, 68, 69, 70, 71, 72,
+ 73, 74, 75, 76, 77, 78, 79, 80,
+ 81, 82, 83, 84, 85, 86, 87, 88,
+ 89, 90, 91, 92, 93, 94, 95, -1,
+ 96, 97, 98, 99, 100, 101, 102, 103,
+ 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119,
+ 120, 121, 122, 123, 124, 125, 126, 33,
+ 34, 35, 36, 37, 38, 39, 40, 41,
+ 42, 43, 44, 45, 46, 47, 48, 49,
+ 50, 51, 52, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, 65,
+ 66, 67, 68, 69, 70, 71, 72, 73,
+ 74, 75, 76, 77, 78, 79, 80, 81,
+ 82, 83, 84, 85, 86, 87, 88, 89,
+ 90, 91, 92, 93, 94, 95, 96, 97,
+ 98, 99, 100, 101, 102, 103, 104, 105,
+ 106, 107, 108, 109, 110, 111, 112, 113,
+ 114, 115, 116, 117, 118, 119, 120, 121,
+ 122, 123, 124, 125, 126, -1, -1, -1
+ };
+ unsigned int c;
+ for (c = 0; c <= 255; ++c)
+ {
+ if (foo (c) != res[c])
+ abort ();
+ }
+ return 0;
+ }