This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/80362] [5/6/7 Regression] gcc miscompiles arithmetic with signed char
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 10 Apr 2017 08:51:50 +0000
- Subject: [Bug middle-end/80362] [5/6/7 Regression] gcc miscompiles arithmetic with signed char
- Auto-submitted: auto-generated
- References: <bug-80362-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80362
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
10205 /* Convert -A / -B to A / B when the type is signed and overflow
is
10206 undefined. */
10207 if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
10208 && TREE_CODE (arg0) == NEGATE_EXPR
10209 && negate_expr_p (op1))
10210 {
where op1 is 3. We're folding (signed char) -(unsigned char) var_1 / 3 and
arg0 is - (unsigned char) var_1 but _unsigned_.
Trivial fix:
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c (revision 246797)
+++ gcc/fold-const.c (working copy)
@@ -10205,7 +10205,7 @@ fold_binary_loc (location_t loc,
/* Convert -A / -B to A / B when the type is signed and overflow is
undefined. */
if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
- && TREE_CODE (arg0) == NEGATE_EXPR
+ && TREE_CODE (op0) == NEGATE_EXPR
&& negate_expr_p (op1))
{
if (INTEGRAL_TYPE_P (type))