]> granicus.if.org Git - clang/commitdiff
[MS ABI] Give __attribute__((overloadable)) functions pretty names
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 18 May 2015 00:05:29 +0000 (00:05 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 18 May 2015 00:05:29 +0000 (00:05 +0000)
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

lib/AST/MicrosoftMangle.cpp
test/CodeGenCXX/mangle-ms.cpp

index 818ea30b328cc51d8c35f46cb49f5aa05a6092ee..894db88c27d570b2f136ac5378ea4c745e703857 100644 (file)
@@ -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<OverloadableAttr>())
+      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) {
   // <calling-convention> ::= A # __cdecl
index ed2172b7c4d85c4f7a77b20a49592b4fa5ee6df0..0da5c6f1f8df1ada630636775f90b1e4dfa6c45d 100644 (file)
@@ -386,3 +386,6 @@ void fn_tmpl() {}
 
 template void fn_tmpl<extern_c_func>();
 // CHECK-DAG: @"\01??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ"
+
+extern "C" void __attribute__((overloadable)) overloaded_fn() {}
+// CHECK-DAG: @"\01?overloaded_fn@@$$J0YAXXZ"