blob: 23d78aadf7eb77b76464f9f44012ddf30296459c [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
Anders Carlsson7ca46432009-12-05 17:04:47 +00002
3namespace {
Anders Carlsson7ca46432009-12-05 17:04:47 +00004 struct A {
5 virtual void f() { }
6 };
Anders Carlsson7ca46432009-12-05 17:04:47 +00007}
8
Anders Carlsson152d4dc2009-12-05 22:19:10 +00009void f() { A b; }
10
11struct B {
12 B();
13 virtual void f();
14};
15
16B::B() { }
17
Anders Carlsson891c8b72009-12-05 22:24:38 +000018struct C {
19 C();
20 virtual void f() { }
21};
22
23C::C() { }
24
Anders Carlsson5794c972009-12-06 00:53:22 +000025struct D {
26 virtual void f();
27};
28
29void D::f() { }
30
Eli Friedman470fb732009-12-11 20:48:18 +000031static struct : D { } e;
32
Douglas Gregorbd6d6192010-01-05 19:06:31 +000033template<typename T>
34struct E {
35 virtual ~E();
36};
37
38template<typename T> E<T>::~E() { }
39
40template<>
41struct E<char> {
42 virtual void anchor();
43};
44
45void E<char>::anchor() { }
46
47template struct E<short>;
48extern template struct E<int>;
49
50void use_E() {
51 E<int> ei;
52 (void)ei;
53 E<long> el;
54 (void)el;
55}
56
Anders Carlsson152d4dc2009-12-05 22:19:10 +000057// B has a key function that is not defined in this translation unit so its vtable
58// has external linkage.
59// CHECK: @_ZTV1B = external constant
60
Anders Carlsson891c8b72009-12-05 22:24:38 +000061// C has no key function, so its vtable should have weak_odr linkage.
Anders Carlsson31b7f522009-12-11 02:46:30 +000062// CHECK: @_ZTS1C = weak_odr constant
63// CHECK: @_ZTI1C = weak_odr constant
Anders Carlsson891c8b72009-12-05 22:24:38 +000064// CHECK: @_ZTV1C = weak_odr constant
65
Anders Carlsson5794c972009-12-06 00:53:22 +000066// D has a key function that is defined in this translation unit so its vtable is
67// defined in the translation unit.
Anders Carlsson31b7f522009-12-11 02:46:30 +000068// CHECK: @_ZTS1D = constant
69// CHECK: @_ZTI1D = constant
Anders Carlsson5794c972009-12-06 00:53:22 +000070// CHECK: @_ZTV1D = constant
71
Douglas Gregorbd6d6192010-01-05 19:06:31 +000072// E<char> is an explicit specialization with a key function defined
73// in this translation unit, so its vtable should have external
74// linkage.
75// CHECK: @_ZTV1EIcE = constant
76
77// E<short> is an explicit template instantiation with a key function
78// defined in this translation unit, so its vtable should have
79// weak_odr linkage.
80// CHECK: @_ZTV1EIsE = weak_odr constant
81
82// E<long> is an implicit template instantiation with a key function
83// defined in this translation unit, so its vtable should have
84// weak_odr linkage.
85// CHECK: @_ZTV1EIlE = weak_odr constant
86
Eli Friedman470fb732009-12-11 20:48:18 +000087// The anonymous struct for e has no linkage, so the vtable should have
88// internal linkage.
89// CHECK: @"_ZTS3$_0" = internal constant
90// CHECK: @"_ZTI3$_0" = internal constant
91// CHECK: @"_ZTV3$_0" = internal constant
92
Douglas Gregorbd6d6192010-01-05 19:06:31 +000093// E<int> is an explicit template instantiation declaration. It has a
94// key function that is not instantiation, so we should only reference
95// its vtable, not define it.
96// CHECK: @_ZTV1EIiE = external constant
97
Anders Carlsson152d4dc2009-12-05 22:19:10 +000098// The A vtable should have internal linkage since it is inside an anonymous
99// namespace.
Anders Carlsson31b7f522009-12-11 02:46:30 +0000100// CHECK: @_ZTSN12_GLOBAL__N_11AE = internal constant
101// CHECK: @_ZTIN12_GLOBAL__N_11AE = internal constant
Anders Carlsson152d4dc2009-12-05 22:19:10 +0000102// CHECK: @_ZTVN12_GLOBAL__N_11AE = internal constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000103
104