This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Avoid printing host INT_MIN as raw digits
- From: Richard Henderson <rth at redhat dot com>
- To: tm <tm at kloo dot net>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 18 Dec 2003 14:14:35 -0800
- Subject: Re: [PATCH] Avoid printing host INT_MIN as raw digits
- References: <Pine.LNX.4.21.0312181144530.20295-100000@mail.kloo.net>
On Thu, Dec 18, 2003 at 11:46:24AM -0800, tm wrote:
> ! /* These test are to suppress compiler warnings. */
> ! if (p->tests->u.intval == -2147483647-1)
> ! {
> ! printf ("-2147483647-1");
> ! }
> ! else
> ! {
> ! #if HOST_BITS_PER_WIDE_INT == 64
> ! if (p->tests->u.intval == -9223372036854775807-1)
> ! {
> ! printf ("-9223372036854775807-1");
> ! }
> ! else
> ! #endif
> ! {
> ! printf (HOST_WIDE_INT_PRINT_DEC_C, p->tests->u.intval);
> ! }
> ! }
Not the prettiest. I committed this version instead.
r~
* genrecog.c (print_host_wide_int): New.
(write_switch, write_cond): Use it.
Index: genrecog.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/genrecog.c,v
retrieving revision 1.132
diff -c -p -d -r1.132 genrecog.c
*** genrecog.c 21 Nov 2003 06:52:23 -0000 1.132
--- genrecog.c 18 Dec 2003 21:26:35 -0000
*************** write_afterward (struct decision *start,
*** 1734,1739 ****
--- 1734,1753 ----
}
}
+ /* Emit a HOST_WIDE_INT as an integer constant expression. We need to take
+ special care to avoid "decimal constant is so large that it is unsigned"
+ warnings in the resulting code. */
+
+ static void
+ print_host_wide_int (HOST_WIDE_INT val)
+ {
+ HOST_WIDE_INT min = (unsigned HOST_WIDE_INT)1 << (HOST_BITS_PER_WIDE_INT-1);
+ if (val == min)
+ printf ("(" HOST_WIDE_INT_PRINT_DEC_C "-1)", val + 1);
+ else
+ printf (HOST_WIDE_INT_PRINT_DEC_C, val);
+ }
+
/* Emit a switch statement, if possible, for an initial sequence of
nodes at START. Return the first node yet untested. */
*************** write_switch (struct decision *start, in
*** 1907,1913 ****
case DT_elt_one_int:
case DT_elt_zero_wide:
case DT_elt_zero_wide_safe:
! printf (HOST_WIDE_INT_PRINT_DEC_C, p->tests->u.intval);
break;
default:
abort ();
--- 1921,1927 ----
case DT_elt_one_int:
case DT_elt_zero_wide:
case DT_elt_zero_wide_safe:
! print_host_wide_int (p->tests->u.intval);
break;
default:
abort ();
*************** write_cond (struct decision_test *p, int
*** 1964,1970 ****
case DT_elt_zero_wide:
case DT_elt_zero_wide_safe:
printf ("XWINT (x%d, 0) == ", depth);
! printf (HOST_WIDE_INT_PRINT_DEC_C, p->u.intval);
break;
case DT_veclen_ge:
--- 1978,1984 ----
case DT_elt_zero_wide:
case DT_elt_zero_wide_safe:
printf ("XWINT (x%d, 0) == ", depth);
! print_host_wide_int (p->u.intval);
break;
case DT_veclen_ge: