From: David Majnemer Date: Mon, 18 May 2015 00:05:29 +0000 (+0000) Subject: [MS ABI] Give __attribute__((overloadable)) functions pretty names X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1136b098285341cfb60363863fe3a747724bc9d;p=clang [MS ABI] Give __attribute__((overloadable)) functions pretty names It turns out that there is a mangling for 'extern "C"', it's only used by MSVC in /clr mode. Co-opt this mangling so that extern "C" functions marked overloadable get demangled nicely. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237548 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index 818ea30b32..894db88c27 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -413,7 +413,13 @@ void MicrosoftCXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD, // As it stands, these functions still need to get expressed in the full // external name. They have their class and type omitted, replaced with '9'. if (ShouldMangle) { - // First, the function class. + // We would like to mangle all extern "C" functions using this additional + // component but this would break compatibility with MSVC's behavior. + // Instead, do this when we know that compatibility isn't important (in + // other words, when it is an overloaded extern "C" funciton). + if (FD->isExternC() && FD->hasAttr()) + Out << "$$J0"; + mangleFunctionClass(FD); mangleFunctionType(FT, FD); @@ -1762,8 +1768,9 @@ void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) { else Out << 'Q'; } - } else + } else { Out << 'Y'; + } } void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) { // ::= A # __cdecl diff --git a/test/CodeGenCXX/mangle-ms.cpp b/test/CodeGenCXX/mangle-ms.cpp index ed2172b7c4..0da5c6f1f8 100644 --- a/test/CodeGenCXX/mangle-ms.cpp +++ b/test/CodeGenCXX/mangle-ms.cpp @@ -386,3 +386,6 @@ void fn_tmpl() {} template void fn_tmpl(); // CHECK-DAG: @"\01??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ" + +extern "C" void __attribute__((overloadable)) overloaded_fn() {} +// CHECK-DAG: @"\01?overloaded_fn@@$$J0YAXXZ"