From df963a38a9e27fc43b485dfdf52bc1b090087e06 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 22 Sep 2017 22:21:44 +0000 Subject: DR1113: anonymous namespaces formally give their contents internal linkage. This doesn't affect our code generation in any material way -- we already give such declarations internal linkage from a codegen perspective -- but it has some subtle effects on code validity. We suppress the 'L' (internal linkage) marker for mangled names in anonymous namespaces, because it is redundant (the information is already carried by the namespace); this deviates from GCC's behavior if a variable or function in an anonymous namespace is redundantly declared 'static' (where GCC does include the 'L'), but GCC's behavior is incoherent because such a declaration can be validly declared with or without the 'static'. We still deviate from the standard in one regard here: extern "C" declarations in anonymous namespaces are still granted external linkage. Changing those does not appear to have been an intentional consequence of the standard change in DR1113. llvm-svn: 314037 --- clang/lib/AST/ItaniumMangle.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'clang/lib/AST/ItaniumMangle.cpp') diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 5ce52171562..8c5ebd0113a 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -1287,9 +1287,15 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, // // void test() { extern void foo(); } // static void foo(); + // + // Don't bother with the L marker for names in anonymous namespaces; the + // 12_GLOBAL__N_1 mangling is quite sufficient there, and this better + // matches GCC anyway, because GCC does not treat anonymous namespaces as + // implying internal linkage. if (ND && ND->getFormalLinkage() == InternalLinkage && !ND->isExternallyVisible() && - getEffectiveDeclContext(ND)->isFileContext()) + getEffectiveDeclContext(ND)->isFileContext() && + !ND->isInAnonymousNamespace()) Out << 'L'; auto *FD = dyn_cast(ND); -- cgit v1.2.3