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

Anders Carlsson andersca at mac.com
Thu Sep 17 19:42:01 PDT 2009


Author: andersca
Date: Thu Sep 17 21:42:01 2009
New Revision: 82189

URL: http://llvm.org/viewvc/llvm-project?rev=82189&view=rev
Log:
Handle mangling of TemplateSpecializationType.

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=82189&r1=82188&r2=82189&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Thu Sep 17 21:42:01 2009
@@ -69,12 +69,18 @@
 
     void mangleFunctionEncoding(const FunctionDecl *FD);
     void mangleName(const NamedDecl *ND);
+    void mangleName(const TemplateDecl *TD, 
+                    const TemplateArgument *TemplateArgs,
+                    unsigned NumTemplateArgs);
     void mangleUnqualifiedName(const NamedDecl *ND);
     void mangleUnscopedName(const NamedDecl *ND);
-    void mangleUnscopedTemplateName(const FunctionDecl *ND);
+    void mangleUnscopedTemplateName(const NamedDecl *ND);
     void mangleSourceName(const IdentifierInfo *II);
     void mangleLocalName(const NamedDecl *ND);
     void mangleNestedName(const NamedDecl *ND);
+    void mangleNestedName(const TemplateDecl *TD, 
+                          const TemplateArgument *TemplateArgs,
+                          unsigned NumTemplateArgs);
     void manglePrefix(const DeclContext *DC);
     void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity);
     void mangleCVQualifiers(unsigned Quals);
@@ -93,6 +99,8 @@
     void mangleCXXCtorType(CXXCtorType T);
     void mangleCXXDtorType(CXXDtorType T);
 
+    void mangleTemplateArgs(const TemplateArgument *TemplateArgs,
+                            unsigned NumTemplateArgs);
     void mangleTemplateArgumentList(const TemplateArgumentList &L);
     void mangleTemplateArgument(const TemplateArgument &A);
   };
@@ -268,6 +276,24 @@
     mangleNestedName(ND);
 }
 
+void CXXNameMangler::mangleName(const TemplateDecl *TD, 
+                                const TemplateArgument *TemplateArgs,
+                                unsigned NumTemplateArgs) {
+  const DeclContext *DC = TD->getDeclContext();
+  while (isa<LinkageSpecDecl>(DC)) {
+    assert(cast<LinkageSpecDecl>(DC)->getLanguage() == 
+           LinkageSpecDecl::lang_cxx && "Unexpected linkage decl!");
+    DC = DC->getParent();
+  }
+ 
+  if (DC->isTranslationUnit() || isStdNamespace(DC)) {
+    mangleUnscopedTemplateName(cast<NamedDecl>(TD->getTemplatedDecl()));
+    mangleTemplateArgs(TemplateArgs, NumTemplateArgs);
+  } else {
+    mangleNestedName(TD, TemplateArgs, NumTemplateArgs);
+  }
+}
+
 void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) {
   //  <unscoped-name> ::= <unqualified-name>
   //                  ::= St <unqualified-name>   # ::std::
@@ -277,14 +303,14 @@
   mangleUnqualifiedName(ND);
 }
 
-void CXXNameMangler::mangleUnscopedTemplateName(const FunctionDecl *FD) {
+void CXXNameMangler::mangleUnscopedTemplateName(const NamedDecl *ND) {
   //     <unscoped-template-name> ::= <unscoped-name>
   //                              ::= <substitution>
-  if (mangleSubstitution(FD))
+  if (mangleSubstitution(ND))
     return;
   
-  mangleUnscopedName(FD);
-  addSubstitution(FD);
+  mangleUnscopedName(ND);
+  addSubstitution(ND);
 }
 
 void CXXNameMangler::mangleCalloffset(int64_t nv, int64_t v) {
@@ -419,6 +445,17 @@
   Out << 'E';
 }
 
+void CXXNameMangler::mangleNestedName(const TemplateDecl *TD, 
+                                      const TemplateArgument *TemplateArgs,
+                                      unsigned NumTemplateArgs) {
+  Out << 'N';
+  manglePrefix(TD->getDeclContext());
+  mangleUnqualifiedName(TD->getTemplatedDecl());
+  
+  mangleTemplateArgs(TemplateArgs, NumTemplateArgs);
+  Out << 'E';
+}
+
 void CXXNameMangler::mangleLocalName(const NamedDecl *ND) {
   // <local-name> := Z <function encoding> E <entity name> [<discriminator>]
   //              := Z <function encoding> E s [<discriminator>]
@@ -827,8 +864,10 @@
 }
 
 void CXXNameMangler::mangleType(const TemplateSpecializationType *T) {
-  // TSTs are never canonical unless they're dependent.
-  assert(false && "can't mangle dependent template specializations yet");
+  TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
+  assert(TD && "FIXME: Support dependent template names!");
+  
+  mangleName(TD, T->getArgs(), T->getNumArgs());
 }
 
 void CXXNameMangler::mangleType(const TypenameType *T) {
@@ -896,6 +935,18 @@
   Out << "E";
 }
 
+void CXXNameMangler::mangleTemplateArgs(const TemplateArgument *TemplateArgs,
+                                        unsigned NumTemplateArgs) {
+  // <template-args> ::= I <template-arg>+ E
+  Out << "I";
+  
+  for (unsigned i = 0; i != NumTemplateArgs; ++i) {
+    mangleTemplateArgument(TemplateArgs[i]);
+  }
+  
+  Out << "E";
+}
+
 void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) {
   // <template-arg> ::= <type>              # type or template
   //                ::= X <expression> E    # expression

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

==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Thu Sep 17 21:42:01 2009
@@ -92,15 +92,24 @@
 
 template<typename T> void ft2(T t, void (*)(T), void (*)(T)) { }
 
+template<typename T, typename U = S1<T> > struct S4 { };
+template<typename T> void ft3(S4<T>*) {  }
+
+void g() {
+  ft2<int>(0);
+}
+extern "C++" {
+  // CHECK: @_Z1hv
+ void h() { } 
+}
+
 void g() {
   // CHECK: @_Z3ft1IidEvT0_T_
   ft1<int, double>(1, 0);
   
   // CHECK: @_Z3ft2IcEvT_PFvS0_ES2_
   ft2<char>(1, 0, 0);
-}
-
-extern "C++" {
-  // CHECK: @_Z1hv
- void h() { } 
+  
+  // CHECK: @_Z3ft3IiEvP2S4IT_2S1IS1_EE
+  ft3<int>(0);
 }





More information about the cfe-commits mailing list