[cfe-commits] [PATCH] [VCPP] Mangle template parameters pack
pravic
ehysta at gmail.com
Mon Nov 5 13:46:47 PST 2012
__ptr64 handling moved to the different patch
Hi eli.friedman, cdavis5x,
http://llvm-reviews.chandlerc.com/D99
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D99?vs=260&id=262#toc
Files:
lib/AST/MicrosoftMangle.cpp
test/CodeGenCXX/mangle-ms-variadic-templates.cpp
Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -825,9 +825,23 @@
break;
case TemplateArgument::Template:
case TemplateArgument::TemplateExpansion:
- case TemplateArgument::Declaration:
- case TemplateArgument::NullPtr:
case TemplateArgument::Pack: {
+ SourceRange loc = TAL.getSourceRange();
+ if (TA.pack_size() > 0) {
+ // mangle pack as template types sequence
+ for (TemplateArgument::pack_iterator PA = TA.pack_begin(),
+ PAEnd = TA.pack_end(); PA != PAEnd; ++PA) {
+ mangleType(PA->getAsType(), loc);
+ }
+ } else {
+ // mangle empty pack
+ // <empty VT> ::= '@' "$$$V" '@'
+ Out << "$$$V";
+ }
+ break;
+ }
+ case TemplateArgument::Declaration:
+ case TemplateArgument::NullPtr: {
// Issue a diagnostic.
DiagnosticsEngine &Diags = Context.getDiags();
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
Index: test/CodeGenCXX/mangle-ms-variadic-templates.cpp
===================================================================
--- test/CodeGenCXX/mangle-ms-variadic-templates.cpp
+++ test/CodeGenCXX/mangle-ms-variadic-templates.cpp
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -fms-extensions -Xclang -cxx-abi -Xclang microsoft -target i386-pc-win32 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -fms-extensions -Xclang -cxx-abi -Xclang microsoft -target x86_64-pc-win32 -o - %s | FileCheck -check-prefix=CHK64 %s
+// expected-no-diagnostics
+
+// Simple mangling test
+template<typename... T> void va(T...);
+
+void test_va() {
+ // CHECK: call void @"\01??$va@$$$V@@YAXXZ"()
+ // CHK64: call void @"\01??$va@$$$V@@YAXXZ"()
+ va();
+ // CHECK: call void @"\01??$va at H@@YAXH at Z"(i32 1)
+ // CHK64: call void @"\01??$va at H@@YAXH at Z"(i32 1)
+ va(1);
+ // CHECK: call void @"\01??$va at HN@@YAXHN at Z"(i32 1, double 2.300000e+00)
+ // CHK64: call void @"\01??$va at HN@@YAXHN at Z"(i32 1, double 2.300000e+00)
+ va(1,2.3);
+ // CHECK: call void @"\01??$va at M@@YAXM at Z"(float 2.500000e+00)
+ // CHK64: call void @"\01??$va at M@@YAXM at Z"(float 2.500000e+00)
+ va(2.5f);
+}
+
+// Struct mangling
+template<class... T>
+struct VS {
+ VS(T...) {}
+};
+
+void test_vs() {
+ // 'QAE': __thiscall (x86)
+ // 'QAA': __cdecl (x86)
+ // 'QEAA': __cdecl __ptr64 (x64)
+ // CHECK: %struct.VS* @"\01??0?$VS@$$$V@@QAE at XZ"(%struct.VS* %vs0)
+ // CHK64: %struct.VS* @"\01??0?$VS@$$$V@@QEAA at XZ"(%struct.VS* %vs0)
+ VS<> vs0;
+ // CHECK: %struct.VS.0* @"\01??0?$VS at H@@QAE at H@Z"(%struct.VS.0* %vs1, i32 1)
+ // CHK64: %struct.VS.0* @"\01??0?$VS at H@@QEAA at H@Z"(%struct.VS.0* %vs1, i32 1)
+ VS<int> vs1(1);
+ // CHECK: %struct.VS.2* @"\01??0?$VS at HN@@QAE at HN@Z"(%struct.VS.2* %vs2, i32 1, double 2.300000e+00)
+ // CHK64: %struct.VS.2* @"\01??0?$VS at HN@@QEAA at HN@Z"(%struct.VS.2* %vs2, i32 1, double 2.300000e+00)
+ VS<int, double> vs2(1, 2.3);
+}
+
+// Mangling for template argument packs
+template<typename ...Types> void f1() {}
+// CHECK: define weak_odr void @"\01??$f1@$$$V@@YAXXZ"
+// CHK64: define weak_odr void @"\01??$f1@$$$V@@YAXXZ"
+template void f1<>();
+// CHECK: define weak_odr void @"\01??$f1 at H@@YAXXZ"
+// CHK64: define weak_odr void @"\01??$f1 at H@@YAXXZ"
+template void f1<int>();
+// CHECK: define weak_odr void @"\01??$f1 at HM@@YAXXZ"
+// CHK64: define weak_odr void @"\01??$f1 at HM@@YAXXZ"
+template void f1<int, float>();
+
+// Mangling function parameter packs
+template<typename ...Types> void f2(Types...) {}
+// CHECK: define weak_odr void @"\01??$f2@$$$V@@YAXXZ"
+// CHK64: define weak_odr void @"\01??$f2@$$$V@@YAXXZ"
+template void f2<>();
+
+// Mangling non-trivial function parameter packs
+template<typename ...Types> void f3(const Types *...) {}
+// CHECK: define weak_odr void @"\01??$f3@$$$V@@YAXXZ"
+// CHK64: define weak_odr void @"\01??$f3@$$$V@@YAXXZ"
+template void f3<>();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99.4.patch
Type: text/x-patch
Size: 3984 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121105/ff5c739b/attachment.bin>
More information about the cfe-commits
mailing list