Warnings in string/stratcliff.c, wcsmbs/wcsatcliff.c with GCC 7 -O3

Stefan Liebler stli@linux.vnet.ibm.com
Wed Mar 22 14:29:00 GMT 2017


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
-------------- next part --------------
#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;
}


More information about the Libc-alpha mailing list