[cfe-commits] r162638 - in /cfe/trunk: lib/AST/MicrosoftMangle.cpp test/CodeGenCXX/mangle-ms-template-callback.cpp test/CodeGenCXX/mangle-ms.cpp
John McCall
rjmccall at apple.com
Fri Aug 24 18:12:57 PDT 2012
Author: rjmccall
Date: Fri Aug 24 20:12:56 2012
New Revision: 162638
URL: http://llvm.org/viewvc/llvm-project?rev=162638&view=rev
Log:
Fix the mangling of function pointers in the MS ABI.
Patch by Timur Iskhodzhanov!
Added:
cfe/trunk/test/CodeGenCXX/mangle-ms-template-callback.cpp
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=162638&r1=162637&r2=162638&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Aug 24 20:12:56 2012
@@ -1059,6 +1059,8 @@
SourceRange) {
// Structors only appear in decls, so at this point we know it's not a
// structor type.
+ // FIXME: This may not be lambda-friendly.
+ Out << "$$A6";
mangleType(T, NULL, false, false);
}
void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T,
@@ -1214,7 +1216,7 @@
if (CC == CC_Default) {
if (IsInstMethod) {
const FunctionProtoType *FPT =
- T->getCanonicalTypeUnqualified().getAs<FunctionProtoType>();
+ T->getCanonicalTypeUnqualified().castAs<FunctionProtoType>();
bool isVariadic = FPT->isVariadic();
CC = getASTContext().getDefaultCXXMethodCallConv(isVariadic);
} else {
@@ -1497,7 +1499,9 @@
void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T,
SourceRange Range) {
Out << "_E";
- mangleType(T->getPointeeType(), Range);
+
+ QualType pointee = T->getPointeeType();
+ mangleType(pointee->castAs<FunctionProtoType>(), NULL, false, false);
}
void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *T,
Added: cfe/trunk/test/CodeGenCXX/mangle-ms-template-callback.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-template-callback.cpp?rev=162638&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-template-callback.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-template-callback.cpp Fri Aug 24 20:12:56 2012
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
+
+template<typename Signature>
+class C;
+
+template<typename Ret>
+class C<Ret(void)> {};
+typedef C<void(void)> C0;
+
+template<typename Ret, typename Arg1>
+class C<Ret(Arg1)> {};
+
+template<typename Ret, typename Arg1, typename Arg2>
+class C<Ret(Arg1, Arg2)> {};
+
+C0 callback_void;
+// CHECK: "\01?callback_void@@3V?$C@$$A6AXXZ@@A"
+
+volatile C0 callback_void_volatile;
+// CHECK: "\01?callback_void_volatile@@3V?$C@$$A6AXXZ@@C"
+
+class Type {};
+
+C<int(void)> callback_int;
+// CHECK: "\01?callback_int@@3V?$C@$$A6AHXZ@@A"
+C<Type(void)> callback_Type;
+// CHECK: "\01?callback_Type@@3V?$C@$$A6A?AVType@@XZ@@A"
+
+C<void(int)> callback_void_int;
+// CHECK: "\01?callback_void_int@@3V?$C@$$A6AXH at Z@@A"
+C<int(int)> callback_int_int;
+// CHECK: "\01?callback_int_int@@3V?$C@$$A6AHH at Z@@A"
+C<void(Type)> callback_void_Type;
+// CHECK: "\01?callback_void_Type@@3V?$C@$$A6AXVType@@@Z@@A"
+
+void foo(C0 c) {}
+// CHECK: "\01?foo@@YAXV?$C@$$A6AXXZ@@@Z"
+
+// Here be dragons!
+// Let's face the magic of template partial specialization...
+
+void function(C<void(void)>) {}
+// CHECK: "\01?function@@YAXV?$C@$$A6AXXZ@@@Z"
+
+template<typename Ret> class C<Ret(*)(void)> {};
+void function_pointer(C<void(*)(void)>) {}
+// CHECK: "\01?function_pointer@@YAXV?$C at P6AXXZ@@@Z"
+
+// Block equivalent to the previous definitions.
+template<typename Ret> class C<Ret(^)(void)> {};
+void block(C<void(^)(void)>) {}
+// CHECK: "\01?block@@YAXV?$C at P_EAXXZ@@@Z"
+// FYI blocks are not present in MSVS, so we're free to choose the spec.
+
+template<typename T> class C<void (T::*)(void)> {};
+class Z {
+ public:
+ void method() {}
+};
+void member_pointer(C<void (Z::*)(void)>) {}
+// CHECK: "\01?member_pointer@@YAXV?$C at P8Z@@AEXXZ@@@Z"
+
+template<typename T> void bar(T) {}
+
+void call_bar() {
+ bar<int (*)(int)>(0);
+// CHECK: "\01??$bar at P6AHH@Z@@YAXP6AHH at Z@Z"
+
+ bar<int (^)(int)>(0);
+// CHECK: "\01??$bar at P_EAHH@Z@@YAXP_EAHH at Z@Z"
+// FYI blocks are not present in MSVS, so we're free to choose the spec.
+}
Modified: cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms.cpp?rev=162638&r1=162637&r2=162638&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms.cpp Fri Aug 24 20:12:56 2012
@@ -128,6 +128,10 @@
void eta(int (^)(int, int)) {}
// CHECK: @"\01?eta@@YAXP_EAHHH at Z@Z"
+typedef int theta_arg(int,int);
+void theta(theta_arg^ block) {}
+// CHECK: @"\01?theta@@YAXP_EAHHH at Z@Z"
+
void operator_new_delete() {
char *ptr = new char;
// CHECK: @"\01??2 at YAPAXI@Z"
More information about the cfe-commits
mailing list