Bug 98561 - -Wstringop-overflow triggered when memcpy to single char and writing to differently sized array members
Summary: -Wstringop-overflow triggered when memcpy to single char and writing to diffe...
Status: RESOLVED DUPLICATE of bug 95353
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 10.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: Wstringop-overflow
  Show dependency treegraph
 
Reported: 2021-01-06 11:14 UTC by Alexander Grund
Modified: 2021-01-06 17:17 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 11.0, 8.3.0, 9.1.0, 9.3.0
Known to fail: 10.1.0, 10.2.0
Last reconfirmed: 2021-01-06 00:00:00


Attachments
Test case to trigger the warning in -O3 (265 bytes, text/x-csrc)
2021-01-06 11:14 UTC, Alexander Grund
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Grund 2021-01-06 11:14:00 UTC
Created attachment 49899 [details]
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.
Comment 1 Martin Sebor 2021-01-06 16:37:29 UTC
Confirmed on the 10 branch.  On trunk it was fixed in r11-1183.

*** This bug has been marked as a duplicate of bug 95353 ***
Comment 2 Alexander Grund 2021-01-06 17:17:08 UTC
I did some work to reduce this further: https://godbolt.org/z/sezTPs

For some reason it seems to be related to std::array. So may I suggest to include the above (or the original reproducer) in the test cases to avoid regressions?