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

            Bug ID: 99954
           Summary: Copy loop over array of unions at -O3 generates memcpy
                    instead of memmove, resulting in incorrect code
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: doublef.mobile at gmail dot com
  Target Milestone: ---

Created attachment 50521
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50521&action=edit
test case (should exit successfully but halts on assertion error)

The attached code is intended to generate an array of e.g. 1,1,2,3,4,5... (if
called without arguments) but instead generates e.g. 1,1,1,1,1 as the loop in
move() is incorrectly optimized to memcpy. The issue has been detected on x86,
amd64 and mips.

As checked on godbolt.org, issue applies to GCC 7+ (6 and below correctly
generate memmove); using -O2 "fixes" the issue on GCC 9 and below but not on
10.

If "#define CONTAINER_KIND struct" is used instead, the issue is not triggered.

Reply via email to