2022-04-07 18:03:55 +08:00
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s --implicit-check-not=should_not_appear_in_output --check-prefixes=CHECK,NULL-INVALID
|
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -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
|
2010-02-23 08:48:20 +08:00
|
|
|
|
|
|
|
struct Member { int x; Member(); Member(int); Member(const Member &); };
|
|
|
|
struct VBase { int x; VBase(); VBase(int); VBase(const VBase &); };
|
|
|
|
|
|
|
|
struct ValueClass {
|
|
|
|
ValueClass(int x, int y) : x(x), y(y) {}
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
}; // subject to ABI trickery
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Test basic functionality. */
|
2010-04-10 03:03:51 +08:00
|
|
|
struct A {
|
2010-02-23 08:48:20 +08:00
|
|
|
A(struct Undeclared &);
|
|
|
|
A(ValueClass);
|
|
|
|
Member mem;
|
|
|
|
};
|
|
|
|
|
|
|
|
A::A(struct Undeclared &ref) : mem(0) {}
|
|
|
|
|
|
|
|
// Check that delegation works.
|
2022-01-16 17:53:11 +08:00
|
|
|
// NULL-INVALID-LABEL: define{{.*}} void @_ZN1AC2ER10Undeclared(%struct.A* {{[^,]*}} %this, %struct.Undeclared* noundef nonnull align 1 %ref) unnamed_addr
|
|
|
|
// NULL-VALID-LABEL: define{{.*}} void @_ZN1AC2ER10Undeclared(%struct.A* {{[^,]*}} %this, %struct.Undeclared* noundef align 1 %ref) unnamed_addr
|
2010-02-23 08:48:20 +08:00
|
|
|
// CHECK: call void @_ZN6MemberC1Ei(
|
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// NULL-INVALID-LABEL: define{{.*}} void @_ZN1AC1ER10Undeclared(%struct.A* {{[^,]*}} %this, %struct.Undeclared* noundef nonnull align 1 %ref) unnamed_addr
|
|
|
|
// NULL-VALID-LABEL: define{{.*}} void @_ZN1AC1ER10Undeclared(%struct.A* {{[^,]*}} %this, %struct.Undeclared* noundef align 1 %ref) unnamed_addr
|
2013-12-09 22:51:17 +08:00
|
|
|
// CHECK: call void @_ZN1AC2ER10Undeclared(
|
2010-02-23 08:48:20 +08:00
|
|
|
|
2013-12-09 22:51:17 +08:00
|
|
|
A::A(ValueClass v) : mem(v.y - v.x) {}
|
2010-02-23 08:48:20 +08:00
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN1AC2E10ValueClass(%struct.A* {{[^,]*}} %this, i64 %v.coerce) unnamed_addr
|
2010-02-23 08:48:20 +08:00
|
|
|
// CHECK: call void @_ZN6MemberC1Ei(
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN1AC1E10ValueClass(%struct.A* {{[^,]*}} %this, i64 %v.coerce) unnamed_addr
|
2013-12-09 22:51:17 +08:00
|
|
|
// CHECK: call void @_ZN1AC2E10ValueClass(
|
2010-02-23 08:48:20 +08:00
|
|
|
|
|
|
|
/* Test that things work for inheritance. */
|
|
|
|
struct B : A {
|
|
|
|
B(struct Undeclared &);
|
|
|
|
Member mem;
|
|
|
|
};
|
|
|
|
|
|
|
|
B::B(struct Undeclared &ref) : A(ref), mem(1) {}
|
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// NULL-INVALID-LABEL: define{{.*}} void @_ZN1BC2ER10Undeclared(%struct.B* {{[^,]*}} %this, %struct.Undeclared* noundef nonnull align 1 %ref) unnamed_addr
|
|
|
|
// NULL-VALID-LABEL: define{{.*}} void @_ZN1BC2ER10Undeclared(%struct.B* {{[^,]*}} %this, %struct.Undeclared* noundef align 1 %ref) unnamed_addr
|
2010-02-23 08:48:20 +08:00
|
|
|
// CHECK: call void @_ZN1AC2ER10Undeclared(
|
|
|
|
// CHECK: call void @_ZN6MemberC1Ei(
|
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// NULL-INVALID-LABEL: define{{.*}} void @_ZN1BC1ER10Undeclared(%struct.B* {{[^,]*}} %this, %struct.Undeclared* noundef nonnull align 1 %ref) unnamed_addr
|
|
|
|
// NULL-VALID-LABEL: define{{.*}} void @_ZN1BC1ER10Undeclared(%struct.B* {{[^,]*}} %this, %struct.Undeclared* noundef align 1 %ref) unnamed_addr
|
2013-12-09 22:51:17 +08:00
|
|
|
// CHECK: call void @_ZN1BC2ER10Undeclared(
|
2010-02-23 08:48:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Test that the delegation optimization is disabled for classes with
|
|
|
|
virtual bases (for now). This is necessary because a vbase
|
|
|
|
initializer could access one of the parameter variables by
|
|
|
|
reference. That's a solvable problem, but let's not solve it right
|
|
|
|
now. */
|
|
|
|
struct C : virtual A {
|
|
|
|
C(int);
|
|
|
|
Member mem;
|
|
|
|
};
|
|
|
|
C::C(int x) : A(ValueClass(x, x+1)), mem(x * x) {}
|
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN1CC2Ei(%struct.C* {{[^,]*}} %this, i8** noundef %vtt, i32 noundef %x) unnamed_addr
|
2013-12-09 22:51:17 +08:00
|
|
|
// CHECK: call void @_ZN6MemberC1Ei(
|
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN1CC1Ei(%struct.C* {{[^,]*}} %this, i32 noundef %x) unnamed_addr
|
2010-02-23 08:48:20 +08:00
|
|
|
// CHECK: call void @_ZN10ValueClassC1Eii(
|
|
|
|
// CHECK: call void @_ZN1AC2E10ValueClass(
|
|
|
|
// CHECK: call void @_ZN6MemberC1Ei(
|
|
|
|
|
|
|
|
|
|
|
|
/* Test that the delegation optimization is disabled for varargs
|
|
|
|
constructors. */
|
|
|
|
struct D : A {
|
|
|
|
D(int, ...);
|
|
|
|
Member mem;
|
|
|
|
};
|
|
|
|
|
|
|
|
D::D(int x, ...) : A(ValueClass(x, x+1)), mem(x*x) {}
|
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN1DC2Eiz(%struct.D* {{[^,]*}} %this, i32 noundef %x, ...) unnamed_addr
|
2010-02-23 08:48:20 +08:00
|
|
|
// CHECK: call void @_ZN10ValueClassC1Eii(
|
|
|
|
// CHECK: call void @_ZN1AC2E10ValueClass(
|
|
|
|
// CHECK: call void @_ZN6MemberC1Ei(
|
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN1DC1Eiz(%struct.D* {{[^,]*}} %this, i32 noundef %x, ...) unnamed_addr
|
2010-02-23 08:48:20 +08:00
|
|
|
// CHECK: call void @_ZN10ValueClassC1Eii(
|
|
|
|
// CHECK: call void @_ZN1AC2E10ValueClass(
|
|
|
|
// CHECK: call void @_ZN6MemberC1Ei(
|
2010-04-30 13:56:45 +08:00
|
|
|
|
|
|
|
// PR6622: this shouldn't crash
|
|
|
|
namespace test0 {
|
|
|
|
struct A {};
|
|
|
|
struct B : virtual A { int x; };
|
|
|
|
struct C : B {};
|
2018-10-15 23:43:00 +08:00
|
|
|
|
2010-04-30 13:56:45 +08:00
|
|
|
void test(C &in) {
|
|
|
|
C tmp = in;
|
|
|
|
}
|
|
|
|
}
|
2011-07-13 15:37:11 +08:00
|
|
|
|
|
|
|
namespace test1 {
|
|
|
|
struct A { A(); void *ptr; };
|
|
|
|
struct B { B(); int x; A a[0]; };
|
|
|
|
B::B() {}
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN5test11BC2Ev(
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[THIS:%.*]] = load [[B:%.*]]*, [[B:%.*]]**
|
2011-07-13 15:37:11 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules for special member functions.
Essentially, as a base class constructor does not construct virtual bases, such
a constructor for an abstract class does not need the corresponding base class
construction to be valid, and likewise for destructors.
This creates an awkward situation: clang will sometimes generate references to
the complete object and deleting destructors for an abstract class (it puts
them in the construction vtable for a derived class). But we can't generate a
"correct" version of these because we can't generate references to base class
constructors any more (if they're template specializations, say, we might not
have instantiated them and can't assume any other TU will emit a copy).
Fortunately, we don't need to, since no correct program can ever invoke them,
so instead emit symbols that just trap.
We should stop emitting references to these symbols, but still need to emit
definitions for compatibility.
llvm-svn: 296275
2017-02-26 07:53:05 +08:00
|
|
|
|
|
|
|
// Ensure that we
|
|
|
|
// a) emit the ABI-required but useless complete object and deleting destructor
|
2018-10-15 23:43:00 +08:00
|
|
|
// symbols for an abstract class, and
|
C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules for special member functions.
Essentially, as a base class constructor does not construct virtual bases, such
a constructor for an abstract class does not need the corresponding base class
construction to be valid, and likewise for destructors.
This creates an awkward situation: clang will sometimes generate references to
the complete object and deleting destructors for an abstract class (it puts
them in the construction vtable for a derived class). But we can't generate a
"correct" version of these because we can't generate references to base class
constructors any more (if they're template specializations, say, we might not
have instantiated them and can't assume any other TU will emit a copy).
Fortunately, we don't need to, since no correct program can ever invoke them,
so instead emit symbols that just trap.
We should stop emitting references to these symbols, but still need to emit
definitions for compatibility.
llvm-svn: 296275
2017-02-26 07:53:05 +08:00
|
|
|
// b) do *not* emit references to virtual base destructors for an abstract class
|
|
|
|
//
|
|
|
|
// Our approach to this is to give these functions a body that simply traps.
|
|
|
|
//
|
|
|
|
// FIXME: We should ideally not create these symbols at all, but Clang can
|
|
|
|
// actually generate references to them in other TUs in some cases, so we can't
|
|
|
|
// stop emitting them without breaking ABI. See:
|
|
|
|
//
|
|
|
|
// https://github.com/itanium-cxx-abi/cxx-abi/issues/10
|
|
|
|
namespace abstract {
|
|
|
|
// Note, the destructor of this class is not instantiated here.
|
|
|
|
template<typename T> struct should_not_appear_in_output {
|
|
|
|
~should_not_appear_in_output() { int arr[-(int)sizeof(T)]; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct X { ~X(); };
|
|
|
|
|
|
|
|
struct A : virtual should_not_appear_in_output<int>, X {
|
|
|
|
virtual ~A() = 0;
|
|
|
|
};
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN8abstract1AD2Ev(
|
C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules for special member functions.
Essentially, as a base class constructor does not construct virtual bases, such
a constructor for an abstract class does not need the corresponding base class
construction to be valid, and likewise for destructors.
This creates an awkward situation: clang will sometimes generate references to
the complete object and deleting destructors for an abstract class (it puts
them in the construction vtable for a derived class). But we can't generate a
"correct" version of these because we can't generate references to base class
constructors any more (if they're template specializations, say, we might not
have instantiated them and can't assume any other TU will emit a copy).
Fortunately, we don't need to, since no correct program can ever invoke them,
so instead emit symbols that just trap.
We should stop emitting references to these symbols, but still need to emit
definitions for compatibility.
llvm-svn: 296275
2017-02-26 07:53:05 +08:00
|
|
|
// CHECK: call {{.*}}@_ZN8abstract1XD2Ev(
|
|
|
|
// CHECK: ret
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN8abstract1AD1Ev(
|
C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules for special member functions.
Essentially, as a base class constructor does not construct virtual bases, such
a constructor for an abstract class does not need the corresponding base class
construction to be valid, and likewise for destructors.
This creates an awkward situation: clang will sometimes generate references to
the complete object and deleting destructors for an abstract class (it puts
them in the construction vtable for a derived class). But we can't generate a
"correct" version of these because we can't generate references to base class
constructors any more (if they're template specializations, say, we might not
have instantiated them and can't assume any other TU will emit a copy).
Fortunately, we don't need to, since no correct program can ever invoke them,
so instead emit symbols that just trap.
We should stop emitting references to these symbols, but still need to emit
definitions for compatibility.
llvm-svn: 296275
2017-02-26 07:53:05 +08:00
|
|
|
// CHECK: call {{.*}}@llvm.trap(
|
|
|
|
// CHECK: unreachable
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN8abstract1AD0Ev(
|
C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules for special member functions.
Essentially, as a base class constructor does not construct virtual bases, such
a constructor for an abstract class does not need the corresponding base class
construction to be valid, and likewise for destructors.
This creates an awkward situation: clang will sometimes generate references to
the complete object and deleting destructors for an abstract class (it puts
them in the construction vtable for a derived class). But we can't generate a
"correct" version of these because we can't generate references to base class
constructors any more (if they're template specializations, say, we might not
have instantiated them and can't assume any other TU will emit a copy).
Fortunately, we don't need to, since no correct program can ever invoke them,
so instead emit symbols that just trap.
We should stop emitting references to these symbols, but still need to emit
definitions for compatibility.
llvm-svn: 296275
2017-02-26 07:53:05 +08:00
|
|
|
// CHECK: call {{.*}}@llvm.trap(
|
|
|
|
// CHECK: unreachable
|
|
|
|
A::~A() {}
|
|
|
|
|
|
|
|
struct B : virtual should_not_appear_in_output<int>, X {
|
|
|
|
virtual void f() = 0;
|
|
|
|
~B();
|
|
|
|
};
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN8abstract1BD2Ev(
|
C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules for special member functions.
Essentially, as a base class constructor does not construct virtual bases, such
a constructor for an abstract class does not need the corresponding base class
construction to be valid, and likewise for destructors.
This creates an awkward situation: clang will sometimes generate references to
the complete object and deleting destructors for an abstract class (it puts
them in the construction vtable for a derived class). But we can't generate a
"correct" version of these because we can't generate references to base class
constructors any more (if they're template specializations, say, we might not
have instantiated them and can't assume any other TU will emit a copy).
Fortunately, we don't need to, since no correct program can ever invoke them,
so instead emit symbols that just trap.
We should stop emitting references to these symbols, but still need to emit
definitions for compatibility.
llvm-svn: 296275
2017-02-26 07:53:05 +08:00
|
|
|
// CHECK: call {{.*}}@_ZN8abstract1XD2Ev(
|
|
|
|
// CHECK: ret
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN8abstract1BD1Ev(
|
C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules for special member functions.
Essentially, as a base class constructor does not construct virtual bases, such
a constructor for an abstract class does not need the corresponding base class
construction to be valid, and likewise for destructors.
This creates an awkward situation: clang will sometimes generate references to
the complete object and deleting destructors for an abstract class (it puts
them in the construction vtable for a derived class). But we can't generate a
"correct" version of these because we can't generate references to base class
constructors any more (if they're template specializations, say, we might not
have instantiated them and can't assume any other TU will emit a copy).
Fortunately, we don't need to, since no correct program can ever invoke them,
so instead emit symbols that just trap.
We should stop emitting references to these symbols, but still need to emit
definitions for compatibility.
llvm-svn: 296275
2017-02-26 07:53:05 +08:00
|
|
|
// CHECK: call {{.*}}@llvm.trap(
|
|
|
|
// CHECK: unreachable
|
|
|
|
|
|
|
|
// CHECK-NOT: @_ZN8abstract1BD0Ev(
|
|
|
|
B::~B() {}
|
|
|
|
}
|