r237548 - [MS ABI] Give __attribute__((overloadable)) functions pretty names

David Majnemer david.majnemer at gmail.com
Sun May 17 17:05:29 PDT 2015


Author: majnemer
Date: Sun May 17 19:05:29 2015
New Revision: 237548

URL: http://llvm.org/viewvc/llvm-project?rev=237548&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/AST/MicrosoftMangle.cpp
    cfe/trunk/test/CodeGenCXX/mangle-ms.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=237548&r1=237547&r2=237548&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Sun May 17 19:05:29 2015
@@ -413,7 +413,13 @@ void MicrosoftCXXNameMangler::mangleFunc
   // 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::mangleFunc
         else
           Out << 'Q';
     }
-  } else
+  } else {
     Out << 'Y';
+  }
 }
 void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) {
   // <calling-convention> ::= A # __cdecl

Modified: cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms.cpp?rev=237548&r1=237547&r2=237548&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms.cpp Sun May 17 19:05:29 2015
@@ -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"





More information about the cfe-commits mailing list