summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-05-18 00:05:29 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-05-18 00:05:29 +0000
commit5a7cfea6b405445e77c66418110f1c9016af795c (patch)
treeb1ef2349100c620680e985c92a02c3637dfbd8b8
parentab4b4a1968b9276d353bb99cfd02e4fa10c7b742 (diff)
downloadbcm5719-llvm-5a7cfea6b405445e77c66418110f1c9016af795c.tar.gz
bcm5719-llvm-5a7cfea6b405445e77c66418110f1c9016af795c.zip
[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. llvm-svn: 237548
-rw-r--r--clang/lib/AST/MicrosoftMangle.cpp11
-rw-r--r--clang/test/CodeGenCXX/mangle-ms.cpp3
2 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 818ea30b328..894db88c27d 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/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<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
diff --git a/clang/test/CodeGenCXX/mangle-ms.cpp b/clang/test/CodeGenCXX/mangle-ms.cpp
index ed2172b7c4d..0da5c6f1f8d 100644
--- a/clang/test/CodeGenCXX/mangle-ms.cpp
+++ b/clang/test/CodeGenCXX/mangle-ms.cpp
@@ -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"
OpenPOWER on IntegriCloud