[cfe-commits] r82883 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenCXX/mangle.cpp

Anders Carlsson andersca at mac.com
Sat Sep 26 17:38:54 PDT 2009


Author: andersca
Date: Sat Sep 26 19:38:53 2009
New Revision: 82883

URL: http://llvm.org/viewvc/llvm-project?rev=82883&view=rev
Log:
Better template parameter type mangling.

Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp
    cfe/trunk/test/CodeGenCXX/mangle.cpp

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=82883&r1=82882&r2=82883&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sat Sep 26 19:38:53 2009
@@ -106,6 +106,8 @@
                             unsigned NumTemplateArgs);
     void mangleTemplateArgumentList(const TemplateArgumentList &L);
     void mangleTemplateArgument(const TemplateArgument &A);
+    
+    void mangleTemplateParameter(unsigned Index);
   };
 }
 
@@ -845,13 +847,8 @@
 }
 
 // <type>           ::= <template-param>
-// <template-param> ::= T_    # first template parameter
-//                  ::= T <parameter-2 non-negative number> _
 void CXXNameMangler::mangleType(const TemplateTypeParmType *T) {
-  if (T->getIndex() == 0)
-    Out << "T_";
-  else
-    Out << 'T' << (T->getIndex() - 1) << '_';
+  mangleTemplateParameter(T->getIndex());
 }
 
 // FIXME: <type> ::= <template-template-param> <template-args>
@@ -927,6 +924,11 @@
 
     mangleTemplatePrefix(TD);
     mangleTemplateArgs(TST->getArgs(), TST->getNumArgs());
+  } else if (const TemplateTypeParmType *TTPT = 
+              dyn_cast<TemplateTypeParmType>(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 @@
     default: assert(false && "Unhandled decl kind!");
     case Decl::NonTypeTemplateParm: {
       const NonTypeTemplateParmDecl *PD = cast<NonTypeTemplateParmDecl>(D);
-      
-      if (PD->getIndex() == 0)
-        Out << "T_";
-      else
-        Out << 'T' << (PD->getIndex() - 1) << '_';
+      mangleTemplateParameter(PD->getIndex());
       break;
     }
 
@@ -1075,6 +1073,15 @@
   }
 }
 
+void CXXNameMangler::mangleTemplateParameter(unsigned Index) {
+  // <template-param> ::= T_    # first template parameter
+  //                  ::= T <parameter-2 non-negative number> _
+  if (Index == 0)
+    Out << "T_";
+  else
+    Out << 'T' << (Index - 1) << '_';
+}
+
 // <substitution> ::= S <seq-id> _
 //                ::= S_
 bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) {

Modified: cfe/trunk/test/CodeGenCXX/mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle.cpp?rev=82883&r1=82882&r2=82883&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Sat Sep 26 19:38:53 2009
@@ -172,3 +172,11 @@
 // CHECK: @_ZSteqIcEbRK1AIT_ES4_
 template bool std::operator==(const ::A<char>&, const ::A<char>&);
 
+struct S {
+  typedef int U;
+};
+
+template <typename T> typename T::U ft6(const T&) { return 0; }
+
+// CHECK: @_Z3ft6I1SENT_1UERKS1_
+template int ft6<S>(const S&);





More information about the cfe-commits mailing list