public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Warnings in string/stratcliff.c, wcsmbs/wcsatcliff.c with GCC 7 -O3
@ 2017-03-22 14:29 Stefan Liebler
  2017-03-22 14:54 ` Wainer dos Santos Moschetta
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Liebler @ 2017-03-22 14:29 UTC (permalink / raw)
  To: libc-alpha

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

Hi,

Compiling string/stratcliff.c with GCC 7 and -O3 leads to the following 
warning/errors on s390x / x86_64:
../test-skeleton.c: In function ‘legacy_test_function’:
cc1: error: assuming signed overflow does not occur when assuming that 
(X - c) <= X is always true [-Werror=strict-overflow]

This error occurs 9 times.
Compiling with -O2 is fine.

The first error occurs for strlen/wcslen tests in line 98 for the 
inner-for-loop. See also the attached smaller testcase.

There's a new pass in GCC 7 and the warning also occurs
with -O2 -fsplit-loops and it disappears with -O3 -fno-split-loops.

The warning also occurs with an extra test which ensures that size is > 
0.  The warning disappears if the outer loop uses "outer >= 0" instead 
of the MAX macro and the extra test is done.

Any ideas how to fix this?
Is this a GCC 7 regression and we should file a bug against GCC 7?

Bye
Stefan

[-- Attachment #2: tst-warn.c --]
[-- Type: text/plain, Size: 1145 bytes --]

#include <stdio.h>
#include <stdlib.h>

/*
  Compiled with GCC 7 -Wall -O3 or -Wall -O2 -fsplit-loops
  cc1: warning: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Wstrict-overflow]
*/

#define MAX(a,b) ((a) > (b) ? (a) : (b))

int main(int argc, char *argv[])
{
  int size = 0;
  if (argc >= 2)
    {
      /* In original testcase: sysconf (_SC_PAGESIZE);  */
      size = strtol (argv[1], NULL, 0);
    }

#if 0
  /* The warning occurs even with this extra check, but the original testcase
     does not check it.
     sysconf (_SC_PAGESIZE) must not return a size less than 1. */
  if (size < 1)
    {
      printf ("size=%d is too small.\n", size);
      return EXIT_FAILURE;
    }
#endif

  int nchars = size / sizeof (char);
  int outer;
  int inner;

  /* Compare with string/stratcliff.c:96  */
#if 1
  for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
#else
  for (outer = nchars - 1; outer >= 0; --outer)
#endif
    {
      for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
	{
	  printf ("outer=%d, inner=%d\n", outer, inner);
	}
    }

  return EXIT_SUCCESS;
}

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

* Re: Warnings in string/stratcliff.c, wcsmbs/wcsatcliff.c with GCC 7 -O3
  2017-03-22 14:29 Warnings in string/stratcliff.c, wcsmbs/wcsatcliff.c with GCC 7 -O3 Stefan Liebler
@ 2017-03-22 14:54 ` Wainer dos Santos Moschetta
  2017-03-23 11:16   ` Stefan Liebler
  0 siblings, 1 reply; 4+ messages in thread
From: Wainer dos Santos Moschetta @ 2017-03-22 14:54 UTC (permalink / raw)
  To: libc-alpha


On 03/22/2017 11:29 AM, Stefan Liebler wrote:
> Hi,
>
> Compiling string/stratcliff.c with GCC 7 and -O3 leads to the following warning/errors on s390x / x86_64:
> ../test-skeleton.c: In function ‘legacy_test_function’:
> cc1: error: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Werror=strict-overflow]

https://sourceware.org/ml/libc-alpha/2017-03/msg00422.html
Could you give a try with above patch in?

It updates the string tests to the support test driver. Above error occurs in the legacy test skeleton. Otherwise the support test-driver will need a fix too.

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

* Re: Warnings in string/stratcliff.c, wcsmbs/wcsatcliff.c with GCC 7 -O3
  2017-03-22 14:54 ` Wainer dos Santos Moschetta
@ 2017-03-23 11:16   ` Stefan Liebler
  2017-08-20 16:50     ` H.J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Liebler @ 2017-03-23 11:16 UTC (permalink / raw)
  To: libc-alpha

On 03/22/2017 03:53 PM, Wainer dos Santos Moschetta wrote:
>
> On 03/22/2017 11:29 AM, Stefan Liebler wrote:
>> Hi,
>>
>> Compiling string/stratcliff.c with GCC 7 and -O3 leads to the following warning/errors on s390x / x86_64:
>> ../test-skeleton.c: In function ‘legacy_test_function’:
>> cc1: error: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Werror=strict-overflow]
>
> https://sourceware.org/ml/libc-alpha/2017-03/msg00422.html
> Could you give a try with above patch in?
>
> It updates the string tests to the support test driver. Above error occurs in the legacy test skeleton. Otherwise the support test-driver will need a fix too.
>

The error does not occur in the legacy test skeleton.  Instead one of 
the errors occur in do_test in string/stratcliff.c around line 96:
       /* strlen/wcslen test */
       for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
	{
	  for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
	    {

I've applied your patch and build the test with GCC 7 -O3:
stratcliff.c: In function ‘do_test’:
cc1: error: assuming signed overflow does not occur when assuming that 
(X - c) <= X is always true [-Werror=strict-overflow]
...

Bye
Stefan

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

* Re: Warnings in string/stratcliff.c, wcsmbs/wcsatcliff.c with GCC 7 -O3
  2017-03-23 11:16   ` Stefan Liebler
@ 2017-08-20 16:50     ` H.J. Lu
  0 siblings, 0 replies; 4+ messages in thread
From: H.J. Lu @ 2017-08-20 16:50 UTC (permalink / raw)
  To: Stefan Liebler; +Cc: GNU C Library

On Thu, Mar 23, 2017 at 4:16 AM, Stefan Liebler <stli@linux.vnet.ibm.com> wrote:
> On 03/22/2017 03:53 PM, Wainer dos Santos Moschetta wrote:
>>
>>
>> On 03/22/2017 11:29 AM, Stefan Liebler wrote:
>>>
>>> Hi,
>>>
>>> Compiling string/stratcliff.c with GCC 7 and -O3 leads to the following
>>> warning/errors on s390x / x86_64:
>>> ../test-skeleton.c: In function ‘legacy_test_function’:
>>> cc1: error: assuming signed overflow does not occur when assuming that (X
>>> - c) <= X is always true [-Werror=strict-overflow]
>>
>>
>> https://sourceware.org/ml/libc-alpha/2017-03/msg00422.html
>> Could you give a try with above patch in?
>>
>> It updates the string tests to the support test driver. Above error occurs
>> in the legacy test skeleton. Otherwise the support test-driver will need a
>> fix too.
>>
>
> The error does not occur in the legacy test skeleton.  Instead one of the
> errors occur in do_test in string/stratcliff.c around line 96:
>       /* strlen/wcslen test */
>       for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
>         {
>           for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
>             {
>
> I've applied your patch and build the test with GCC 7 -O3:
> stratcliff.c: In function ‘do_test’:
> cc1: error: assuming signed overflow does not occur when assuming that (X -
> c) <= X is always true [-Werror=strict-overflow]
> ...

I opened:

https://sourceware.org/bugzilla/show_bug.cgi?id=21982



-- 
H.J.

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

end of thread, other threads:[~2017-08-20 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22 14:29 Warnings in string/stratcliff.c, wcsmbs/wcsatcliff.c with GCC 7 -O3 Stefan Liebler
2017-03-22 14:54 ` Wainer dos Santos Moschetta
2017-03-23 11:16   ` Stefan Liebler
2017-08-20 16:50     ` H.J. Lu

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).