public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] make -Wformat-overflow consistent between data models
@ 2019-02-23  3:00 Martin Sebor
  2019-02-23  9:55 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Sebor @ 2019-02-23  3:00 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

A few tests recently added for PR 88993 introduced an assumption
on the host compiler's data model that breaks between ILP32 and
LP64, causing failures test run failures
(see https://gcc.gnu.org/ml/gcc-patches/2019-02/msg01867.html).
Rather than avoiding the problem in the tests the attached patch
removes the data model assumption from the sprintf pass itself,
making the warnings emitted by the pass consistent regardless.

Bootstrapped and tested on x86_64-linux, and smoke-tested with
an i386-linux GCC.

Martin

[-- Attachment #2: gcc-printf-excess-width.diff --]
[-- Type: text/x-patch, Size: 3026 bytes --]

gcc/ChangeLog:

	* gimple-ssa-sprintf.c (target_strtol): Rename...
	(target_strtohwi): ...to this.  Handle values up to HOST_WIDE_INT_MAX.
	(parse_directive): Adjust to name change.  Use HOST_WIDE_INT_MAX to
	check for range error.

Index: gcc/gimple-ssa-sprintf.c
===================================================================
--- gcc/gimple-ssa-sprintf.c	(revision 269136)
+++ gcc/gimple-ssa-sprintf.c	(working copy)
@@ -411,12 +411,12 @@ target_to_host (char *hostr, size_t hostsz, const
 }
 
 /* Convert the sequence of decimal digits in the execution character
-   starting at S to a long, just like strtol does.  Return the result
-   and set *END to one past the last converted character.  On range
-   error set ERANGE to the digit that caused it.  */
+   starting at *PS to a HOST_WIDE_INT, analogously to strtol.  Return
+   the result and set *PS to one past the last converted character.
+   On range error set ERANGE to the digit that caused it.  */
 
-static inline long
-target_strtol10 (const char **ps, const char **erange)
+static inline HOST_WIDE_INT
+target_strtowi (const char **ps, const char **erange)
 {
   unsigned HOST_WIDE_INT val = 0;
   for ( ; ; ++*ps)
@@ -427,9 +427,9 @@ target_to_host (char *hostr, size_t hostsz, const
 	  c -= '0';
 
 	  /* Check for overflow.  */
-	  if (val > (LONG_MAX - c) / 10LU)
+	  if (val > ((unsigned HOST_WIDE_INT) HOST_WIDE_INT_MAX - c) / 10LU)
 	    {
-	      val = LONG_MAX;
+	      val = HOST_WIDE_INT_MAX;
 	      *erange = *ps;
 
 	      /* Skip the remaining digits.  */
@@ -3149,7 +3149,7 @@ parse_directive (sprintf_dom_walker::call_info &in
 	 width and sort it out later after the next character has
 	 been seen.  */
       pwidth = pf;
-      width = target_strtol10 (&pf, &werange);
+      width = target_strtowi (&pf, &werange);
     }
   else if (target_to_host (*pf) == '*')
     {
@@ -3231,7 +3231,7 @@ parse_directive (sprintf_dom_walker::call_info &in
 	{
 	  werange = 0;
 	  pwidth = pf;
-	  width = target_strtol10 (&pf, &werange);
+	  width = target_strtowi (&pf, &werange);
 	}
       else if (target_to_host (*pf) == '*')
 	{
@@ -3264,7 +3264,7 @@ parse_directive (sprintf_dom_walker::call_info &in
       if (ISDIGIT (target_to_host (*pf)))
 	{
 	  pprec = pf;
-	  precision = target_strtol10 (&pf, &perange);
+	  precision = target_strtowi (&pf, &perange);
 	}
       else if (target_to_host (*pf) == '*')
 	{
@@ -3418,7 +3418,7 @@ parse_directive (sprintf_dom_walker::call_info &in
     }
   else
     {
-      if (width == LONG_MAX && werange)
+      if (width == HOST_WIDE_INT_MAX && werange)
 	{
 	  size_t begin = dir.beg - info.fmtstr + (pwidth - pcnt);
 	  size_t caret = begin + (werange - pcnt);
@@ -3451,7 +3451,7 @@ parse_directive (sprintf_dom_walker::call_info &in
     }
   else
     {
-      if (precision == LONG_MAX && perange)
+      if (precision == HOST_WIDE_INT_MAX && perange)
 	{
 	  size_t begin = dir.beg - info.fmtstr + (pprec - pcnt) - 1;
 	  size_t caret = dir.beg - info.fmtstr + (perange - pcnt) - 1;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] make -Wformat-overflow consistent between data models
  2019-02-23  3:00 [PATCH] make -Wformat-overflow consistent between data models Martin Sebor
@ 2019-02-23  9:55 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2019-02-23  9:55 UTC (permalink / raw)
  To: Martin Sebor; +Cc: gcc-patches

On Fri, Feb 22, 2019 at 07:25:53PM -0700, Martin Sebor wrote:
> A few tests recently added for PR 88993 introduced an assumption
> on the host compiler's data model that breaks between ILP32 and
> LP64, causing failures test run failures
> (see https://gcc.gnu.org/ml/gcc-patches/2019-02/msg01867.html).
> Rather than avoiding the problem in the tests the attached patch
> removes the data model assumption from the sprintf pass itself,
> making the warnings emitted by the pass consistent regardless.
> 
> Bootstrapped and tested on x86_64-linux, and smoke-tested with
> an i386-linux GCC.
> 
> Martin

> gcc/ChangeLog:
> 
> 	* gimple-ssa-sprintf.c (target_strtol): Rename...
> 	(target_strtohwi): ...to this.  Handle values up to HOST_WIDE_INT_MAX.
> 	(parse_directive): Adjust to name change.  Use HOST_WIDE_INT_MAX to
> 	check for range error.

Ok.

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-23  8:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-23  3:00 [PATCH] make -Wformat-overflow consistent between data models Martin Sebor
2019-02-23  9:55 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).