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.
  • [Bug middle-end/11554... mikulas at artax dot karlin.mff.cuni.cz via Gcc-bugs

Reply via email to