public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/115541] New: gcc generates calls to memcpy that violate the memcpy specification
@ 2024-06-18 16:25 mikulas at artax dot karlin.mff.cuni.cz
  2024-06-18 16:28 ` [Bug middle-end/115541] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: mikulas at artax dot karlin.mff.cuni.cz @ 2024-06-18 16:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115541
           Summary: gcc generates calls to memcpy that violate the memcpy
                    specification
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikulas at artax dot karlin.mff.cuni.cz
  Target Milestone: ---

struct s {
        int a[10000];
};

void assign(struct s *s1, struct s *s2)
{
        *s1 = *s2;
}

compiling it with -O2 results in this:

assign:
        subq    $8, %rsp
        movl    $40000, %edx
        call    memcpy@PLT
        addq    $8, %rsp
        ret

The problem is that when we call the function "assign" with s1 equal to s2, gcc
generates a call to memcpy with overlapping arguments and that violates the C
standard.

Note that if the memcpy implementation uses an instruction such as "DC ZVA" to
zero cache line without reading it from memory, this becomes a practical
problem.

gcc should generate memmove instead of memcpy in this case.

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

* [Bug middle-end/115541] gcc generates calls to memcpy that violate the memcpy specification
  2024-06-18 16:25 [Bug middle-end/115541] New: gcc generates calls to memcpy that violate the memcpy specification mikulas at artax dot karlin.mff.cuni.cz
@ 2024-06-18 16:28 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-18 16:28 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.

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

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

end of thread, other threads:[~2024-06-18 16:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-18 16:25 [Bug middle-end/115541] New: gcc generates calls to memcpy that violate the memcpy specification mikulas at artax dot karlin.mff.cuni.cz
2024-06-18 16:28 ` [Bug middle-end/115541] " pinskia at gcc dot gnu.org

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