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

            Bug ID: 111154
           Summary: vect-cost-model=dynamic triggers false warning on
                    array operation
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: changyp6 at gmail dot com
  Target Milestone: ---

Created attachment 55792
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55792&action=edit
Test case of vect-cost-model

I have a program, which operates on an array, which size is defined by a macro.

When compiling this code, GCC always reports following warnings:
```
test.c:35:18: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
   35 |         desta[i] = src[i];
      |         ~~~~~~~~~^~~~~~~~
test.c:7:16: note: at offset 8 into destination object 'desta' of size 8
    7 | static uint8_t desta[ARRAY_SIZE];
      |                ^~~~~
test.c:35:18: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
   35 |         desta[i] = src[i];
      |         ~~~~~~~~~^~~~~~~~
test.c:7:16: note: at offset 9 into destination object 'desta' of size 8
    7 | static uint8_t desta[ARRAY_SIZE];
      |                ^~~~~
test.c:35:18: warning: writing 1 byte into a region of size 0
[-Wstringop-overflow=]
   35 |         desta[i] = src[i];
      |         ~~~~~~~~~^~~~~~~~
```
After digging on this issue, I found that this warning is triggered by 
`-fvect-cost-model=dynamic`, in -O3
`-fvect-cost-model=very-cheap` won't trigger this warning.

Attached is the test case program, just run
`make bugs`
to produce this false warning

This source code file has 3 functions, each function has a for-loop to operate
the array.
The upper bound of the for-loop is determined by a global static variable,
which will be set by another function.

If I remove 1 function which operate on the array, this warning won't show up.
It seems that this issue is related to loop-vectorization, if there are enough
loops, loop-vectorization will be triggered, and the array's bound is an
variable, which cannot be determined directly by GCC, in this case, GCC
vectorize the loop, accessed regions outside of the array.

Reply via email to