[llvm-bugs] [Bug 36992] New: copy constructor memcpy optimization tramples virtual bases in tail padding

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Apr 3 13:01:48 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=36992

            Bug ID: 36992
           Summary: copy constructor memcpy optimization tramples virtual
                    bases in tail padding
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Testcase:

struct A { char c; A(const A&) : c(1) {} };
struct B { int n; char c[3]; ~B(); };
struct C : B, virtual A {}; C f(C c) { return c; }

The move constructor we emit for C performs an 8-byte memcpy to construct its B
base class, which tramples over the initialization we've already performed for
the A virtual base class.


Similar issues will arise when memcpyizing non-static data members due to P0840
-- http://wg21.link/p0840r2, or http://wg21.link/p0840r1 for the latest
publicly-visible version:

struct A { char c; A(const A&) : c(1) {} };
struct B { int n; char c[3]; ~B(); };
struct C : virtual A { [[no_unique_address]] B b; }; C f(C c) { return c; }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180403/001777f5/attachment.html>


More information about the llvm-bugs mailing list