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

            Bug ID: 103956
           Summary: [10 Regression] -Wstringop-overflow= false positive on
                    -O3 for writes to array
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: martin at martin dot st
  Target Milestone: ---

Since GCC 10.0, the following snippet produces warnings (various numbers of
warnings with the same issue) for this reduced snippet:

$ cat repro.c
struct data {
  unsigned char array[10];
};
void copy(struct data *data, unsigned char *src, int n) {
  int i;
  for (i = 0; i < n; i++)
    data->array[i] = src[i];
}
$ gcc -c -O3 repro.c
repro.c: In function 'copy':
repro.c:7:20: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
    7 |     data->array[i] = src[i];
      |     ~~~~~~~~~~~~~~~^~~~~~~~
repro.c:2:17: note: at offset 10 into destination object 'array' of size 10
    2 |   unsigned char array[10];
      |                 ^~~~~


It doesn't reproduce at -O2.

The issue is also testable on Compiler Explorer:
https://godbolt.org/z/xsc3K37jK

Reply via email to