diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-06-29 22:39:32 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-06-29 22:39:32 +0000 |
commit | 1fd2dd145d9bcdf0b8d60a88e1795b6ae83656f5 (patch) | |
tree | ab0e5c3ba7f6483cd9ad24dbcdab0cda06dd7671 /lib/CodeGen/Mangle.cpp | |
parent | 7881a0565893f1da6faafbd86377f5b50e4376a5 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74466 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/Mangle.cpp')
-rw-r--r-- | lib/CodeGen/Mangle.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index b5ad5acc01..850183568a 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -170,7 +170,29 @@ void CXXNameMangler::mangleGuardVariable(const VarDecl *D) void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { // <encoding> ::= <function name> <bare-function-type> mangleName(FD); - mangleBareFunctionType(FD->getType()->getAsFunctionType(), false); + + // Whether the mangling of a function type includes the return type depends + // on the context and the nature of the function. The rules for deciding + // whether the return type is included are: + // + // 1. Template functions (names or types) have return types encoded, with + // the exceptions listed below. + // 2. Function types not appearing as part of a function name mangling, + // e.g. parameters, pointer types, etc., have return type encoded, with the + // exceptions listed below. + // 3. Non-template function names do not have return types encoded. + // + // The exceptions mentioned in (1) and (2) above, for which the return + // type is never included, are + // 1. Constructors. + // 2. Destructors. + // 3. Conversion operator functions, e.g. operator int. + bool MangleReturnType = false; + if (FD->getPrimaryTemplate() && + !(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) || + isa<CXXConversionDecl>(FD))) + MangleReturnType = true; + mangleBareFunctionType(FD->getType()->getAsFunctionType(), MangleReturnType); } static bool isStdNamespace(const DeclContext *DC) { @@ -253,6 +275,12 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) { assert(false && "Can't mangle a using directive name!"); break; } + + if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) { + if (const TemplateArgumentList *TemplateArgs + = Function->getTemplateSpecializationArgs()) + mangleTemplateArgumentList(*TemplateArgs); + } } void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) { |