diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-03-04 05:38:05 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-03-04 05:38:05 +0000 |
commit | 8f77453f7cdee7de088e14aa9782b1ff30aa9bf7 (patch) | |
tree | 86b6029c58c5a2aa4994f147790709f1359355fa | |
parent | c25fd190ef5ca173bc53140c7f705e3f659d2d7d (diff) | |
download | bcm5719-llvm-8f77453f7cdee7de088e14aa9782b1ff30aa9bf7.tar.gz bcm5719-llvm-8f77453f7cdee7de088e14aa9782b1ff30aa9bf7.zip |
MS ABI: Mangle variable templates properly
We wouldn't recognize variable templates as being templates leading us
to leave the template arguments off of the mangled name. This would
allow two unrelated templates to map to the same mangled name.
N.B. While MSVC doesn't support variable templates as of this date,
this mangling is the most likely thing they will choose to use. Their
demangler can successfully demangle our manglings with the template
arguments shown.
llvm-svn: 202789
-rw-r--r-- | clang/lib/AST/MicrosoftMangle.cpp | 8 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/mangle-ms-cxx14.cpp | 8 |
2 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index 72ab3732e2d..a610e157d90 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -562,6 +562,13 @@ isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { return Spec->getSpecializedTemplate(); } + // Check if we have a variable template. + if (const VarTemplateSpecializationDecl *Spec = + dyn_cast<VarTemplateSpecializationDecl>(ND)) { + TemplateArgs = &Spec->getTemplateArgs(); + return Spec->getSpecializedTemplate(); + } + return 0; } @@ -585,7 +592,6 @@ MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, return; } - // We have a class template. // Here comes the tricky thing: if we need to mangle something like // void foo(A::X<Y>, B::X<Y>), // the X<Y> part is aliased. However, if you need to mangle diff --git a/clang/test/CodeGenCXX/mangle-ms-cxx14.cpp b/clang/test/CodeGenCXX/mangle-ms-cxx14.cpp new file mode 100644 index 00000000000..5bf0e967a79 --- /dev/null +++ b/clang/test/CodeGenCXX/mangle-ms-cxx14.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -std=c++1y -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s + +template <typename> int x = 0; + +// CHECK: "\01??$x@X@@3HA" +template <> int x<void>; +// CHECK: "\01??$x@H@@3HA" +template <> int x<int>; |