summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp18
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h3
-rw-r--r--clang/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp4
-rw-r--r--clang/test/CodeGenCXX/explicit-instantiation.cpp4
-rw-r--r--clang/test/CodeGenCXX/mangle-exprs.cpp10
-rw-r--r--clang/test/CodeGenCXX/mangle-template.cpp4
-rw-r--r--clang/test/CodeGenCXX/mangle.cpp16
-rw-r--r--clang/test/CodeGenCXX/member-templates.cpp4
-rw-r--r--clang/test/CodeGenCXX/template-linkage.cpp10
-rw-r--r--clang/test/CodeGenCXX/temporaries.cpp2
10 files changed, 36 insertions, 39 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 7314dae8131..c67948d27f0 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -285,7 +285,8 @@ GetLinkageForFunction(ASTContext &Context, const FunctionDecl *FD,
break;
case TSK_ExplicitInstantiationDefinition:
- return CodeGenModule::GVA_ExplicitTemplateInstantiation;
+ // FIXME: explicit instantiation definitions should use weak linkage
+ return CodeGenModule::GVA_StrongExternal;
case TSK_ExplicitInstantiationDeclaration:
case TSK_ImplicitInstantiation:
@@ -334,8 +335,7 @@ CodeGenModule::getFunctionLinkage(const FunctionDecl *D) {
// In C99 mode, 'inline' functions are guaranteed to have a strong
// definition somewhere else, so we can use available_externally linkage.
return llvm::Function::AvailableExternallyLinkage;
- } else if (Linkage == GVA_CXXInline || Linkage == GVA_TemplateInstantiation ||
- Linkage == GVA_ExplicitTemplateInstantiation) {
+ } else if (Linkage == GVA_CXXInline || Linkage == GVA_TemplateInstantiation) {
// In C++, the compiler has to emit a definition in every translation unit
// that references the function. We should use linkonce_odr because
// a) if all references in this translation unit are optimized away, we
@@ -589,7 +589,6 @@ bool CodeGenModule::MayDeferGeneration(const ValueDecl *Global) {
// static, static inline, always_inline, and extern inline functions can
// always be deferred. Normal inline functions can be deferred in C99/C++.
- // Implicit template instantiations can also be deferred in C++.
if (Linkage == GVA_Internal || Linkage == GVA_C99Inline ||
Linkage == GVA_CXXInline || Linkage == GVA_TemplateInstantiation)
return true;
@@ -1044,15 +1043,15 @@ GetLinkageForVariable(ASTContext &Context, const VarDecl *VD) {
switch (TSK) {
case TSK_Undeclared:
case TSK_ExplicitSpecialization:
- return CodeGenModule::GVA_StrongExternal;
+ // FIXME: ExplicitInstantiationDefinition should be weak!
+ case TSK_ExplicitInstantiationDefinition:
+ return CodeGenModule::GVA_StrongExternal;
+
case TSK_ExplicitInstantiationDeclaration:
llvm_unreachable("Variable should not be instantiated");
// Fall through to treat this like any other instantiation.
- case TSK_ExplicitInstantiationDefinition:
- return CodeGenModule::GVA_ExplicitTemplateInstantiation;
-
case TSK_ImplicitInstantiation:
return CodeGenModule::GVA_TemplateInstantiation;
}
@@ -1172,8 +1171,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
GV->setLinkage(llvm::GlobalVariable::WeakODRLinkage);
else
GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage);
- } else if (Linkage == GVA_TemplateInstantiation ||
- Linkage == GVA_ExplicitTemplateInstantiation)
+ } else if (Linkage == GVA_TemplateInstantiation)
GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage);
else if (!getLangOptions().CPlusPlus && !CodeGenOpts.NoCommon &&
!D->hasExternalStorage() && !D->getInit() &&
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index 9077adedd0b..40dc5638898 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -437,8 +437,7 @@ public:
GVA_C99Inline,
GVA_CXXInline,
GVA_StrongExternal,
- GVA_TemplateInstantiation,
- GVA_ExplicitTemplateInstantiation
+ GVA_TemplateInstantiation
};
llvm::GlobalVariable::LinkageTypes
diff --git a/clang/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp b/clang/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp
index d8f7b52145d..70eb6964186 100644
--- a/clang/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp
+++ b/clang/test/CXX/temp/temp.spec/temp.explicit/p1-emit.cpp
@@ -12,10 +12,10 @@ T X<T>::member1;
template<typename T>
T X<T>::member2 = 17;
-// CHECK: @_ZN1XIiE7member1E = weak global i32 0
+// CHECK: @_ZN1XIiE7member1E = global i32 0
template int X<int>::member1;
-// CHECK: @_ZN1XIiE7member2E = weak global i32 17
+// CHECK: @_ZN1XIiE7member2E = global i32 17
template int X<int>::member2;
// For implicit instantiation of
diff --git a/clang/test/CodeGenCXX/explicit-instantiation.cpp b/clang/test/CodeGenCXX/explicit-instantiation.cpp
index 0b1712e062e..ab9174e8f40 100644
--- a/clang/test/CodeGenCXX/explicit-instantiation.cpp
+++ b/clang/test/CodeGenCXX/explicit-instantiation.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -emit-llvm -triple i686-pc-linux-gnu -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple i686-pc-linux-gnu -o %t %s
+// RUN: grep "define i32 @_ZNK4plusIillEclERKiRKl" %t | count 1
template<typename T, typename U, typename Result>
struct plus {
@@ -10,5 +11,4 @@ Result plus<T, U, Result>::operator()(const T& t, const U& u) const {
return t + u;
}
-// CHECK: define linkonce_odr i32 @_ZNK4plusIillEclERKiRKl
template struct plus<int, long, long>;
diff --git a/clang/test/CodeGenCXX/mangle-exprs.cpp b/clang/test/CodeGenCXX/mangle-exprs.cpp
index fe36c0b4a7a..cdad39852c9 100644
--- a/clang/test/CodeGenCXX/mangle-exprs.cpp
+++ b/clang/test/CodeGenCXX/mangle-exprs.cpp
@@ -30,15 +30,15 @@ namespace Casts {
template <int N> T<N> f() { return T<N>(); }
- // CHECK: define linkonce_odr void @_ZN5Casts8implicitILj4EEEvPN9enable_ifIXleT_Li4EEvE4typeE
+ // CHECK: define void @_ZN5Casts8implicitILj4EEEvPN9enable_ifIXleT_Li4EEvE4typeE
template void implicit<4>(void*);
- // CHECK: define linkonce_odr void @_ZN5Casts6cstyleILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
+ // CHECK: define void @_ZN5Casts6cstyleILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
template void cstyle<4>(void*);
- // CHECK: define linkonce_odr void @_ZN5Casts10functionalILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
+ // CHECK: define void @_ZN5Casts10functionalILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
template void functional<4>(void*);
- // CHECK: define linkonce_odr void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
+ // CHECK: define void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
template void static_<4>(void*);
- // CHECK: define linkonce_odr i64 @_ZN5Casts1fILi6EEENS_1TIXT_EEEv
+ // CHECK: define i64 @_ZN5Casts1fILi6EEENS_1TIXT_EEEv
template T<6> f<6>();
}
diff --git a/clang/test/CodeGenCXX/mangle-template.cpp b/clang/test/CodeGenCXX/mangle-template.cpp
index 384ce45e1cb..57f30a762ed 100644
--- a/clang/test/CodeGenCXX/mangle-template.cpp
+++ b/clang/test/CodeGenCXX/mangle-template.cpp
@@ -82,7 +82,7 @@ namespace test7 {
X(U*, typename int_c<(meta<T>::value + meta<U>::value)>::type *) { }
};
- // CHECK: define linkonce_odr void @_ZN5test71XIiEC1IdEEPT_PNS_5int_cIXplL_ZNS_4metaIiE5valueEEsrNS6_IS3_EE5valueEE4typeE
+ // CHECK: define void @_ZN5test71XIiEC1IdEEPT_PNS_5int_cIXplL_ZNS_4metaIiE5valueEEsrNS6_IS3_EE5valueEE4typeE
template X<int>::X(double*, float*);
}
@@ -101,6 +101,6 @@ namespace test8 {
template<typename T>
void f(int_c<meta<T>::type::value>) { }
- // CHECK: define linkonce_odr void @_ZN5test81fIiEEvNS_5int_cIXsrNS_4metaIT_E4typeE5valueEEE
+ // CHECK: define void @_ZN5test81fIiEEvNS_5int_cIXsrNS_4metaIT_E4typeE5valueEEE
template void f<int>(int_c<sizeof(int)>);
}
diff --git a/clang/test/CodeGenCXX/mangle.cpp b/clang/test/CodeGenCXX/mangle.cpp
index e8ab2c77a8b..3f966902a21 100644
--- a/clang/test/CodeGenCXX/mangle.cpp
+++ b/clang/test/CodeGenCXX/mangle.cpp
@@ -250,26 +250,26 @@ void f() { __fill_a<int>(); }
namespace Expressions {
// Unary operators.
-// CHECK: define linkonce_odr void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i
+// CHECK: define void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i
template <int i> void f1(int (*)[(-i) + 2]) { };
template void f1<1>(int (*)[1]);
-// CHECK: define linkonce_odr void @_ZN11Expressions2f2ILi1EEEvPApsT__i
+// CHECK: define void @_ZN11Expressions2f2ILi1EEEvPApsT__i
template <int i> void f2(int (*)[+i]) { };
template void f2<1>(int (*)[1]);
// Binary operators.
-// CHECK: define linkonce_odr void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i
+// CHECK: define void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i
template <int i> void f3(int (*)[i+i]) { };
template void f3<1>(int (*)[2]);
-// CHECK: define linkonce_odr void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i
+// CHECK: define void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i
template <int i> void f4(int (*)[2 + i+i]) { };
template void f4<1>(int (*)[4]);
// The ternary operator.
-// CHECK: define linkonce_odr void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i
+// CHECK: define void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i
template <bool b> void f4(int (*)[b ? 1 : 2]) { };
template void f4<true>(int (*)[1]);
}
@@ -305,7 +305,7 @@ template<typename T, typename = Policy<P, true> > class Alloc
T *allocate(int, const void*) { return 0; }
};
-// CHECK: define linkonce_odr i8* @_ZN6PR58615AllocIcNS_6PolicyINS_1PELb1EEEE8allocateEiPKv
+// CHECK: define i8* @_ZN6PR58615AllocIcNS_6PolicyINS_1PELb1EEEE8allocateEiPKv
template class Alloc<char>;
}
@@ -369,7 +369,7 @@ namespace test0 {
namespace test1 {
template<typename T> struct X { };
template<template<class> class Y, typename T> void f(Y<T>) { }
- // CHECK: define linkonce_odr void @_ZN5test11fINS_1XEiEEvT_IT0_E
+ // CHECK: define void @_ZN5test11fINS_1XEiEEvT_IT0_E
template void f(X<int>);
}
@@ -447,7 +447,7 @@ namespace test7 {
void g(zed<&foo::bar>*)
{}
}
-// CHECK: define linkonce_odr void @_ZN5test81AILZNS_1B5valueEEE3incEv
+// CHECK: define void @_ZN5test81AILZNS_1B5valueEEE3incEv
namespace test8 {
template <int &counter> class A { void inc() { counter++; } };
class B { static int value; };
diff --git a/clang/test/CodeGenCXX/member-templates.cpp b/clang/test/CodeGenCXX/member-templates.cpp
index f82224780e6..355ba20e171 100644
--- a/clang/test/CodeGenCXX/member-templates.cpp
+++ b/clang/test/CodeGenCXX/member-templates.cpp
@@ -15,8 +15,8 @@ struct B {
template<typename T> B::B(T) {}
-// CHECK: define linkonce_odr void @_ZN1BC1IiEET_(%struct.B* %this, i32)
-// CHECK: define linkonce_odr void @_ZN1BC2IiEET_(%struct.B* %this, i32)
+// CHECK: define void @_ZN1BC1IiEET_(%struct.B* %this, i32)
+// CHECK: define void @_ZN1BC2IiEET_(%struct.B* %this, i32)
template B::B(int);
template<typename T>
diff --git a/clang/test/CodeGenCXX/template-linkage.cpp b/clang/test/CodeGenCXX/template-linkage.cpp
index 03451bed158..5d573d6e829 100644
--- a/clang/test/CodeGenCXX/template-linkage.cpp
+++ b/clang/test/CodeGenCXX/template-linkage.cpp
@@ -6,19 +6,19 @@ template<typename T> struct A {
// Explicit instantiations have external linkage.
-// CHECK: define linkonce_odr void @_ZN1AIiE1gEv(
+// CHECK: define void @_ZN1AIiE1gEv(
template void A<int>::g();
-// CHECK: define linkonce_odr void @_ZN1AIfE1fEf(
-// CHECK: define linkonce_odr void @_ZN1AIfE1gEv(
+// CHECK: define void @_ZN1AIfE1fEf(
+// CHECK: define void @_ZN1AIfE1gEv(
// FIXME: This should also emit the vtable.
template struct A<float>;
-// CHECK: define linkonce_odr void @_Z1fIiEvT_
+// CHECK: define void @_Z1fIiEvT_
template <typename T> void f(T) { }
template void f<int>(int);
-// CHECK: define linkonce_odr void @_Z1gIiEvT_
+// CHECK: define void @_Z1gIiEvT_
template <typename T> inline void g(T) { }
template void g<int>(int);
diff --git a/clang/test/CodeGenCXX/temporaries.cpp b/clang/test/CodeGenCXX/temporaries.cpp
index 7d2d201a46d..3b624afd0ad 100644
--- a/clang/test/CodeGenCXX/temporaries.cpp
+++ b/clang/test/CodeGenCXX/temporaries.cpp
@@ -256,7 +256,7 @@ namespace PR6199 {
struct B { operator A(); };
- // CHECK: define linkonce_odr void @_ZN6PR61992f2IiEENS_1AET_
+ // CHECK: define void @_ZN6PR61992f2IiEENS_1AET_
template<typename T> A f2(T) {
B b;
// CHECK: call void @_ZN6PR61991BcvNS_1AEEv
OpenPOWER on IntegriCloud