public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/98561] New: -Wstringop-overflow triggered when memcpy to single char and writing to differently sized array members
@ 2021-01-06 11:14 alexander.grund@tu-dresden.de
  2021-01-06 16:37 ` [Bug middle-end/98561] " msebor at gcc dot gnu.org
  2021-01-06 17:17 ` alexander.grund@tu-dresden.de
  0 siblings, 2 replies; 3+ messages in thread
From: alexander.grund@tu-dresden.de @ 2021-01-06 11:14 UTC (permalink / raw)
  To: gcc-bugs

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.grund@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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/98561] -Wstringop-overflow triggered when memcpy to single char and writing to differently sized array members
  2021-01-06 11:14 [Bug middle-end/98561] New: -Wstringop-overflow triggered when memcpy to single char and writing to differently sized array members alexander.grund@tu-dresden.de
@ 2021-01-06 16:37 ` msebor at gcc dot gnu.org
  2021-01-06 17:17 ` alexander.grund@tu-dresden.de
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-01-06 16:37 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE
                 CC|                            |msebor at gcc dot gnu.org
      Known to work|                            |11.0
   Last reconfirmed|                            |2021-1-6

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed on the 10 branch.  On trunk it was fixed in r11-1183.

*** This bug has been marked as a duplicate of bug 95353 ***

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/98561] -Wstringop-overflow triggered when memcpy to single char and writing to differently sized array members
  2021-01-06 11:14 [Bug middle-end/98561] New: -Wstringop-overflow triggered when memcpy to single char and writing to differently sized array members alexander.grund@tu-dresden.de
  2021-01-06 16:37 ` [Bug middle-end/98561] " msebor at gcc dot gnu.org
@ 2021-01-06 17:17 ` alexander.grund@tu-dresden.de
  1 sibling, 0 replies; 3+ messages in thread
From: alexander.grund@tu-dresden.de @ 2021-01-06 17:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Alexander Grund <alexander.grund@tu-dresden.de> ---
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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-06 17:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06 11:14 [Bug middle-end/98561] New: -Wstringop-overflow triggered when memcpy to single char and writing to differently sized array members alexander.grund@tu-dresden.de
2021-01-06 16:37 ` [Bug middle-end/98561] " msebor at gcc dot gnu.org
2021-01-06 17:17 ` alexander.grund@tu-dresden.de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).