[cfe-commits] r90544 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenCXX/mangle-subst-std.cpp
Anders Carlsson
andersca at mac.com
Thu Dec 3 22:23:23 PST 2009
Author: andersca
Date: Fri Dec 4 00:23:23 2009
New Revision: 90544
URL: http://llvm.org/viewvc/llvm-project?rev=90544&view=rev
Log:
Correctly mangle the 'std' namespace inside extern "C++" blocks.
Modified:
cfe/trunk/lib/CodeGen/Mangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp
Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=90544&r1=90543&r2=90544&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Fri Dec 4 00:23:23 2009
@@ -247,14 +247,32 @@
mangleBareFunctionType(FT, MangleReturnType);
}
-static bool isStdNamespace(const NamespaceDecl *NS) {
+/// isStd - Return whether a given namespace is the 'std' namespace.
+static bool isStd(const NamespaceDecl *NS) {
const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier();
return II && II->isStr("std");
}
+static const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC) {
+ while (isa<LinkageSpecDecl>(DC)) {
+ assert(cast<LinkageSpecDecl>(DC)->getLanguage() ==
+ LinkageSpecDecl::lang_cxx && "Unexpected linkage decl!");
+ DC = DC->getParent();
+ }
+
+ return DC;
+}
+
+// isStdNamespace - Return whether a given decl context is a toplevel 'std'
+// namespace.
static bool isStdNamespace(const DeclContext *DC) {
- return DC->isNamespace() && DC->getParent()->isTranslationUnit() &&
- isStdNamespace(cast<NamespaceDecl>(DC));
+ if (!DC->isNamespace())
+ return false;
+
+ if (!IgnoreLinkageSpecDecls(DC->getParent())->isTranslationUnit())
+ return false;
+
+ return isStd(cast<NamespaceDecl>(DC));
}
static const TemplateDecl *
@@ -317,12 +335,7 @@
void CXXNameMangler::mangleName(const TemplateDecl *TD,
const TemplateArgument *TemplateArgs,
unsigned NumTemplateArgs) {
- const DeclContext *DC = TD->getDeclContext();
- while (isa<LinkageSpecDecl>(DC)) {
- assert(cast<LinkageSpecDecl>(DC)->getLanguage() ==
- LinkageSpecDecl::lang_cxx && "Unexpected linkage decl!");
- DC = DC->getParent();
- }
+ const DeclContext *DC = IgnoreLinkageSpecDecls(TD->getDeclContext());
if (DC->isTranslationUnit() || isStdNamespace(DC)) {
mangleUnscopedTemplateName(TD);
@@ -1244,11 +1257,8 @@
bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) {
// <substitution> ::= St # ::std::
- // FIXME: type_info == comes out as __ZNK3std9type_infoeqERKS0_ instead of
- // __ZNKSt9type_infoeqERKS_
- // FIXME: __ZSt13set_terminatePFvvE comes out as __ZNSt13set_terminateEPFvvE.
if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
- if (isStdNamespace(NS)) {
+ if (isStd(NS)) {
Out << "St";
return true;
}
Modified: cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp?rev=90544&r1=90543&r2=90544&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-subst-std.cpp Fri Dec 4 00:23:23 2009
@@ -37,3 +37,13 @@
// CHECK: _Z1fSo
void f(std::basic_ostream<char, std::char_traits<char> >) { }
+
+extern "C++" {
+namespace std
+{
+ typedef void (*terminate_handler) ();
+
+ // CHECK: _ZSt13set_terminatePFvvE
+ terminate_handler set_terminate(terminate_handler) { return 0; }
+}
+}
More information about the cfe-commits
mailing list