[cfe-commits] r89741 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenCXX/member-templates.cpp

Anders Carlsson andersca at mac.com
Mon Nov 23 21:36:32 PST 2009


Author: andersca
Date: Mon Nov 23 23:36:32 2009
New Revision: 89741

URL: http://llvm.org/viewvc/llvm-project?rev=89741&view=rev
Log:
When mangling a ctor/dtor we need to take into consideration whether it's a member template.

Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp
    cfe/trunk/test/CodeGenCXX/member-templates.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Mon Nov 23 23:36:32 2009
@@ -29,6 +29,21 @@
 using namespace clang;
 
 namespace {
+  
+static const CXXMethodDecl *getStructor(const CXXMethodDecl *MD) {
+  assert((isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) &&
+         "Passed in decl is not a ctor or dtor!");
+  
+  if (const TemplateDecl *TD = MD->getPrimaryTemplate()) {
+    MD = cast<CXXMethodDecl>(TD->getTemplatedDecl());
+
+    assert((isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) &&
+           "Templated decl is not a ctor or dtor!");
+  }
+    
+  return MD;
+}
+  
 /// CXXNameMangler - Manage the mangling of a single name.
 class CXXNameMangler {
   MangleContext &Context;
@@ -44,10 +59,10 @@
     : Context(C), Out(Res), Structor(0), StructorType(0) { }
   CXXNameMangler(MangleContext &C, llvm::SmallVectorImpl<char> &Res,
                  const CXXConstructorDecl *D, CXXCtorType Type)
-    : Context(C), Out(Res), Structor(D), StructorType(Type) { }
+    : Context(C), Out(Res), Structor(getStructor(D)), StructorType(Type) { }
   CXXNameMangler(MangleContext &C, llvm::SmallVectorImpl<char> &Res,
                  const CXXDestructorDecl *D, CXXDtorType Type)
-    : Context(C), Out(Res), Structor(D), StructorType(Type) { }
+    : Context(C), Out(Res), Structor(getStructor(D)), StructorType(Type) { }
 
   llvm::raw_svector_ostream &getStream() { return Out; }
 

Modified: cfe/trunk/test/CodeGenCXX/member-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-templates.cpp?rev=89741&r1=89740&r2=89741&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-templates.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-templates.cpp Mon Nov 23 23:36:32 2009
@@ -7,3 +7,14 @@
 };
 
 template<typename T> A::A(T) {}
+
+struct B {
+  template<typename T>
+  B(T);
+};
+
+template<typename T> B::B(T) {}
+
+// CHECK: define void @_ZN1BC1IiEET_(%struct.B* %this, i32)
+// CHECK: define void @_ZN1BC2IiEET_(%struct.B* %this, i32)
+template B::B(int);





More information about the cfe-commits mailing list