From 7e120030a07ad8c4365526b1c5cd22a641297635 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 24 Nov 2009 05:36:32 +0000 Subject: [PATCH] When mangling a ctor/dtor we need to take into consideration whether it's a member template. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89741 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/Mangle.cpp | 19 +++++++++++++++++-- test/CodeGenCXX/member-templates.cpp | 11 +++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index 6dacd35d2b..b09b27f489 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/lib/CodeGen/Mangle.cpp @@ -29,6 +29,21 @@ using namespace clang; namespace { + +static const CXXMethodDecl *getStructor(const CXXMethodDecl *MD) { + assert((isa(MD) || isa(MD)) && + "Passed in decl is not a ctor or dtor!"); + + if (const TemplateDecl *TD = MD->getPrimaryTemplate()) { + MD = cast(TD->getTemplatedDecl()); + + assert((isa(MD) || isa(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 @@ public: : Context(C), Out(Res), Structor(0), StructorType(0) { } CXXNameMangler(MangleContext &C, llvm::SmallVectorImpl &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 &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; } diff --git a/test/CodeGenCXX/member-templates.cpp b/test/CodeGenCXX/member-templates.cpp index c2df012053..d85d6394f0 100644 --- a/test/CodeGenCXX/member-templates.cpp +++ b/test/CodeGenCXX/member-templates.cpp @@ -7,3 +7,14 @@ struct A { }; template A::A(T) {} + +struct B { + template + B(T); +}; + +template B::B(T) {} + +// CHECK: define void @_ZN1BC1IiEET_(%struct.B* %this, i32) +// CHECK: define void @_ZN1BC2IiEET_(%struct.B* %this, i32) +template B::B(int); -- 2.40.0