public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99431] New: Return value of __builtin_memset() incorrect if partially optimized away
@ 2021-03-06 16:56 jonathon.reinhart at gmail dot com
  2021-03-06 18:09 ` [Bug c/99431] " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jonathon.reinhart at gmail dot com @ 2021-03-06 16:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99431
           Summary: Return value of __builtin_memset() incorrect if
                    partially optimized away
           Product: gcc
           Version: 9.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jonathon.reinhart at gmail dot com
  Target Milestone: ---

Created attachment 50319
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50319&action=edit
Minimal example

Please see attached code or https://godbolt.org/z/oTMhsd.

If the address of a struct object is passed to __builtin_memset(), and some
leading fields are assigned elsewhere in the function, GCC may effectively
adjust the portion of the object written to by the memset(), to eliminate
redundant writes. However, the return value of memset(), which should always
match the first argument, is also (incorrectly) adjusted, leading to an invalid
result.

Specifically, this happens with -Os. I attempted to narrow this down to a
specific set of optimizations by testing everything listed in the output of
this command, but that was insufficient to reproduce the problem:

  gcc -Q -Os --help=optimizers

I found it interesting, although not surprising, that adding this between the
__builtin_memset() call and the "other" assignments caused the problem to go
away: 

    __asm__("" :::"memory");

GCC versions tested:
  10.2 OK
  10.1 OK
  9.3  Broken
  8.3  Broken
  7.3  Broken
  7.2  Broke
  7.1  Broken
  6.3  OK

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

* [Bug c/99431] Return value of __builtin_memset() incorrect if partially optimized away
  2021-03-06 16:56 [Bug c/99431] New: Return value of __builtin_memset() incorrect if partially optimized away jonathon.reinhart at gmail dot com
@ 2021-03-06 18:09 ` jakub at gcc dot gnu.org
  2021-03-06 18:10 ` jakub at gcc dot gnu.org
  2021-03-06 18:18 ` jonathon.reinhart at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-06 18:09 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
On the trunk started with r7-5965-g7c9560a578a06125cb30458a26605f91feb29b0d
and got fixed with r10-7140-g349ab34dc64a10fe0b1eda66d13b62862878b73e

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

* [Bug c/99431] Return value of __builtin_memset() incorrect if partially optimized away
  2021-03-06 16:56 [Bug c/99431] New: Return value of __builtin_memset() incorrect if partially optimized away jonathon.reinhart at gmail dot com
  2021-03-06 18:09 ` [Bug c/99431] " jakub at gcc dot gnu.org
@ 2021-03-06 18:10 ` jakub at gcc dot gnu.org
  2021-03-06 18:18 ` jonathon.reinhart at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-06 18:10 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So dup.

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

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

* [Bug c/99431] Return value of __builtin_memset() incorrect if partially optimized away
  2021-03-06 16:56 [Bug c/99431] New: Return value of __builtin_memset() incorrect if partially optimized away jonathon.reinhart at gmail dot com
  2021-03-06 18:09 ` [Bug c/99431] " jakub at gcc dot gnu.org
  2021-03-06 18:10 ` jakub at gcc dot gnu.org
@ 2021-03-06 18:18 ` jonathon.reinhart at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jonathon.reinhart at gmail dot com @ 2021-03-06 18:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathon Reinhart <jonathon.reinhart at gmail dot com> ---
Yep, that's it. I figured there had to be a dup, but couldn't find it. Thanks
Jakub.

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-06 16:56 [Bug c/99431] New: Return value of __builtin_memset() incorrect if partially optimized away jonathon.reinhart at gmail dot com
2021-03-06 18:09 ` [Bug c/99431] " jakub at gcc dot gnu.org
2021-03-06 18:10 ` jakub at gcc dot gnu.org
2021-03-06 18:18 ` jonathon.reinhart at gmail dot com

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).