1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s --implicit-check-not=should_not_appear_in_output --check-prefixes=CHECK,NULL-INVALID
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -fno-delete-null-pointer-checks -o - | FileCheck %s --implicit-check-not=should_not_appear_in_output --check-prefixes=CHECK,NULL-VALID
4 struct Member
{ int x
; Member(); Member(int); Member(const Member
&); };
5 struct VBase
{ int x
; VBase(); VBase(int); VBase(const VBase
&); };
8 ValueClass(int x
, int y
) : x(x
), y(y
) {}
11 }; // subject to ABI trickery
15 /* Test basic functionality. */
17 A(struct Undeclared
&);
22 A::A(struct Undeclared
&ref
) : mem(0) {}
24 // Check that delegation works.
25 // NULL-INVALID-LABEL: define{{.*}} void @_ZN1AC2ER10Undeclared(%struct.A* {{[^,]*}} %this, %struct.Undeclared* noundef nonnull align 1 %ref) unnamed_addr
26 // NULL-VALID-LABEL: define{{.*}} void @_ZN1AC2ER10Undeclared(%struct.A* {{[^,]*}} %this, %struct.Undeclared* noundef align 1 %ref) unnamed_addr
27 // CHECK: call void @_ZN6MemberC1Ei(
29 // NULL-INVALID-LABEL: define{{.*}} void @_ZN1AC1ER10Undeclared(%struct.A* {{[^,]*}} %this, %struct.Undeclared* noundef nonnull align 1 %ref) unnamed_addr
30 // NULL-VALID-LABEL: define{{.*}} void @_ZN1AC1ER10Undeclared(%struct.A* {{[^,]*}} %this, %struct.Undeclared* noundef align 1 %ref) unnamed_addr
31 // CHECK: call void @_ZN1AC2ER10Undeclared(
33 A::A(ValueClass v
) : mem(v
.y
- v
.x
) {}
35 // CHECK-LABEL: define{{.*}} void @_ZN1AC2E10ValueClass(%struct.A* {{[^,]*}} %this, i64 %v.coerce) unnamed_addr
36 // CHECK: call void @_ZN6MemberC1Ei(
38 // CHECK-LABEL: define{{.*}} void @_ZN1AC1E10ValueClass(%struct.A* {{[^,]*}} %this, i64 %v.coerce) unnamed_addr
39 // CHECK: call void @_ZN1AC2E10ValueClass(
41 /* Test that things work for inheritance. */
43 B(struct Undeclared
&);
47 B::B(struct Undeclared
&ref
) : A(ref
), mem(1) {}
49 // NULL-INVALID-LABEL: define{{.*}} void @_ZN1BC2ER10Undeclared(%struct.B* {{[^,]*}} %this, %struct.Undeclared* noundef nonnull align 1 %ref) unnamed_addr
50 // NULL-VALID-LABEL: define{{.*}} void @_ZN1BC2ER10Undeclared(%struct.B* {{[^,]*}} %this, %struct.Undeclared* noundef align 1 %ref) unnamed_addr
51 // CHECK: call void @_ZN1AC2ER10Undeclared(
52 // CHECK: call void @_ZN6MemberC1Ei(
54 // NULL-INVALID-LABEL: define{{.*}} void @_ZN1BC1ER10Undeclared(%struct.B* {{[^,]*}} %this, %struct.Undeclared* noundef nonnull align 1 %ref) unnamed_addr
55 // NULL-VALID-LABEL: define{{.*}} void @_ZN1BC1ER10Undeclared(%struct.B* {{[^,]*}} %this, %struct.Undeclared* noundef align 1 %ref) unnamed_addr
56 // CHECK: call void @_ZN1BC2ER10Undeclared(
59 /* Test that the delegation optimization is disabled for classes with
60 virtual bases (for now). This is necessary because a vbase
61 initializer could access one of the parameter variables by
62 reference. That's a solvable problem, but let's not solve it right
64 struct C
: virtual A
{
68 C::C(int x
) : A(ValueClass(x
, x
+1)), mem(x
* x
) {}
70 // CHECK-LABEL: define{{.*}} void @_ZN1CC2Ei(%struct.C* {{[^,]*}} %this, i8** noundef %vtt, i32 noundef %x) unnamed_addr
71 // CHECK: call void @_ZN6MemberC1Ei(
73 // CHECK-LABEL: define{{.*}} void @_ZN1CC1Ei(%struct.C* {{[^,]*}} %this, i32 noundef %x) unnamed_addr
74 // CHECK: call void @_ZN10ValueClassC1Eii(
75 // CHECK: call void @_ZN1AC2E10ValueClass(
76 // CHECK: call void @_ZN6MemberC1Ei(
79 /* Test that the delegation optimization is disabled for varargs
86 D::D(int x
, ...) : A(ValueClass(x
, x
+1)), mem(x
*x
) {}
88 // CHECK-LABEL: define{{.*}} void @_ZN1DC2Eiz(%struct.D* {{[^,]*}} %this, i32 noundef %x, ...) unnamed_addr
89 // CHECK: call void @_ZN10ValueClassC1Eii(
90 // CHECK: call void @_ZN1AC2E10ValueClass(
91 // CHECK: call void @_ZN6MemberC1Ei(
93 // CHECK-LABEL: define{{.*}} void @_ZN1DC1Eiz(%struct.D* {{[^,]*}} %this, i32 noundef %x, ...) unnamed_addr
94 // CHECK: call void @_ZN10ValueClassC1Eii(
95 // CHECK: call void @_ZN1AC2E10ValueClass(
96 // CHECK: call void @_ZN6MemberC1Ei(
98 // PR6622: this shouldn't crash
101 struct B
: virtual A
{ int x
; };
110 struct A
{ A(); void *ptr
; };
111 struct B
{ B(); int x
; A a
[0]; };
113 // CHECK-LABEL: define{{.*}} void @_ZN5test11BC2Ev(
114 // CHECK: [[THIS:%.*]] = load [[B:%.*]]*, [[B:%.*]]**
115 // CHECK-NEXT: ret void
119 // a) emit the ABI-required but useless complete object and deleting destructor
120 // symbols for an abstract class, and
121 // b) do *not* emit references to virtual base destructors for an abstract class
123 // Our approach to this is to give these functions a body that simply traps.
125 // FIXME: We should ideally not create these symbols at all, but Clang can
126 // actually generate references to them in other TUs in some cases, so we can't
127 // stop emitting them without breaking ABI. See:
129 // https://github.com/itanium-cxx-abi/cxx-abi/issues/10
131 // Note, the destructor of this class is not instantiated here.
132 template<typename T
> struct should_not_appear_in_output
{
133 ~should_not_appear_in_output() { int arr
[-(int)sizeof(T
)]; }
138 struct A
: virtual should_not_appear_in_output
<int>, X
{
142 // CHECK-LABEL: define{{.*}} void @_ZN8abstract1AD2Ev(
143 // CHECK: call {{.*}}@_ZN8abstract1XD2Ev(
146 // CHECK-LABEL: define{{.*}} void @_ZN8abstract1AD1Ev(
147 // CHECK: call {{.*}}@llvm.trap(
148 // CHECK: unreachable
150 // CHECK-LABEL: define{{.*}} void @_ZN8abstract1AD0Ev(
151 // CHECK: call {{.*}}@llvm.trap(
152 // CHECK: unreachable
155 struct B
: virtual should_not_appear_in_output
<int>, X
{
156 virtual void f() = 0;
160 // CHECK-LABEL: define{{.*}} void @_ZN8abstract1BD2Ev(
161 // CHECK: call {{.*}}@_ZN8abstract1XD2Ev(
164 // CHECK-LABEL: define{{.*}} void @_ZN8abstract1BD1Ev(
165 // CHECK: call {{.*}}@llvm.trap(
166 // CHECK: unreachable
168 // CHECK-NOT: @_ZN8abstract1BD0Ev(