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

            Bug ID: 98561
           Summary: -Wstringop-overflow triggered when memcpy to single
                    char and writing to differently sized array members
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alexander.gr...@tu-dresden.de
  Target Milestone: ---

Created attachment 49899
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49899&action=edit
Test case to trigger the warning in -O3

This looks very similar to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87296
but occurs in GCC 10.0 to 10.2, not before.

The test case triggers the bug when compiled with `gcc -O3` but NOT with `gcc
-O2 -ftree-vectorize` as in the above bug. Instead it is `gcc -O2 -fpeel-loops`

See reproducer on godbolt: https://godbolt.org/z/Ef1Pne

Interesting here is that it does not involve actual OOB access through VLA or
size-0/size-1 hacks and is extremely sensitive. The following changes make the
warning disappear:
- changing the array sizes (some combinations only)
- hiding the memcpy
- using C-Arrays
- using a single array
- removing either for-loop

Also the size of the 2nd array matters for the amount of warnings shown for
that line.

It seems it is already fixed on trunk but all mentioned issues so far involved
a VLA or OOB access so this is not a direct duplicate.

Of course the test code is a reduced MWE but you can guess the purpose.

Reply via email to