From cf956c43e15b4860922b242785417fcb34afb5af Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 5 Feb 2014 18:59:38 +0000 Subject: [PATCH] MS ABI: Fix mangling of static methods and function references Function references always use $1? like function pointers and never $E? like var decl references. Static methods are mangled like function pointers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200869 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/MicrosoftMangle.cpp | 13 +++++++++---- test/CodeGenCXX/mangle-ms-template-callback.cpp | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index b2f74cf4d1..6ce7018be1 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -1090,12 +1090,17 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD, } case TemplateArgument::Declaration: { const NamedDecl *ND = cast(TA.getAsDecl()); - if (const FieldDecl *FD = dyn_cast(ND)) + if (const FieldDecl *FD = dyn_cast(ND)) { mangleMemberDataPointer(cast(FD->getParent()), FD); - else if (const CXXMethodDecl *MD = dyn_cast(ND)) - mangleMemberFunctionPointer(MD->getParent(), MD); - else + } else if (const FunctionDecl *FD = dyn_cast(ND)) { + const CXXMethodDecl *MD = dyn_cast(ND); + if (MD && MD->isInstance()) + mangleMemberFunctionPointer(MD->getParent(), MD); + else + mangle(ND, "$1?"); + } else { mangle(ND, TA.isDeclForReferenceParam() ? "$E?" : "$1?"); + } break; } case TemplateArgument::Integral: diff --git a/test/CodeGenCXX/mangle-ms-template-callback.cpp b/test/CodeGenCXX/mangle-ms-template-callback.cpp index cfa4e880a5..1a8f82fc82 100644 --- a/test/CodeGenCXX/mangle-ms-template-callback.cpp +++ b/test/CodeGenCXX/mangle-ms-template-callback.cpp @@ -70,3 +70,20 @@ void call_bar() { // CHECK: "\01??$bar@P_EAHH@Z@@YAXP_EAHH@Z@Z" // FYI blocks are not present in MSVS, so we're free to choose the spec. } + +template void WrapFnPtr() { Fn(); } +template void WrapFnRef() { Fn(); } +struct Thing { + static void VoidStaticMethod(); +}; +void VoidFn(); +void CallWrapper() { + WrapFnPtr(); + WrapFnRef(); + WrapFnPtr(); + WrapFnRef(); +} +// CHECK: call {{.*}} @"\01??$WrapFnPtr@$1?VoidFn@@YAXXZ@@YAXXZ" +// CHECK: call {{.*}} @"\01??$WrapFnRef@$1?VoidFn@@YAXXZ@@YAXXZ" +// CHECK: call {{.*}} @"\01??$WrapFnPtr@$1?VoidStaticMethod@Thing@@SAXXZ@@YAXXZ" +// CHECK: call {{.*}} @"\01??$WrapFnRef@$1?VoidStaticMethod@Thing@@SAXXZ@@YAXXZ" -- 2.40.0