summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-06-29 22:39:32 +0000
committerDouglas Gregor <dgregor@apple.com>2009-06-29 22:39:32 +0000
commite8925dbc1d66285c4909e51d76ef61421be55d03 (patch)
treec4c51db7c92b60b686b6b9decc66ed51cfb9b2cd /clang/lib/CodeGen/CodeGenModule.cpp
parent2be8bf44cd0cc8719d01e947beda7640406b4db4 (diff)
downloadbcm5719-llvm-e8925dbc1d66285c4909e51d76ef61421be55d03.tar.gz
bcm5719-llvm-e8925dbc1d66285c4909e51d76ef61421be55d03.zip
Improve code generation for function template specializations:
- Track implicit instantiations vs. the not-yet-supported explicit specializations - Give implicit instantiations of function templates (and member functions of class templates) linkonce_odr linkage. - Improve name mangling for function template specializations, including the template arguments of the instantiation and the return type of the function. Note that our name-mangling is improved, but not correct: we still don't mangle substitutions, although the manglings we produce can be demangled. llvm-svn: 74466
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index acd90e26469..7957a9fe88b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -243,12 +243,20 @@ void CodeGenModule::EmitAnnotations() {
static CodeGenModule::GVALinkage
GetLinkageForFunction(ASTContext &Context, const FunctionDecl *FD,
const LangOptions &Features) {
+ // The kind of external linkage this function will have, if it is not
+ // inline or static.
+ CodeGenModule::GVALinkage External = CodeGenModule::GVA_StrongExternal;
+ if (Context.getLangOptions().CPlusPlus &&
+ (FD->getPrimaryTemplate() || FD->getInstantiatedFromMemberFunction()) &&
+ !FD->isExplicitSpecialization())
+ External = CodeGenModule::GVA_TemplateInstantiation;
+
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
// C++ member functions defined inside the class are always inline.
if (MD->isInline() || !MD->isOutOfLine())
return CodeGenModule::GVA_CXXInline;
- return CodeGenModule::GVA_StrongExternal;
+ return External;
}
// "static" functions get internal linkage.
@@ -256,7 +264,7 @@ GetLinkageForFunction(ASTContext &Context, const FunctionDecl *FD,
return CodeGenModule::GVA_Internal;
if (!FD->isInline())
- return CodeGenModule::GVA_StrongExternal;
+ return External;
// If the inline function explicitly has the GNU inline attribute on it, or if
// this is C89 mode, we use to GNU semantics.
@@ -273,7 +281,7 @@ GetLinkageForFunction(ASTContext &Context, const FunctionDecl *FD,
if (FD->isExternGNUInline(Context))
return CodeGenModule::GVA_C99Inline;
// Normal inline is a strong symbol.
- return CodeGenModule::GVA_StrongExternal;
+ return External;
}
// The definition of inline changes based on the language. Note that we
@@ -306,7 +314,7 @@ void CodeGenModule::SetFunctionDefinitionAttributes(const FunctionDecl *D,
// In C99 mode, 'inline' functions are guaranteed to have a strong
// definition somewhere else, so we can use available_externally linkage.
GV->setLinkage(llvm::Function::AvailableExternallyLinkage);
- } else if (Linkage == GVA_CXXInline) {
+ } 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
OpenPOWER on IntegriCloud