From 4285f84a5c3725210b4f12551af6c5d467d0763d Mon Sep 17 00:00:00 2001 From: Timur Iskhodzhanov Date: Tue, 26 Jun 2012 22:29:50 +0000 Subject: [PATCH] [Windows] Improve mangling of templates when back references are present git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159234 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/MicrosoftMangle.cpp | 7 ++ test/CodeGenCXX/mangle-ms-back-references.cpp | 65 ++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index 0d42689833..37c654d666 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -706,8 +706,15 @@ void MicrosoftCXXNameMangler::mangleTemplateInstantiationName( // ::= // ::= // Always start with the unqualified name. + + // Templates have their own context for back references. + BackRefMap TemplateContext; + NameBackReferences.swap(TemplateContext); + mangleUnscopedTemplateName(TD); mangleTemplateArgs(TemplateArgs); + + NameBackReferences.swap(TemplateContext); } void diff --git a/test/CodeGenCXX/mangle-ms-back-references.cpp b/test/CodeGenCXX/mangle-ms-back-references.cpp index 95ac5bb921..e15f14b754 100644 --- a/test/CodeGenCXX/mangle-ms-back-references.cpp +++ b/test/CodeGenCXX/mangle-ms-back-references.cpp @@ -9,7 +9,7 @@ void f2(const char* a, char* b) {} void f3(int a, const char* b, const char* c) {} // CHECK: "\01?f3@@YAXHPBD0@Z" -const char *f4(const char* a, const char* b) {} +const char *f4(const char* a, const char* b) { return 0; } // CHECK: "\01?f4@@YAPBDPBD0@Z" void f5(char const* a, unsigned int b, char c, void const* d, char const* e, unsigned int f) {} @@ -46,7 +46,7 @@ void g4(const char* a, struct S* b, const char* c, struct S* d) { // built-ins. typedef unsigned int uintptr_t; typedef unsigned int size_t; -void *h(size_t a, uintptr_t b) {} +void *h(size_t a, uintptr_t b) { return 0; } // CHECK: "\01?h@@YAPAXII@Z" // Function pointers might be mangled in a complex way. @@ -61,3 +61,64 @@ void h2(void (*f_ptr)(void *), void *arg) {} PInt3Func h3(PInt3Func x, PInt3Func y, int* z) { return 0; } // CHECK: "\01?h3@@YAP6APAHPAH0@ZP6APAH00@Z10@Z" + +namespace PR13207 { +class A {}; +class B {}; +class C {}; + +template +class I {}; +template +class J {}; +template +class K {}; + +class L { + public: + void foo(I x) {} +}; +// CHECK: "\01?foo@L@PR13207@@QAEXV?$I@VA@PR13207@@@2@@Z" + +void call_l_foo(L* l) { l->foo(I()); } + +void foo(I x) {} +// CHECK: "\01?foo@PR13207@@YAXV?$I@VA@PR13207@@@1@@Z" +void foo2(I x, I y) { } +// CHECK "\01?foo2@PR13207@@YAXV?$I@VA@PR13207@@@1@0@Z" +void bar(J x) {} +// CHECK: "\01?bar@PR13207@@YAXV?$J@VA@PR13207@@VB@2@@1@@Z" +void spam(K x) {} +// CHECK: "\01?spam@PR13207@@YAXV?$K@VA@PR13207@@VB@2@VC@2@@1@@Z" + +namespace NA { +class X {}; +template class Y {}; +void foo(Y x) {} +// CHECK: "\01?foo@NA@PR13207@@YAXV?$Y@VX@NA@PR13207@@@12@@Z" +} + +namespace NB { +class X {}; +template class Y {}; +void foo(Y x) {} +// CHECK: "\01?foo@NB@PR13207@@YAXV?$Y@VX@NA@PR13207@@@12@@Z" + +void bar(NA::Y x) {} +// CHECK: "\01?bar@NB@PR13207@@YAXV?$Y@VX@NB@PR13207@@@NA@2@@Z" + +void spam(NA::Y x) {} +// CHECK: "\01?spam@NB@PR13207@@YAXV?$Y@VX@NA@PR13207@@@NA@2@@Z" +} + +namespace NC { +class X {}; +template class Y {}; + +void foo(Y x) {} +// CHECK: "\01?foo@NC@PR13207@@YAXV?$Y@VX@NB@PR13207@@@12@@Z" + +void foobar(NC::Y > > x) {} +// CHECK: "\01?foobar@NC@PR13207@@YAXV?$Y@V?$Y@V?$Y@VX@NA@PR13207@@@NA@PR13207@@@NB@PR13207@@@12@@Z" +} +} -- 2.40.0