llvm-project/clang/lib/AST
Douglas Gregor 7dc5c17d92 When a function or variable somehow depends on a type or declaration
that is in an anonymous namespace, give that function or variable
internal linkage.

This change models an oddity of the C++ standard, where names declared
in an anonymous namespace have external linkage but, because anonymous
namespace are really "uniquely-named" namespaces, the names cannot be
referenced from other translation units. That means that they have
external linkage for semantic analysis, but the only sensible
implementation for code generation is to give them internal
linkage. We now model this notion via the UniqueExternalLinkage
linkage type. There are several changes here:

  - Extended NamedDecl::getLinkage() to produce UniqueExternalLinkage
    when the declaration is in an anonymous namespace.
  - Added Type::getLinkage() to determine the linkage of a type, which
    is defined as the minimum linkage of the types (when we're dealing
    with a compound type that is not a struct/class/union).
  - Extended NamedDecl::getLinkage() to consider the linkage of the
    template arguments and template parameters of function template
    specializations and class template specializations.
  - Taught code generation to rely on NamedDecl::getLinkage() when
    determining the linkage of variables and functions, also
    considering the linkage of the types of those variables and
    functions (C++ only). Map UniqueExternalLinkage to internal
    linkage, taking out the explicit checks for
    isInAnonymousNamespace().

This fixes much of PR5792, which, as discovered by Anders Carlsson, is
actually the reason behind the pass-manager assertion that causes the
majority of clang-on-clang regression test failures. With this fix,
Clang-built-Clang+LLVM passes 88% of its regression tests (up from
67%). The specific numbers are:

LLVM:
  Expected Passes    : 4006
  Expected Failures  : 32
  Unsupported Tests  : 40
  Unexpected Failures: 736

Clang:
  Expected Passes    : 1903
  Expected Failures  : 14
  Unexpected Failures: 75

Overall:
  Expected Passes    : 5909
  Expected Failures  : 46
  Unsupported Tests  : 40
  Unexpected Failures: 811

Still to do:
  - Improve testing
  - Check whether we should allow the presence of types with
  InternalLinkage (in addition to UniqueExternalLinkage) given
  variables/functions internal linkage in C++, as mentioned in
  PR5792. 
  - Determine how expensive the getLinkage() calls are in practice;
  consider caching the result in NamedDecl.
  - Assess the feasibility of Chris's idea in comment #1 of PR5792.

llvm-svn: 95216
2010-02-03 09:33:45 +00:00
..
APValue.cpp Convert the type of the LValue offset variable in APValue to CharUnits, moving 2010-01-15 12:37:54 +00:00
ASTConsumer.cpp Push DeclGroup much farther throughout the compiler. Now the various 2009-03-29 16:50:03 +00:00
ASTContext.cpp Change the return type of ASTContext::getDeclAlignInBytes() to CharUnits and, 2010-01-27 17:10:57 +00:00
AttrImpl.cpp Make clone() method out-of-line for Attr classes. 2010-01-10 14:38:13 +00:00
CMakeLists.txt Make clone() method out-of-line for Attr classes. 2010-01-10 14:38:13 +00:00
CXXInheritance.cpp Implement elementary access control. 2010-01-23 00:46:32 +00:00
Decl.cpp When a function or variable somehow depends on a type or declaration 2010-02-03 09:33:45 +00:00
DeclBase.cpp Create function, block, and template parameters in the context of the 2010-01-22 00:28:27 +00:00
DeclCXX.cpp Rework base and member initialization in constructors, with several 2010-01-31 09:12:51 +00:00
DeclGroup.cpp Add 'DeclStmt::DoDestroy()' which doesn't actually recurse over its child expressions (via StmtIterator), as those expressions are owned by the Decls and Types (which are destroyed elsewhere). This fixes a crasher reported in <rdar://problem/7487294>. 2009-12-23 08:56:00 +00:00
DeclObjC.cpp Patch to implement rewriting of properties. 2010-01-21 17:36:00 +00:00
DeclPrinter.cpp Rework base and member initialization in constructors, with several 2010-01-31 09:12:51 +00:00
DeclTemplate.cpp Fix PR6156 and test several of the basic aspects of non-type template arguments 2010-01-31 07:24:03 +00:00
DeclarationName.cpp Implement semantic checking for C++ literal operators. 2010-01-13 09:01:02 +00:00
Expr.cpp Numerous changes to selector handling: 2010-02-03 02:09:30 +00:00
ExprCXX.cpp Extract a common base class between UnresolvedLookupExpr and 2010-02-02 06:20:04 +00:00
ExprConstant.cpp In C++, an initializer on a variable doesn't necessarily mean it's the definition. With that in mind, rename getDefinition to getAnyInitializer (to distinguish it from getInit) and reimplement it in terms of isThisDeclarationADefinition. Update all code to use this new function. 2010-02-01 20:16:42 +00:00
FullExpr.cpp More work on the FullExpr class. 2009-12-16 06:10:22 +00:00
InheritViz.cpp Remove tabs, and whitespace cleanups. 2009-09-09 15:08:12 +00:00
Makefile -fno-rtti is now the default. 2010-01-24 20:43:31 +00:00
NestedNameSpecifier.cpp Move all of the type-printing logic to its own C++ source file 2009-11-10 00:39:07 +00:00
ParentMap.cpp Remove tabs, and whitespace cleanups. 2009-09-09 15:08:12 +00:00
RecordLayoutBuilder.cpp Be sure to select primary bases among the nearly empties in preorder, 2010-01-22 20:27:17 +00:00
RecordLayoutBuilder.h Move key functions to a separate map. 2009-12-07 04:35:11 +00:00
Stmt.cpp Implement Doug's suggestion. Eliminate the Stmts pointer from CXXTryStmt and instead allocate the statements after the object. 2010-02-03 03:56:39 +00:00
StmtDumper.cpp Dump the constructor type for a CXXConstructExpr. 2010-02-02 19:03:45 +00:00
StmtIterator.cpp Add StmtIterator support for iterating over both the condition 2009-12-23 23:38:34 +00:00
StmtPrinter.cpp Add an CXXBindReferenceExpr (not used just yet). 2010-01-29 02:39:32 +00:00
StmtProfile.cpp Add an CXXBindReferenceExpr (not used just yet). 2010-01-29 02:39:32 +00:00
StmtViz.cpp Adapt to the DOTGraphTraits changes in LLVM. 2009-11-30 14:16:05 +00:00
TemplateBase.cpp DeclaratorInfo -> TypeSourceInfo. Makes an effort to rename associated variables, 2009-12-07 02:54:59 +00:00
TemplateName.cpp Push overloaded function templates through the parser using a totally different 2009-12-02 08:04:21 +00:00
Type.cpp When a function or variable somehow depends on a type or declaration 2010-02-03 09:33:45 +00:00
TypeLoc.cpp float, double, and long double do need extra data in the 2010-01-18 20:37:56 +00:00
TypePrinter.cpp Implement name lookup for conversion function template specializations 2010-01-11 18:40:55 +00:00