diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-01-05 19:06:31 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-01-05 19:06:31 +0000 |
commit | a318efd1f21a21358f45a201f7b6cb2b8b118ec0 (patch) | |
tree | a4ce378e010ad14d8fd2ec042050df78be33568d /clang/test | |
parent | 79ed590c85749e088e80506c831a3da292122c9c (diff) | |
download | bcm5719-llvm-a318efd1f21a21358f45a201f7b6cb2b8b118ec0.tar.gz bcm5719-llvm-a318efd1f21a21358f45a201f7b6cb2b8b118ec0.zip |
Improve key-function computation for templates. In particular:
- All classes can have a key function; templates don't change that.
non-template classes when computing the key function.
- We always mark all of the virtual member functions of class
template instantiations.
- The vtable for an instantiation of a class template has weak
linkage.
We could probably use available_externally linkage for vtables of
classes instantiated by explicit instantiation declarations (extern
templates), but GCC doesn't do this and I'm not 100% that the ABI
permits it.
llvm-svn: 92753
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CodeGenCXX/vtable-key-function.cpp | 18 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/vtable-linkage.cpp | 46 |
2 files changed, 64 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/vtable-key-function.cpp b/clang/test/CodeGenCXX/vtable-key-function.cpp index 90e8ea66f76..97a546f8c93 100644 --- a/clang/test/CodeGenCXX/vtable-key-function.cpp +++ b/clang/test/CodeGenCXX/vtable-key-function.cpp @@ -13,3 +13,21 @@ struct A { A::A() { } A::A(int) { } } + +// Make sure that we don't assert when building the vtable for a class +// template specialization or explicit instantiation with a key +// function. +template<typename T> +struct Base { + virtual ~Base(); +}; + +template<typename T> +struct Derived : public Base<T> { }; + +template<> +struct Derived<char> : public Base<char> { + virtual void anchor(); +}; + +void Derived<char>::anchor() { } diff --git a/clang/test/CodeGenCXX/vtable-linkage.cpp b/clang/test/CodeGenCXX/vtable-linkage.cpp index 6d3cf240096..23d78aadf7e 100644 --- a/clang/test/CodeGenCXX/vtable-linkage.cpp +++ b/clang/test/CodeGenCXX/vtable-linkage.cpp @@ -30,6 +30,30 @@ void D::f() { } static struct : D { } e; +template<typename T> +struct E { + virtual ~E(); +}; + +template<typename T> E<T>::~E() { } + +template<> +struct E<char> { + virtual void anchor(); +}; + +void E<char>::anchor() { } + +template struct E<short>; +extern template struct E<int>; + +void use_E() { + E<int> ei; + (void)ei; + E<long> el; + (void)el; +} + // B has a key function that is not defined in this translation unit so its vtable // has external linkage. // CHECK: @_ZTV1B = external constant @@ -45,14 +69,36 @@ static struct : D { } e; // CHECK: @_ZTI1D = constant // CHECK: @_ZTV1D = constant +// E<char> is an explicit specialization with a key function defined +// in this translation unit, so its vtable should have external +// linkage. +// CHECK: @_ZTV1EIcE = constant + +// E<short> is an explicit template instantiation with a key function +// defined in this translation unit, so its vtable should have +// weak_odr linkage. +// CHECK: @_ZTV1EIsE = weak_odr constant + +// E<long> is an implicit template instantiation with a key function +// defined in this translation unit, so its vtable should have +// weak_odr linkage. +// CHECK: @_ZTV1EIlE = weak_odr constant + // The anonymous struct for e has no linkage, so the vtable should have // internal linkage. // CHECK: @"_ZTS3$_0" = internal constant // CHECK: @"_ZTI3$_0" = internal constant // CHECK: @"_ZTV3$_0" = internal constant +// E<int> is an explicit template instantiation declaration. It has a +// key function that is not instantiation, so we should only reference +// its vtable, not define it. +// CHECK: @_ZTV1EIiE = external constant + // The A vtable should have internal linkage since it is inside an anonymous // namespace. // CHECK: @_ZTSN12_GLOBAL__N_11AE = internal constant // CHECK: @_ZTIN12_GLOBAL__N_11AE = internal constant // CHECK: @_ZTVN12_GLOBAL__N_11AE = internal constant + + |