1 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
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);
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 {{.*}} @_ZTVN8Implicit1CE
18 namespace InitWithinNVSize
{
19 // This is the same as the previous test, except that the A base lies
20 // entirely within the nvsize of C. This makes it valid to copy at the
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
; }
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 {{.*}} @_ZTVN16InitWithinNVSize1CE
36 namespace 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*));
46 // CHECK: define {{.*}} @_ZN12NoUniqueAddr1CC1EOS0_
47 // CHECK: call {{.*}} @_ZN12NoUniqueAddr1AC2ERKS0_(
48 // CHECK: store ptr {{.*}} @_ZTVN12NoUniqueAddr1CE
49 // 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
; }
53 // CHECK: define {{.*}} @_ZN12NoUniqueAddr1DC1EOS0_
54 // CHECK: call {{.*}} @_ZN12NoUniqueAddr1AC2ERKS0_(
55 // CHECK: store ptr {{.*}} @_ZTVN12NoUniqueAddr1DE
56 // 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
; }
60 // CHECK: define {{.*}} @_ZN12NoUniqueAddr1EC1EOS0_
61 // CHECK: call {{.*}} @_ZN12NoUniqueAddr1AC2ERKS0_(
62 // CHECK: store ptr {{.*}} @_ZTVN12NoUniqueAddr1EE
63 // We can copy the full size of B here. (As it happens, we fold the copy of 'x' into
64 // 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
; }
68 struct F
: virtual A
{
69 F(const F
&o
) : A(o
), b(o
.b
) {}
70 [[no_unique_address
]] B b
;
73 // CHECK: define {{.*}} @_ZN12NoUniqueAddr1FC1ERKS0_
74 // CHECK: call {{.*}} @_ZN12NoUniqueAddr1AC2ERKS0_(
75 // CHECK: store ptr {{.*}} @_ZTVN12NoUniqueAddr1FE
76 // 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
; }