summaryrefslogtreecommitdiffstats
path: root/test/CodeGenCXX/explicit-instantiation.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2015-01-10 01:19:48 +0000
committerHans Wennborg <hans@hanshq.net>2015-01-10 01:19:48 +0000
commitafe88a16c63ece9ce3715c3acbbabd83a488921f (patch)
treec8274af5e61df2facf88ee8a955235d4f9b65fc8 /test/CodeGenCXX/explicit-instantiation.cpp
parent9017269b38fe5d47f2e27633e94f682a045e65b3 (diff)
Don't emit implicit template instantiations eagerly (PR21718)
Their linkage can change if they are later explicitly instantiated. We would previously emit such functions eagerly (as opposed to lazily on first use) if they have a 'dllexport' or 'used' attribute, and fail an assert when hitting the explicit instantiation. This is achieved by replacing the old CodeGenModule::MayDeferGeneration() method with two new ones: MustBeEmitted() and MayBeEmittedEagerly(). Differential Revision: http://reviews.llvm.org/D6674 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225570 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/explicit-instantiation.cpp')
-rw-r--r--test/CodeGenCXX/explicit-instantiation.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/CodeGenCXX/explicit-instantiation.cpp b/test/CodeGenCXX/explicit-instantiation.cpp
index 5bd06784cf..6076444c25 100644
--- a/test/CodeGenCXX/explicit-instantiation.cpp
+++ b/test/CodeGenCXX/explicit-instantiation.cpp
@@ -90,6 +90,19 @@ namespace LateInstantiation {
// CHECK-OPT: define available_externally i32 @_ZN17LateInstantiation1fIiEEiv(
}
+namespace PR21718 {
+// The linkage of a used constexpr member function can change from linkonce_odr
+// to weak_odr after explicit instantiation without errors about defining the
+// same function twice.
+template <typename T>
+struct S {
+// CHECK-LABEL: define weak_odr i32 @_ZN7PR217181SIiE1fEv
+ __attribute__((used)) constexpr int f() { return 0; }
+};
+int g() { return S<int>().f(); }
+template struct S<int>;
+}
+
// Check that we emit definitions from explicit instantiations even when they
// occur prior to the definition itself.
template <typename T> struct S {