From: Anders Carlsson Date: Sun, 27 Sep 2009 00:38:53 +0000 (+0000) Subject: Better template parameter type mangling. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ccdf8d62cba2ad730001f133b6cc4836c42da83;p=clang Better template parameter type mangling. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82883 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index 9ee9a3da88..447255c668 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -106,6 +106,8 @@ namespace { unsigned NumTemplateArgs); void mangleTemplateArgumentList(const TemplateArgumentList &L); void mangleTemplateArgument(const TemplateArgument &A); + + void mangleTemplateParameter(unsigned Index); }; } @@ -845,13 +847,8 @@ void CXXNameMangler::mangleType(const MemberPointerType *T) { } // ::= -// ::= T_ # first template parameter -// ::= T _ void CXXNameMangler::mangleType(const TemplateTypeParmType *T) { - if (T->getIndex() == 0) - Out << "T_"; - else - Out << 'T' << (T->getIndex() - 1) << '_'; + mangleTemplateParameter(T->getIndex()); } // FIXME: ::= @@ -927,6 +924,11 @@ void CXXNameMangler::mangleType(const TypenameType *T) { mangleTemplatePrefix(TD); mangleTemplateArgs(TST->getArgs(), TST->getNumArgs()); + } else if (const TemplateTypeParmType *TTPT = + dyn_cast(QTy)) { + // We use the QualType mangle type variant here because it handles + // substitutions. + mangleType(QualType(TTPT, 0)); } else assert(false && "Unhandled type!"); @@ -959,11 +961,7 @@ void CXXNameMangler::mangleExpression(const Expr *E) { default: assert(false && "Unhandled decl kind!"); case Decl::NonTypeTemplateParm: { const NonTypeTemplateParmDecl *PD = cast(D); - - if (PD->getIndex() == 0) - Out << "T_"; - else - Out << 'T' << (PD->getIndex() - 1) << '_'; + mangleTemplateParameter(PD->getIndex()); break; } @@ -1075,6 +1073,15 @@ void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) { } } +void CXXNameMangler::mangleTemplateParameter(unsigned Index) { + // ::= T_ # first template parameter + // ::= T _ + if (Index == 0) + Out << "T_"; + else + Out << 'T' << (Index - 1) << '_'; +} + // ::= S _ // ::= S_ bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) { diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index fffd4569b4..a55f5b97fe 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -172,3 +172,11 @@ template bool operator==(const A&, const A&) { return true; } // CHECK: @_ZSteqIcEbRK1AIT_ES4_ template bool std::operator==(const ::A&, const ::A&); +struct S { + typedef int U; +}; + +template typename T::U ft6(const T&) { return 0; } + +// CHECK: @_Z3ft6I1SENT_1UERKS1_ +template int ft6(const S&);