1 // RUN: %clang_cc1 %s -triple x86_64-linux -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-optzns | FileCheck %s
2 // RUN: %clang_cc1 %s -triple x86_64-linux -emit-llvm -o - -mconstructor-aliases | FileCheck --check-prefix=NOOPT %s
4 // RUN: %clang_cc1 -cc1 -triple x86_64--netbsd -emit-llvm \
5 // RUN: -mconstructor-aliases -O2 %s -o - | FileCheck --check-prefix=CHECK-RAUW %s
8 // test that we don't produce an alias when the destructor is weak_odr. The
9 // reason to avoid it that another TU might have no explicit template
10 // instantiation definition or declaration, causing it to to output only
11 // one of the destructors as linkonce_odr, producing a different comdat.
13 // CHECK-DAG: define weak_odr void @_ZN5test16foobarIvEC2Ev
14 // CHECK-DAG: define weak_odr void @_ZN5test16foobarIvEC1Ev
16 template <typename T> struct foobar {
20 template struct foobar<void>;
24 // test that when the destrucor is linkonce_odr we just replace every use of
27 // CHECK-DAG: define linkonce_odr void @_ZN5test26foobarIvEC2Ev(
28 // CHECK-DAG: call void @_ZN5test26foobarIvEC2Ev
30 template <typename T> struct foobar {
37 // test that instead of an internal alias we just use the other destructor
40 // CHECK-DAG: define internal void @_ZN5test312_GLOBAL__N_11AD2Ev(
41 // CHECK-DAG: call i32 @__cxa_atexit{{.*}}_ZN5test312_GLOBAL__N_11AD2Ev
47 struct B : public A {};
54 // Test that we don't produce aliases from B to A. We cannot because we cannot
55 // guarantee that they will be present in every TU. Instead, we just call
56 // A's destructor directly.
58 // CHECK-DAG: define linkonce_odr void @_ZN5test41AD2Ev(
59 // CHECK-DAG: call i32 @__cxa_atexit{{.*}}_ZN5test41AD2Ev
61 // test that we don't do this optimization at -O0 so that the debugger can
62 // see both destructors.
63 // NOOPT-DAG: call i32 @__cxa_atexit{{.*}}@_ZN5test41BD2Ev
64 // NOOOPT-DAG: define linkonce_odr void @_ZN5test41BD2Ev
75 // similar to test4, but with an internal B.
77 // CHECK-DAG: define linkonce_odr void @_ZN5test51AD2Ev(
78 // CHECK-DAG: call i32 @__cxa_atexit{{.*}}_ZN5test51AD2Ev
91 // Test that we use ~A directly, even when ~A is not defined. The symbol for
92 // ~B would have been internal and still contain a reference to ~A.
102 // CHECK-DAG: call i32 @__cxa_atexit({{.*}}@_ZN5test61AD2Ev
106 // Test that we don't produce an alias from ~B to ~A<int> (or crash figuring
107 // out if we should).
109 // CHECK-DAG: define void @_ZN5test71BD2Ev
110 template <typename> struct A {
116 template class A<int>;
121 // Test that we replace ~zed with ~bar which is an alias to ~foo.
122 // CHECK-DAG: call i32 @__cxa_atexit({{.*}}@_ZN5test83barD2Ev
123 // CHECK-DAG: @_ZN5test83barD2Ev = alias {{.*}} @_ZN5test83fooD2Ev
128 struct bar : public foo {
132 struct zed : public bar {};
136 // CHECK-RAUW: @_ZTV1C = linkonce_odr unnamed_addr constant [4 x i8*] [{{[^@]*}}@_ZTI1C {{[^@]*}}@_ZN1CD2Ev {{[^@]*}}@_ZN1CD0Ev {{[^@]*}}]
137 // r194296 replaced C::~C with B::~B without emitting the later.
151 __attribute__((always_inline)) ~B() {
155 extern template class B<char>;