https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79546

            Bug ID: 79546
           Summary: Strange error: missed loop optimization, the loop
                    counter may overflow
                    [-Werror=unsafe-loop-optimizations]
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rjones at redhat dot com
  Target Milestone: ---

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

int f (size_t len);

int
main (int argc, char *argv[])
{
  size_t len;

  if (argc < 2) abort ();
  if (sscanf (argv[1], "%zu", &len) != 1) abort ();

  f (len);

  exit (0);
}

int
f (size_t len)
{
  size_t i;

  i = 0;
  while (i < len) {
    i += 0x1000;
    printf ("page %zu\n", i);
  }
}
-----------------------

When compiled with:

$ gcc -O2 -Werror=unsafe-loop-optimizations test.c -o test
test.c: In function ‘main’:
test.c:25:9: error: missed loop optimization, the loop counter may overflow
[-Werror=unsafe-loop-optimizations]
   while (i < len) {
         ^
test.c: In function ‘f’:
test.c:25:9: error: missed loop optimization, the loop counter may overflow
[-Werror=unsafe-loop-optimizations]
   while (i < len) {
         ^
cc1: some warnings being treated as errors

-----------------------

What I don't understand is what the error means, nor how to correct it.

-----------------------

$ gcc --version
gcc (GCC) 7.0.1 20170204 (Red Hat 7.0.1-0.6)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

From Fedora 26.

Reply via email to