Perform two more constructor/destructor code-size optimizations:
1) emit base destructors as aliases to their unique base class destructors
under some careful conditions. This is enabled for the same targets that can
support complete-to-base aliases, i.e. not darwin.
2) Emit non-variadic complete constructors for classes with no virtual bases
as calls to the base constructor. This is enabled on all targets and in
theory can trigger in situations that the alias optimization can't (mostly
involving virtual bases, mostly not yet supported).
These are bundled together because I didn't think it worthwhile to split them,
not because they really need to be.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96842 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGenCXX/destructors.cpp b/test/CodeGenCXX/destructors.cpp
index f06661a..accd1b3 100644
--- a/test/CodeGenCXX/destructors.cpp
+++ b/test/CodeGenCXX/destructors.cpp
@@ -1,4 +1,11 @@
// RUN: %clang_cc1 %s -emit-llvm -o - -mconstructor-aliases | FileCheck %s
+
+// CHECK: @_ZN5test01AD1Ev = alias {{.*}} @_ZN5test01AD2Ev
+// CHECK: @_ZN5test11MD2Ev = alias {{.*}} @_ZN5test11AD2Ev
+// CHECK: @_ZN5test11ND2Ev = alias {{.*}} @_ZN5test11AD2Ev
+// CHECK: @_ZN5test11OD2Ev = alias {{.*}} @_ZN5test11AD2Ev
+// CHECK: @_ZN5test11SD2Ev = alias bitcast {{.*}} @_ZN5test11AD2Ev
+
struct A {
int a;
@@ -60,7 +67,7 @@
// The function-try-block won't suppress -mconstructor-aliases here.
A::~A() try { } catch (int i) {}
-// CHECK: @_ZN5test01AD1Ev = alias {{.*}} @_ZN5test01AD2Ev
+// complete destructor alias tested above
// CHECK: define void @_ZN5test01AD2Ev
// CHECK: invoke void @_ZN5test06MemberD1Ev
@@ -89,3 +96,40 @@
// CHECK: invoke void @_ZN5test04BaseD2Ev
// CHECK: unwind label [[BASE_UNWIND:%[a-zA-Z0-9.]+]]
}
+
+// Test base-class aliasing.
+namespace test1 {
+ struct A { ~A(); char ***m; }; // non-trivial destructor
+ struct B { ~B(); }; // non-trivial destructor
+ struct Empty { }; // trivial destructor, empty
+ struct NonEmpty { int x; }; // trivial destructor, non-empty
+
+ struct M : A { ~M(); };
+ M::~M() {} // alias tested above
+
+ struct N : A, Empty { ~N(); };
+ N::~N() {} // alias tested above
+
+ struct O : Empty, A { ~O(); };
+ O::~O() {} // alias tested above
+
+ struct P : NonEmpty, A { ~P(); };
+ P::~P() {} // CHECK: define void @_ZN5test11PD2Ev
+
+ struct Q : A, B { ~Q(); };
+ Q::~Q() {} // CHECK: define void @_ZN5test11QD2Ev
+
+ struct R : A { ~R(); };
+ R::~R() { A a; } // CHECK: define void @_ZN5test11RD2Ev
+
+ struct S : A { ~S(); int x; };
+ S::~S() {} // alias tested above
+
+ struct T : A { ~T(); B x; };
+ T::~T() {} // CHECK: define void @_ZN5test11TD2Ev
+
+ // The VTT parameter prevents this. We could still make this work
+ // for calling conventions that are safe against extra parameters.
+ struct U : A, virtual B { ~U(); };
+ U::~U() {} // CHECK: define void @_ZN5test11UD2Ev
+}