79 lines · cpp
1// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s2 3// PR369924namespace Implicit {5 struct A { char c; A(const A&); };6 struct B { int n; char c[3]; ~B(); };7 struct C : B, virtual A {};8 static_assert(sizeof(C) == sizeof(void*) + 8);9 C f(C c) { return c; }10 11 // CHECK: define {{.*}} @_ZN8Implicit1CC1EOS0_12 // CHECK: call {{.*}} @_ZN8Implicit1AC2ERKS0_(13 // Note: this must memcpy 7 bytes, not 8, to avoid trampling over the virtual base class.14 // CHECK: call void @llvm.memcpy.p0.p0.i{{32|64}}(ptr {{.*}}, ptr {{.*}}, i{{32|64}} 7, i1 false)15 // CHECK: store ptr {{.*}} @_ZTVN8Implicit1CE16}17 18namespace InitWithinNVSize {19 // This is the same as the previous test, except that the A base lies20 // entirely within the nvsize of C. This makes it valid to copy at the21 // full width.22 struct A { char c; A(const A&); };23 struct B { int n; char c[3]; ~B(); };24 struct C : B, virtual A { char x; };25 static_assert(sizeof(C) > sizeof(void*) + 8);26 C f(C c) { return c; }27 28 // CHECK: define {{.*}} @_ZN16InitWithinNVSize1CC1EOS0_29 // CHECK: call {{.*}} @_ZN16InitWithinNVSize1AC2ERKS0_(30 // This copies over the 'C::x' member, but that's OK because we've not initialized it yet.31 // CHECK: call void @llvm.memcpy.p0.p0.i{{32|64}}(ptr {{.*}}, ptr {{.*}}, i{{32|64}} 8, i1 false)32 // CHECK: store ptr {{.*}} @_ZTVN16InitWithinNVSize1CE33 // CHECK: store i834}35 36namespace NoUniqueAddr {37 struct A { char c; A(const A&); };38 struct B { int n; char c[3]; ~B(); };39 struct C : virtual A { B b; };40 struct D : virtual A { [[no_unique_address]] B b; };41 struct E : virtual A { [[no_unique_address]] B b; char x; };42 static_assert(sizeof(C) == sizeof(void*) + 8 + alignof(void*));43 static_assert(sizeof(D) == sizeof(void*) + 8);44 static_assert(sizeof(E) == sizeof(void*) + 8 + alignof(void*));45 46 // CHECK: define {{.*}} @_ZN12NoUniqueAddr1CC1EOS0_47 // CHECK: call {{.*}} @_ZN12NoUniqueAddr1AC2ERKS0_(48 // CHECK: store ptr {{.*}} @_ZTVN12NoUniqueAddr1CE49 // Copy the full size of B.50 // CHECK: call void @llvm.memcpy.p0.p0.i{{32|64}}(ptr {{.*}}, ptr {{.*}}, i{{32|64}} 8, i1 false)51 C f(C c) { return c; }52 53 // CHECK: define {{.*}} @_ZN12NoUniqueAddr1DC1EOS0_54 // CHECK: call {{.*}} @_ZN12NoUniqueAddr1AC2ERKS0_(55 // CHECK: store ptr {{.*}} @_ZTVN12NoUniqueAddr1DE56 // Copy just the data size of B, to avoid overwriting the A base class.57 // CHECK: call void @llvm.memcpy.p0.p0.i{{32|64}}(ptr {{.*}}, ptr {{.*}}, i{{32|64}} 7, i1 false)58 D f(D d) { return d; }59 60 // CHECK: define {{.*}} @_ZN12NoUniqueAddr1EC1EOS0_61 // CHECK: call {{.*}} @_ZN12NoUniqueAddr1AC2ERKS0_(62 // CHECK: store ptr {{.*}} @_ZTVN12NoUniqueAddr1EE63 // We can copy the full size of B here. (As it happens, we fold the copy of 'x' into64 // this memcpy, so we're copying 8 bytes either way.)65 // CHECK: call void @llvm.memcpy.p0.p0.i{{32|64}}(ptr {{.*}}, ptr {{.*}}, i{{32|64}} 8, i1 false)66 E f(E e) { return e; }67 68 struct F : virtual A {69 F(const F &o) : A(o), b(o.b) {}70 [[no_unique_address]] B b;71 };72 73 // CHECK: define {{.*}} @_ZN12NoUniqueAddr1FC1ERKS0_74 // CHECK: call {{.*}} @_ZN12NoUniqueAddr1AC2ERKS0_(75 // CHECK: store ptr {{.*}} @_ZTVN12NoUniqueAddr1FE76 // CHECK: call void @llvm.memcpy.p0.p0.i{{32|64}}(ptr {{.*}}, ptr {{.*}}, i{{32|64}} 7, i1 false)77 F f(F x) { return x; }78}79