r202789 - MS ABI: Mangle variable templates properly
David Majnemer
david.majnemer at gmail.com
Mon Mar 3 21:38:05 PST 2014
Author: majnemer
Date: Mon Mar 3 23:38:05 2014
New Revision: 202789
URL: http://llvm.org/viewvc/llvm-project?rev=202789&view=rev
Log:
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.
Added:
cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp
Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=202789&r1=202788&r2=202789&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Mon Mar 3 23:38:05 2014
@@ -562,6 +562,13 @@ isTemplate(const NamedDecl *ND, const Te
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::mangleUnqualifi
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
Added: cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp?rev=202789&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp Mon Mar 3 23:38:05 2014
@@ -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 at X@@3HA"
+template <> int x<void>;
+// CHECK: "\01??$x at H@@3HA"
+template <> int x<int>;
More information about the cfe-commits
mailing list