2006-10-15 22:34:45 +00:00
|
|
|
//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:25 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-10-15 22:34:45 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-06-04 13:04:04 +00:00
|
|
|
// This file implements the Decl subclasses.
|
2006-10-15 22:34:45 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Decl.h"
|
2009-02-03 19:21:40 +00:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-02-22 19:35:57 +00:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2009-05-10 22:57:19 +00:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2008-03-15 06:12:44 +00:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2009-08-19 01:27:32 +00:00
|
|
|
#include "clang/AST/TypeLoc.h"
|
2008-08-11 04:54:23 +00:00
|
|
|
#include "clang/AST/Stmt.h"
|
2008-12-17 23:39:55 +00:00
|
|
|
#include "clang/AST/Expr.h"
|
2009-12-15 19:16:31 +00:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2009-05-29 20:38:28 +00:00
|
|
|
#include "clang/AST/PrettyPrinter.h"
|
2010-10-24 17:26:50 +00:00
|
|
|
#include "clang/AST/ASTMutationListener.h"
|
2009-06-14 01:54:56 +00:00
|
|
|
#include "clang/Basic/Builtins.h"
|
2008-08-11 04:54:23 +00:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2010-05-11 21:36:43 +00:00
|
|
|
#include "clang/Basic/Specifiers.h"
|
2011-03-26 12:10:19 +00:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2009-09-04 01:14:41 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2008-05-20 00:43:19 +00:00
|
|
|
|
2006-10-25 05:11:20 +00:00
|
|
|
using namespace clang;
|
2006-10-15 22:34:45 +00:00
|
|
|
|
2008-03-31 00:36:02 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-01-20 01:17:11 +00:00
|
|
|
// NamedDecl Implementation
|
2008-11-09 23:41:00 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-03-26 12:10:19 +00:00
|
|
|
static llvm::Optional<Visibility> getVisibilityOf(const Decl *D) {
|
|
|
|
// If this declaration has an explicit visibility attribute, use it.
|
|
|
|
if (const VisibilityAttr *A = D->getAttr<VisibilityAttr>()) {
|
|
|
|
switch (A->getVisibility()) {
|
|
|
|
case VisibilityAttr::Default:
|
|
|
|
return DefaultVisibility;
|
|
|
|
case VisibilityAttr::Hidden:
|
|
|
|
return HiddenVisibility;
|
|
|
|
case VisibilityAttr::Protected:
|
|
|
|
return ProtectedVisibility;
|
|
|
|
}
|
2010-12-18 03:30:47 +00:00
|
|
|
|
2011-03-26 12:10:19 +00:00
|
|
|
return DefaultVisibility;
|
2010-10-28 04:18:25 +00:00
|
|
|
}
|
2010-12-18 03:30:47 +00:00
|
|
|
|
2011-03-26 12:10:19 +00:00
|
|
|
// If we're on Mac OS X, an 'availability' for Mac OS X attribute
|
|
|
|
// implies visibility(default).
|
|
|
|
if (D->getASTContext().Target.getTriple().getOS() == llvm::Triple::Darwin) {
|
|
|
|
for (specific_attr_iterator<AvailabilityAttr>
|
|
|
|
A = D->specific_attr_begin<AvailabilityAttr>(),
|
|
|
|
AEnd = D->specific_attr_end<AvailabilityAttr>();
|
|
|
|
A != AEnd; ++A)
|
|
|
|
if ((*A)->getPlatform()->getName().equals("macosx"))
|
|
|
|
return DefaultVisibility;
|
2010-10-22 21:05:15 +00:00
|
|
|
}
|
2011-03-26 12:10:19 +00:00
|
|
|
|
|
|
|
return llvm::Optional<Visibility>();
|
2010-10-22 21:05:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-30 11:50:40 +00:00
|
|
|
typedef NamedDecl::LinkageInfo LinkageInfo;
|
2010-10-22 21:05:15 +00:00
|
|
|
typedef std::pair<Linkage,Visibility> LVPair;
|
2010-10-30 11:50:40 +00:00
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
static LVPair merge(LVPair L, LVPair R) {
|
|
|
|
return LVPair(minLinkage(L.first, R.first),
|
|
|
|
minVisibility(L.second, R.second));
|
|
|
|
}
|
|
|
|
|
2010-10-30 11:50:40 +00:00
|
|
|
static LVPair merge(LVPair L, LinkageInfo R) {
|
|
|
|
return LVPair(minLinkage(L.first, R.linkage()),
|
|
|
|
minVisibility(L.second, R.visibility()));
|
|
|
|
}
|
|
|
|
|
2010-11-05 19:56:37 +00:00
|
|
|
namespace {
|
2010-11-02 01:45:15 +00:00
|
|
|
/// Flags controlling the computation of linkage and visibility.
|
|
|
|
struct LVFlags {
|
|
|
|
bool ConsiderGlobalVisibility;
|
|
|
|
bool ConsiderVisibilityAttributes;
|
2011-03-04 10:39:25 +00:00
|
|
|
bool ConsiderTemplateParameterTypes;
|
2010-11-02 01:45:15 +00:00
|
|
|
|
|
|
|
LVFlags() : ConsiderGlobalVisibility(true),
|
2011-03-04 10:39:25 +00:00
|
|
|
ConsiderVisibilityAttributes(true),
|
|
|
|
ConsiderTemplateParameterTypes(true) {
|
2010-11-02 01:45:15 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 18:36:25 +00:00
|
|
|
/// \brief Returns a set of flags that is only useful for computing the
|
|
|
|
/// linkage, not the visibility, of a declaration.
|
|
|
|
static LVFlags CreateOnlyDeclLinkage() {
|
|
|
|
LVFlags F;
|
|
|
|
F.ConsiderGlobalVisibility = false;
|
|
|
|
F.ConsiderVisibilityAttributes = false;
|
2011-03-04 10:39:25 +00:00
|
|
|
F.ConsiderTemplateParameterTypes = false;
|
2010-12-06 18:36:25 +00:00
|
|
|
return F;
|
|
|
|
}
|
|
|
|
|
2010-11-02 01:45:15 +00:00
|
|
|
/// Returns a set of flags, otherwise based on these, which ignores
|
|
|
|
/// off all sources of visibility except template arguments.
|
|
|
|
LVFlags onlyTemplateVisibility() const {
|
|
|
|
LVFlags F = *this;
|
|
|
|
F.ConsiderGlobalVisibility = false;
|
|
|
|
F.ConsiderVisibilityAttributes = false;
|
2011-03-04 10:39:25 +00:00
|
|
|
F.ConsiderTemplateParameterTypes = false;
|
2010-11-02 01:45:15 +00:00
|
|
|
return F;
|
|
|
|
}
|
2010-12-06 18:50:56 +00:00
|
|
|
};
|
2010-11-05 19:56:37 +00:00
|
|
|
} // end anonymous namespace
|
2010-11-02 01:45:15 +00:00
|
|
|
|
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
|
|
|
/// \brief Get the most restrictive linkage for the types in the given
|
|
|
|
/// template parameter list.
|
2010-10-22 21:05:15 +00:00
|
|
|
static LVPair
|
|
|
|
getLVForTemplateParameterList(const TemplateParameterList *Params) {
|
|
|
|
LVPair LV(ExternalLinkage, DefaultVisibility);
|
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
|
|
|
for (TemplateParameterList::const_iterator P = Params->begin(),
|
|
|
|
PEnd = Params->end();
|
|
|
|
P != PEnd; ++P) {
|
2011-01-19 20:10:05 +00:00
|
|
|
if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
|
|
|
|
if (NTTP->isExpandedParameterPack()) {
|
|
|
|
for (unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) {
|
|
|
|
QualType T = NTTP->getExpansionType(I);
|
|
|
|
if (!T->isDependentType())
|
|
|
|
LV = merge(LV, T->getLinkageAndVisibility());
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if (!NTTP->getType()->isDependentType()) {
|
2010-10-22 21:05:15 +00:00
|
|
|
LV = merge(LV, NTTP->getType()->getLinkageAndVisibility());
|
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
|
|
|
continue;
|
|
|
|
}
|
2011-01-19 20:10:05 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
if (TemplateTemplateParmDecl *TTP
|
|
|
|
= dyn_cast<TemplateTemplateParmDecl>(*P)) {
|
2010-10-30 11:50:40 +00:00
|
|
|
LV = merge(LV, getLVForTemplateParameterList(TTP->getTemplateParameters()));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
return LV;
|
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
|
|
|
}
|
|
|
|
|
2010-12-06 18:36:25 +00:00
|
|
|
/// getLVForDecl - Get the linkage and visibility for the given declaration.
|
|
|
|
static LinkageInfo getLVForDecl(const NamedDecl *D, LVFlags F);
|
|
|
|
|
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
|
|
|
/// \brief Get the most restrictive linkage for the types and
|
|
|
|
/// declarations in the given template argument list.
|
2010-10-22 21:05:15 +00:00
|
|
|
static LVPair getLVForTemplateArgumentList(const TemplateArgument *Args,
|
2010-12-06 18:36:25 +00:00
|
|
|
unsigned NumArgs,
|
|
|
|
LVFlags &F) {
|
2010-10-22 21:05:15 +00:00
|
|
|
LVPair LV(ExternalLinkage, DefaultVisibility);
|
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
|
|
|
|
|
|
|
for (unsigned I = 0; I != NumArgs; ++I) {
|
|
|
|
switch (Args[I].getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
case TemplateArgument::Integral:
|
|
|
|
case TemplateArgument::Expression:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Type:
|
2010-10-22 21:05:15 +00:00
|
|
|
LV = merge(LV, Args[I].getAsType()->getLinkageAndVisibility());
|
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
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Declaration:
|
2010-10-22 21:05:15 +00:00
|
|
|
// The decl can validly be null as the representation of nullptr
|
|
|
|
// arguments, valid only in C++0x.
|
|
|
|
if (Decl *D = Args[I].getAsDecl()) {
|
2010-12-06 18:50:56 +00:00
|
|
|
if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
|
|
|
|
LV = merge(LV, getLVForDecl(ND, F));
|
2010-10-22 21:05:15 +00:00
|
|
|
}
|
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
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Template:
|
2011-01-05 18:58:31 +00:00
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
if (TemplateDecl *Template
|
|
|
|
= Args[I].getAsTemplateOrTemplatePattern().getAsTemplateDecl())
|
2010-12-06 18:50:56 +00:00
|
|
|
LV = merge(LV, getLVForDecl(Template, F));
|
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
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Pack:
|
2010-10-22 21:05:15 +00:00
|
|
|
LV = merge(LV, getLVForTemplateArgumentList(Args[I].pack_begin(),
|
2010-12-06 18:36:25 +00:00
|
|
|
Args[I].pack_size(),
|
|
|
|
F));
|
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
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
return LV;
|
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
|
|
|
}
|
|
|
|
|
2010-10-30 11:50:40 +00:00
|
|
|
static LVPair
|
2010-12-06 18:36:25 +00:00
|
|
|
getLVForTemplateArgumentList(const TemplateArgumentList &TArgs,
|
|
|
|
LVFlags &F) {
|
|
|
|
return getLVForTemplateArgumentList(TArgs.data(), TArgs.size(), F);
|
2010-08-13 08:35:10 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 01:45:15 +00:00
|
|
|
static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D, LVFlags F) {
|
2010-08-31 00:36:30 +00:00
|
|
|
assert(D->getDeclContext()->getRedeclContext()->isFileContext() &&
|
2009-11-25 22:24:25 +00:00
|
|
|
"Not a name having namespace scope");
|
|
|
|
ASTContext &Context = D->getASTContext();
|
|
|
|
|
|
|
|
// C++ [basic.link]p3:
|
|
|
|
// A name having namespace scope (3.3.6) has internal linkage if it
|
|
|
|
// is the name of
|
|
|
|
// - an object, reference, function or function template that is
|
|
|
|
// explicitly declared static; or,
|
|
|
|
// (This bullet corresponds to C99 6.2.2p3.)
|
|
|
|
if (const VarDecl *Var = dyn_cast<VarDecl>(D)) {
|
|
|
|
// Explicitly declared static.
|
2010-08-26 03:08:43 +00:00
|
|
|
if (Var->getStorageClass() == SC_Static)
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::internal();
|
2009-11-25 22:24:25 +00:00
|
|
|
|
|
|
|
// - an object or reference that is explicitly declared const
|
|
|
|
// and neither explicitly declared extern nor previously
|
|
|
|
// declared to have external linkage; or
|
|
|
|
// (there is no equivalent in C99)
|
|
|
|
if (Context.getLangOptions().CPlusPlus &&
|
2009-11-26 03:04:01 +00:00
|
|
|
Var->getType().isConstant(Context) &&
|
2010-08-26 03:08:43 +00:00
|
|
|
Var->getStorageClass() != SC_Extern &&
|
|
|
|
Var->getStorageClass() != SC_PrivateExtern) {
|
2009-11-25 22:24:25 +00:00
|
|
|
bool FoundExtern = false;
|
|
|
|
for (const VarDecl *PrevVar = Var->getPreviousDeclaration();
|
|
|
|
PrevVar && !FoundExtern;
|
|
|
|
PrevVar = PrevVar->getPreviousDeclaration())
|
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
|
|
|
if (isExternalLinkage(PrevVar->getLinkage()))
|
2009-11-25 22:24:25 +00:00
|
|
|
FoundExtern = true;
|
|
|
|
|
|
|
|
if (!FoundExtern)
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::internal();
|
2009-11-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
} else if (isa<FunctionDecl>(D) || isa<FunctionTemplateDecl>(D)) {
|
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
|
|
|
// C++ [temp]p4:
|
|
|
|
// A non-member function template can have internal linkage; any
|
|
|
|
// other template name shall have external linkage.
|
2009-11-25 22:24:25 +00:00
|
|
|
const FunctionDecl *Function = 0;
|
|
|
|
if (const FunctionTemplateDecl *FunTmpl
|
|
|
|
= dyn_cast<FunctionTemplateDecl>(D))
|
|
|
|
Function = FunTmpl->getTemplatedDecl();
|
|
|
|
else
|
|
|
|
Function = cast<FunctionDecl>(D);
|
|
|
|
|
|
|
|
// Explicitly declared static.
|
2010-08-26 03:08:43 +00:00
|
|
|
if (Function->getStorageClass() == SC_Static)
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo(InternalLinkage, DefaultVisibility, false);
|
2009-11-25 22:24:25 +00:00
|
|
|
} else if (const FieldDecl *Field = dyn_cast<FieldDecl>(D)) {
|
|
|
|
// - a data member of an anonymous union.
|
|
|
|
if (cast<RecordDecl>(Field->getDeclContext())->isAnonymousStructOrUnion())
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::internal();
|
2009-11-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 19:03:39 +00:00
|
|
|
if (D->isInAnonymousNamespace()) {
|
|
|
|
const VarDecl *Var = dyn_cast<VarDecl>(D);
|
|
|
|
const FunctionDecl *Func = dyn_cast<FunctionDecl>(D);
|
|
|
|
if ((!Var || !Var->isExternC()) && (!Func || !Func->isExternC()))
|
|
|
|
return LinkageInfo::uniqueExternal();
|
|
|
|
}
|
2010-10-28 04:18:25 +00:00
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
// Set up the defaults.
|
|
|
|
|
|
|
|
// C99 6.2.2p5:
|
|
|
|
// If the declaration of an identifier for an object has file
|
|
|
|
// scope and no storage-class specifier, its linkage is
|
|
|
|
// external.
|
2010-10-30 11:50:40 +00:00
|
|
|
LinkageInfo LV;
|
|
|
|
|
2010-11-02 01:45:15 +00:00
|
|
|
if (F.ConsiderVisibilityAttributes) {
|
2011-03-26 12:10:19 +00:00
|
|
|
if (llvm::Optional<Visibility> Vis = D->getExplicitVisibility()) {
|
|
|
|
LV.setVisibility(*Vis, true);
|
2010-11-02 01:45:15 +00:00
|
|
|
F.ConsiderGlobalVisibility = false;
|
2010-12-10 02:59:44 +00:00
|
|
|
} else {
|
|
|
|
// If we're declared in a namespace with a visibility attribute,
|
|
|
|
// use that namespace's visibility, but don't call it explicit.
|
|
|
|
for (const DeclContext *DC = D->getDeclContext();
|
|
|
|
!isa<TranslationUnitDecl>(DC);
|
|
|
|
DC = DC->getParent()) {
|
|
|
|
if (!isa<NamespaceDecl>(DC)) continue;
|
2011-03-26 12:10:19 +00:00
|
|
|
if (llvm::Optional<Visibility> Vis
|
|
|
|
= cast<NamespaceDecl>(DC)->getExplicitVisibility()) {
|
|
|
|
LV.setVisibility(*Vis, false);
|
2010-12-10 02:59:44 +00:00
|
|
|
F.ConsiderGlobalVisibility = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-11-02 01:45:15 +00:00
|
|
|
}
|
2010-10-30 11:50:40 +00:00
|
|
|
}
|
2010-10-22 21:05:15 +00:00
|
|
|
|
2009-11-25 22:24:25 +00:00
|
|
|
// C++ [basic.link]p4:
|
2010-10-22 21:05:15 +00:00
|
|
|
|
2009-11-25 22:24:25 +00:00
|
|
|
// A name having namespace scope has external linkage if it is the
|
|
|
|
// name of
|
|
|
|
//
|
|
|
|
// - an object or reference, unless it has internal linkage; or
|
|
|
|
if (const VarDecl *Var = dyn_cast<VarDecl>(D)) {
|
2010-10-29 22:22:43 +00:00
|
|
|
// GCC applies the following optimization to variables and static
|
|
|
|
// data members, but not to functions:
|
|
|
|
//
|
2010-10-22 21:05:15 +00:00
|
|
|
// Modify the variable's LV by the LV of its type unless this is
|
|
|
|
// C or extern "C". This follows from [basic.link]p9:
|
|
|
|
// A type without linkage shall not be used as the type of a
|
|
|
|
// variable or function with external linkage unless
|
|
|
|
// - the entity has C language linkage, or
|
|
|
|
// - the entity is declared within an unnamed namespace, or
|
|
|
|
// - the entity is not used or is defined in the same
|
|
|
|
// translation unit.
|
|
|
|
// and [basic.link]p10:
|
|
|
|
// ...the types specified by all declarations referring to a
|
|
|
|
// given variable or function shall be identical...
|
|
|
|
// C does not have an equivalent rule.
|
|
|
|
//
|
2010-10-26 04:59:26 +00:00
|
|
|
// Ignore this if we've got an explicit attribute; the user
|
|
|
|
// probably knows what they're doing.
|
|
|
|
//
|
2010-10-22 21:05:15 +00:00
|
|
|
// Note that we don't want to make the variable non-external
|
|
|
|
// because of this, but unique-external linkage suits us.
|
2010-10-30 09:18:49 +00:00
|
|
|
if (Context.getLangOptions().CPlusPlus && !Var->isExternC()) {
|
2010-10-22 21:05:15 +00:00
|
|
|
LVPair TypeLV = Var->getType()->getLinkageAndVisibility();
|
|
|
|
if (TypeLV.first != ExternalLinkage)
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::uniqueExternal();
|
|
|
|
if (!LV.visibilityExplicit())
|
|
|
|
LV.mergeVisibility(TypeLV.second);
|
2010-10-29 22:22:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 18:38:13 +00:00
|
|
|
if (Var->getStorageClass() == SC_PrivateExtern)
|
|
|
|
LV.setVisibility(HiddenVisibility, true);
|
|
|
|
|
2009-11-25 22:24:25 +00:00
|
|
|
if (!Context.getLangOptions().CPlusPlus &&
|
2010-08-26 03:08:43 +00:00
|
|
|
(Var->getStorageClass() == SC_Extern ||
|
|
|
|
Var->getStorageClass() == SC_PrivateExtern)) {
|
2010-10-22 21:05:15 +00:00
|
|
|
|
2009-11-25 22:24:25 +00:00
|
|
|
// C99 6.2.2p4:
|
|
|
|
// For an identifier declared with the storage-class specifier
|
|
|
|
// extern in a scope in which a prior declaration of that
|
|
|
|
// identifier is visible, if the prior declaration specifies
|
|
|
|
// internal or external linkage, the linkage of the identifier
|
|
|
|
// at the later declaration is the same as the linkage
|
|
|
|
// specified at the prior declaration. If no prior declaration
|
|
|
|
// is visible, or if the prior declaration specifies no
|
|
|
|
// linkage, then the identifier has external linkage.
|
|
|
|
if (const VarDecl *PrevVar = Var->getPreviousDeclaration()) {
|
2010-12-06 18:36:25 +00:00
|
|
|
LinkageInfo PrevLV = getLVForDecl(PrevVar, F);
|
2010-10-30 11:50:40 +00:00
|
|
|
if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage());
|
|
|
|
LV.mergeVisibility(PrevLV);
|
2009-11-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// - a function, unless it has internal linkage; or
|
2010-10-22 21:05:15 +00:00
|
|
|
} else if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
|
2010-10-28 07:07:52 +00:00
|
|
|
// In theory, we can modify the function's LV by the LV of its
|
|
|
|
// type unless it has C linkage (see comment above about variables
|
|
|
|
// for justification). In practice, GCC doesn't do this, so it's
|
|
|
|
// just too painful to make work.
|
2010-10-22 21:05:15 +00:00
|
|
|
|
2010-11-02 18:38:13 +00:00
|
|
|
if (Function->getStorageClass() == SC_PrivateExtern)
|
|
|
|
LV.setVisibility(HiddenVisibility, true);
|
|
|
|
|
2009-11-25 22:24:25 +00:00
|
|
|
// C99 6.2.2p5:
|
|
|
|
// If the declaration of an identifier for a function has no
|
|
|
|
// storage-class specifier, its linkage is determined exactly
|
|
|
|
// as if it were declared with the storage-class specifier
|
|
|
|
// extern.
|
|
|
|
if (!Context.getLangOptions().CPlusPlus &&
|
2010-08-26 03:08:43 +00:00
|
|
|
(Function->getStorageClass() == SC_Extern ||
|
|
|
|
Function->getStorageClass() == SC_PrivateExtern ||
|
|
|
|
Function->getStorageClass() == SC_None)) {
|
2009-11-25 22:24:25 +00:00
|
|
|
// C99 6.2.2p4:
|
|
|
|
// For an identifier declared with the storage-class specifier
|
|
|
|
// extern in a scope in which a prior declaration of that
|
|
|
|
// identifier is visible, if the prior declaration specifies
|
|
|
|
// internal or external linkage, the linkage of the identifier
|
|
|
|
// at the later declaration is the same as the linkage
|
|
|
|
// specified at the prior declaration. If no prior declaration
|
|
|
|
// is visible, or if the prior declaration specifies no
|
|
|
|
// linkage, then the identifier has external linkage.
|
|
|
|
if (const FunctionDecl *PrevFunc = Function->getPreviousDeclaration()) {
|
2010-12-06 18:36:25 +00:00
|
|
|
LinkageInfo PrevLV = getLVForDecl(PrevFunc, F);
|
2010-10-30 11:50:40 +00:00
|
|
|
if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage());
|
|
|
|
LV.mergeVisibility(PrevLV);
|
2009-11-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-10 06:50:24 +00:00
|
|
|
// In C++, then if the type of the function uses a type with
|
|
|
|
// unique-external linkage, it's not legally usable from outside
|
|
|
|
// this translation unit. However, we should use the C linkage
|
|
|
|
// rules instead for extern "C" declarations.
|
|
|
|
if (Context.getLangOptions().CPlusPlus && !Function->isExternC() &&
|
|
|
|
Function->getType()->getLinkage() == UniqueExternalLinkage)
|
|
|
|
return LinkageInfo::uniqueExternal();
|
|
|
|
|
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
|
|
|
if (FunctionTemplateSpecializationInfo *SpecInfo
|
|
|
|
= Function->getTemplateSpecializationInfo()) {
|
2010-11-02 01:45:15 +00:00
|
|
|
LV.merge(getLVForDecl(SpecInfo->getTemplate(),
|
|
|
|
F.onlyTemplateVisibility()));
|
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
|
|
|
const TemplateArgumentList &TemplateArgs = *SpecInfo->TemplateArguments;
|
2010-12-06 18:36:25 +00:00
|
|
|
LV.merge(getLVForTemplateArgumentList(TemplateArgs, F));
|
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
|
|
|
}
|
|
|
|
|
2009-11-25 22:24:25 +00:00
|
|
|
// - a named class (Clause 9), or an unnamed class defined in a
|
|
|
|
// typedef declaration in which the class has the typedef name
|
|
|
|
// for linkage purposes (7.1.3); or
|
|
|
|
// - a named enumeration (7.2), or an unnamed enumeration
|
|
|
|
// defined in a typedef declaration in which the enumeration
|
|
|
|
// has the typedef name for linkage purposes (7.1.3); or
|
2010-10-22 21:05:15 +00:00
|
|
|
} else if (const TagDecl *Tag = dyn_cast<TagDecl>(D)) {
|
|
|
|
// Unnamed tags have no linkage.
|
|
|
|
if (!Tag->getDeclName() && !Tag->getTypedefForAnonDecl())
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::none();
|
2010-10-22 21:05:15 +00:00
|
|
|
|
|
|
|
// If this is a class template specialization, consider the
|
|
|
|
// linkage of the template and template arguments.
|
|
|
|
if (const ClassTemplateSpecializationDecl *Spec
|
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(Tag)) {
|
2010-11-02 01:45:15 +00:00
|
|
|
// From the template.
|
|
|
|
LV.merge(getLVForDecl(Spec->getSpecializedTemplate(),
|
|
|
|
F.onlyTemplateVisibility()));
|
2010-10-22 21:05:15 +00:00
|
|
|
|
|
|
|
// The arguments at which the template was instantiated.
|
|
|
|
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
|
2010-12-06 18:36:25 +00:00
|
|
|
LV.merge(getLVForTemplateArgumentList(TemplateArgs, F));
|
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
|
|
|
}
|
2009-11-25 22:24:25 +00:00
|
|
|
|
2010-10-26 04:59:26 +00:00
|
|
|
// Consider -fvisibility unless the type has C linkage.
|
2010-11-02 01:45:15 +00:00
|
|
|
if (F.ConsiderGlobalVisibility)
|
|
|
|
F.ConsiderGlobalVisibility =
|
2010-10-26 04:59:26 +00:00
|
|
|
(Context.getLangOptions().CPlusPlus &&
|
|
|
|
!Tag->getDeclContext()->isExternCContext());
|
2010-10-22 21:05:15 +00:00
|
|
|
|
2009-11-25 22:24:25 +00:00
|
|
|
// - an enumerator belonging to an enumeration with external linkage;
|
2010-10-22 21:05:15 +00:00
|
|
|
} else if (isa<EnumConstantDecl>(D)) {
|
2010-12-06 18:36:25 +00:00
|
|
|
LinkageInfo EnumLV = getLVForDecl(cast<NamedDecl>(D->getDeclContext()), F);
|
2010-10-30 11:50:40 +00:00
|
|
|
if (!isExternalLinkage(EnumLV.linkage()))
|
|
|
|
return LinkageInfo::none();
|
|
|
|
LV.merge(EnumLV);
|
2009-11-25 22:24:25 +00:00
|
|
|
|
|
|
|
// - a template, unless it is a function template that has
|
|
|
|
// internal linkage (Clause 14);
|
2011-03-04 10:39:25 +00:00
|
|
|
} else if (const TemplateDecl *temp = dyn_cast<TemplateDecl>(D)) {
|
|
|
|
if (F.ConsiderTemplateParameterTypes)
|
|
|
|
LV.merge(getLVForTemplateParameterList(temp->getTemplateParameters()));
|
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
|
|
|
|
2009-11-25 22:24:25 +00:00
|
|
|
// - a namespace (7.3), unless it is declared within an unnamed
|
|
|
|
// namespace.
|
2010-10-22 21:05:15 +00:00
|
|
|
} else if (isa<NamespaceDecl>(D) && !D->isInAnonymousNamespace()) {
|
|
|
|
return LV;
|
|
|
|
|
|
|
|
// By extension, we assign external linkage to Objective-C
|
|
|
|
// interfaces.
|
|
|
|
} else if (isa<ObjCInterfaceDecl>(D)) {
|
|
|
|
// fallout
|
|
|
|
|
|
|
|
// Everything not covered here has no linkage.
|
|
|
|
} else {
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::none();
|
2010-10-22 21:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we ended up with non-external linkage, visibility should
|
|
|
|
// always be default.
|
2010-10-30 11:50:40 +00:00
|
|
|
if (LV.linkage() != ExternalLinkage)
|
|
|
|
return LinkageInfo(LV.linkage(), DefaultVisibility, false);
|
2010-10-22 21:05:15 +00:00
|
|
|
|
|
|
|
// If we didn't end up with hidden visibility, consider attributes
|
|
|
|
// and -fvisibility.
|
2010-11-02 01:45:15 +00:00
|
|
|
if (F.ConsiderGlobalVisibility)
|
2010-10-30 11:50:40 +00:00
|
|
|
LV.mergeVisibility(Context.getLangOptions().getVisibilityMode());
|
2009-11-25 22:24:25 +00:00
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
return LV;
|
2009-11-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 01:45:15 +00:00
|
|
|
static LinkageInfo getLVForClassMember(const NamedDecl *D, LVFlags F) {
|
2010-10-22 21:05:15 +00:00
|
|
|
// Only certain class members have linkage. Note that fields don't
|
|
|
|
// really have linkage, but it's convenient to say they do for the
|
|
|
|
// purposes of calculating linkage of pointer-to-data-member
|
|
|
|
// template arguments.
|
2010-08-13 08:35:10 +00:00
|
|
|
if (!(isa<CXXMethodDecl>(D) ||
|
|
|
|
isa<VarDecl>(D) ||
|
2010-10-22 21:05:15 +00:00
|
|
|
isa<FieldDecl>(D) ||
|
2010-08-13 08:35:10 +00:00
|
|
|
(isa<TagDecl>(D) &&
|
|
|
|
(D->getDeclName() || cast<TagDecl>(D)->getTypedefForAnonDecl()))))
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::none();
|
2010-08-13 08:35:10 +00:00
|
|
|
|
2010-11-02 01:45:15 +00:00
|
|
|
LinkageInfo LV;
|
|
|
|
|
|
|
|
// The flags we're going to use to compute the class's visibility.
|
|
|
|
LVFlags ClassF = F;
|
|
|
|
|
|
|
|
// If we have an explicit visibility attribute, merge that in.
|
|
|
|
if (F.ConsiderVisibilityAttributes) {
|
2011-03-26 12:10:19 +00:00
|
|
|
if (llvm::Optional<Visibility> Vis = D->getExplicitVisibility()) {
|
|
|
|
LV.mergeVisibility(*Vis, true);
|
2010-11-02 01:45:15 +00:00
|
|
|
|
|
|
|
// Ignore global visibility later, but not this attribute.
|
|
|
|
F.ConsiderGlobalVisibility = false;
|
|
|
|
|
|
|
|
// Ignore both global visibility and attributes when computing our
|
|
|
|
// parent's visibility.
|
|
|
|
ClassF = F.onlyTemplateVisibility();
|
|
|
|
}
|
|
|
|
}
|
2010-10-30 11:50:40 +00:00
|
|
|
|
|
|
|
// Class members only have linkage if their class has external
|
2010-11-02 01:45:15 +00:00
|
|
|
// linkage.
|
|
|
|
LV.merge(getLVForDecl(cast<RecordDecl>(D->getDeclContext()), ClassF));
|
|
|
|
if (!isExternalLinkage(LV.linkage()))
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::none();
|
2010-08-13 08:35:10 +00:00
|
|
|
|
|
|
|
// If the class already has unique-external linkage, we can't improve.
|
2010-11-02 01:45:15 +00:00
|
|
|
if (LV.linkage() == UniqueExternalLinkage)
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::uniqueExternal();
|
2010-10-22 21:05:15 +00:00
|
|
|
|
2010-08-13 08:35:10 +00:00
|
|
|
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
|
2011-02-10 06:50:24 +00:00
|
|
|
// If the type of the function uses a type with unique-external
|
|
|
|
// linkage, it's not legally usable from outside this translation unit.
|
|
|
|
if (MD->getType()->getLinkage() == UniqueExternalLinkage)
|
|
|
|
return LinkageInfo::uniqueExternal();
|
|
|
|
|
2010-10-29 22:22:43 +00:00
|
|
|
TemplateSpecializationKind TSK = TSK_Undeclared;
|
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
// If this is a method template specialization, use the linkage for
|
|
|
|
// the template parameters and arguments.
|
|
|
|
if (FunctionTemplateSpecializationInfo *Spec
|
2010-08-13 08:35:10 +00:00
|
|
|
= MD->getTemplateSpecializationInfo()) {
|
2010-12-06 18:36:25 +00:00
|
|
|
LV.merge(getLVForTemplateArgumentList(*Spec->TemplateArguments, F));
|
2011-03-04 10:39:25 +00:00
|
|
|
if (F.ConsiderTemplateParameterTypes)
|
|
|
|
LV.merge(getLVForTemplateParameterList(
|
2010-10-22 21:05:15 +00:00
|
|
|
Spec->getTemplate()->getTemplateParameters()));
|
2010-10-29 22:22:43 +00:00
|
|
|
|
|
|
|
TSK = Spec->getTemplateSpecializationKind();
|
|
|
|
} else if (MemberSpecializationInfo *MSI =
|
|
|
|
MD->getMemberSpecializationInfo()) {
|
|
|
|
TSK = MSI->getTemplateSpecializationKind();
|
2010-08-13 08:35:10 +00:00
|
|
|
}
|
|
|
|
|
2010-10-29 22:22:43 +00:00
|
|
|
// If we're paying attention to global visibility, apply
|
|
|
|
// -finline-visibility-hidden if this is an inline method.
|
|
|
|
//
|
2010-10-30 11:50:40 +00:00
|
|
|
// Note that ConsiderGlobalVisibility doesn't yet have information
|
|
|
|
// about whether containing classes have visibility attributes,
|
|
|
|
// and that's intentional.
|
|
|
|
if (TSK != TSK_ExplicitInstantiationDeclaration &&
|
2010-11-02 01:45:15 +00:00
|
|
|
F.ConsiderGlobalVisibility &&
|
2010-11-01 01:29:57 +00:00
|
|
|
MD->getASTContext().getLangOptions().InlineVisibilityHidden) {
|
|
|
|
// InlineVisibilityHidden only applies to definitions, and
|
|
|
|
// isInlined() only gives meaningful answers on definitions
|
|
|
|
// anyway.
|
|
|
|
const FunctionDecl *Def = 0;
|
|
|
|
if (MD->hasBody(Def) && Def->isInlined())
|
|
|
|
LV.setVisibility(HiddenVisibility);
|
|
|
|
}
|
2010-10-22 21:05:15 +00:00
|
|
|
|
2010-10-29 22:22:43 +00:00
|
|
|
// Note that in contrast to basically every other situation, we
|
|
|
|
// *do* apply -fvisibility to method declarations.
|
|
|
|
|
|
|
|
} else if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
|
|
|
|
if (const ClassTemplateSpecializationDecl *Spec
|
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
|
|
|
|
// Merge template argument/parameter information for member
|
|
|
|
// class template specializations.
|
2010-12-06 18:36:25 +00:00
|
|
|
LV.merge(getLVForTemplateArgumentList(Spec->getTemplateArgs(), F));
|
2011-03-04 10:39:25 +00:00
|
|
|
if (F.ConsiderTemplateParameterTypes)
|
|
|
|
LV.merge(getLVForTemplateParameterList(
|
2010-10-22 21:05:15 +00:00
|
|
|
Spec->getSpecializedTemplate()->getTemplateParameters()));
|
2010-10-29 22:22:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Static data members.
|
|
|
|
} else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
2010-10-30 09:18:49 +00:00
|
|
|
// Modify the variable's linkage by its type, but ignore the
|
|
|
|
// type's visibility unless it's a definition.
|
|
|
|
LVPair TypeLV = VD->getType()->getLinkageAndVisibility();
|
|
|
|
if (TypeLV.first != ExternalLinkage)
|
2010-10-30 11:50:40 +00:00
|
|
|
LV.mergeLinkage(UniqueExternalLinkage);
|
|
|
|
if (!LV.visibilityExplicit())
|
|
|
|
LV.mergeVisibility(TypeLV.second);
|
2010-10-29 22:22:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 01:45:15 +00:00
|
|
|
F.ConsiderGlobalVisibility &= !LV.visibilityExplicit();
|
2010-10-29 22:22:43 +00:00
|
|
|
|
|
|
|
// Apply -fvisibility if desired.
|
2010-11-02 01:45:15 +00:00
|
|
|
if (F.ConsiderGlobalVisibility && LV.visibility() != HiddenVisibility) {
|
2010-10-30 11:50:40 +00:00
|
|
|
LV.mergeVisibility(D->getASTContext().getLangOptions().getVisibilityMode());
|
2010-08-13 08:35:10 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
return LV;
|
2010-08-13 08:35:10 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 19:01:05 +00:00
|
|
|
static void clearLinkageForClass(const CXXRecordDecl *record) {
|
|
|
|
for (CXXRecordDecl::decl_iterator
|
|
|
|
i = record->decls_begin(), e = record->decls_end(); i != e; ++i) {
|
|
|
|
Decl *child = *i;
|
|
|
|
if (isa<NamedDecl>(child))
|
|
|
|
cast<NamedDecl>(child)->ClearLinkageCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NamedDecl::ClearLinkageCache() {
|
|
|
|
// Note that we can't skip clearing the linkage of children just
|
|
|
|
// because the parent doesn't have cached linkage: we don't cache
|
|
|
|
// when computing linkage for parent contexts.
|
|
|
|
|
|
|
|
HasCachedLinkage = 0;
|
|
|
|
|
|
|
|
// If we're changing the linkage of a class, we need to reset the
|
|
|
|
// linkage of child declarations, too.
|
|
|
|
if (const CXXRecordDecl *record = dyn_cast<CXXRecordDecl>(this))
|
|
|
|
clearLinkageForClass(record);
|
|
|
|
|
2011-02-19 02:53:41 +00:00
|
|
|
if (ClassTemplateDecl *temp =
|
|
|
|
dyn_cast<ClassTemplateDecl>(const_cast<NamedDecl*>(this))) {
|
2011-02-08 19:01:05 +00:00
|
|
|
// Clear linkage for the template pattern.
|
|
|
|
CXXRecordDecl *record = temp->getTemplatedDecl();
|
|
|
|
record->HasCachedLinkage = 0;
|
|
|
|
clearLinkageForClass(record);
|
|
|
|
|
2011-02-19 02:53:41 +00:00
|
|
|
// We need to clear linkage for specializations, too.
|
|
|
|
for (ClassTemplateDecl::spec_iterator
|
|
|
|
i = temp->spec_begin(), e = temp->spec_end(); i != e; ++i)
|
|
|
|
i->ClearLinkageCache();
|
2011-02-08 19:01:05 +00:00
|
|
|
}
|
2011-02-19 02:53:41 +00:00
|
|
|
|
|
|
|
// Clear cached linkage for function template decls, too.
|
|
|
|
if (FunctionTemplateDecl *temp =
|
2011-03-22 06:58:49 +00:00
|
|
|
dyn_cast<FunctionTemplateDecl>(const_cast<NamedDecl*>(this))) {
|
|
|
|
temp->getTemplatedDecl()->ClearLinkageCache();
|
2011-02-19 02:53:41 +00:00
|
|
|
for (FunctionTemplateDecl::spec_iterator
|
|
|
|
i = temp->spec_begin(), e = temp->spec_end(); i != e; ++i)
|
|
|
|
i->ClearLinkageCache();
|
2011-03-22 06:58:49 +00:00
|
|
|
}
|
2011-02-19 02:53:41 +00:00
|
|
|
|
2011-02-08 19:01:05 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 18:36:25 +00:00
|
|
|
Linkage NamedDecl::getLinkage() const {
|
|
|
|
if (HasCachedLinkage) {
|
2010-12-07 15:51:48 +00:00
|
|
|
assert(Linkage(CachedLinkage) ==
|
|
|
|
getLVForDecl(this, LVFlags::CreateOnlyDeclLinkage()).linkage());
|
2010-12-06 18:36:25 +00:00
|
|
|
return Linkage(CachedLinkage);
|
|
|
|
}
|
|
|
|
|
|
|
|
CachedLinkage = getLVForDecl(this,
|
|
|
|
LVFlags::CreateOnlyDeclLinkage()).linkage();
|
|
|
|
HasCachedLinkage = 1;
|
|
|
|
return Linkage(CachedLinkage);
|
|
|
|
}
|
|
|
|
|
2010-10-30 11:50:40 +00:00
|
|
|
LinkageInfo NamedDecl::getLinkageAndVisibility() const {
|
2010-12-06 18:36:25 +00:00
|
|
|
LinkageInfo LI = getLVForDecl(this, LVFlags());
|
2010-12-07 15:51:48 +00:00
|
|
|
assert(!HasCachedLinkage || Linkage(CachedLinkage) == LI.linkage());
|
2010-12-06 18:36:25 +00:00
|
|
|
HasCachedLinkage = 1;
|
|
|
|
CachedLinkage = LI.linkage();
|
|
|
|
return LI;
|
2010-10-29 00:29:13 +00:00
|
|
|
}
|
2010-04-20 23:15:35 +00:00
|
|
|
|
2011-03-26 12:10:19 +00:00
|
|
|
llvm::Optional<Visibility> NamedDecl::getExplicitVisibility() const {
|
|
|
|
// Use the most recent declaration of a variable.
|
|
|
|
if (const VarDecl *var = dyn_cast<VarDecl>(this))
|
|
|
|
return getVisibilityOf(var->getMostRecentDeclaration());
|
|
|
|
|
|
|
|
// Use the most recent declaration of a function, and also handle
|
|
|
|
// function template specializations.
|
|
|
|
if (const FunctionDecl *fn = dyn_cast<FunctionDecl>(this)) {
|
|
|
|
if (llvm::Optional<Visibility> V
|
|
|
|
= getVisibilityOf(fn->getMostRecentDeclaration()))
|
|
|
|
return V;
|
|
|
|
|
|
|
|
// If the function is a specialization of a template with an
|
|
|
|
// explicit visibility attribute, use that.
|
|
|
|
if (FunctionTemplateSpecializationInfo *templateInfo
|
|
|
|
= fn->getTemplateSpecializationInfo())
|
|
|
|
return getVisibilityOf(templateInfo->getTemplate()->getTemplatedDecl());
|
|
|
|
|
|
|
|
return llvm::Optional<Visibility>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, just check the declaration itself first.
|
|
|
|
if (llvm::Optional<Visibility> V = getVisibilityOf(this))
|
|
|
|
return V;
|
|
|
|
|
|
|
|
// If there wasn't explicit visibility there, and this is a
|
|
|
|
// specialization of a class template, check for visibility
|
|
|
|
// on the pattern.
|
|
|
|
if (const ClassTemplateSpecializationDecl *spec
|
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(this))
|
|
|
|
return getVisibilityOf(spec->getSpecializedTemplate()->getTemplatedDecl());
|
|
|
|
|
|
|
|
return llvm::Optional<Visibility>();
|
|
|
|
}
|
|
|
|
|
2010-11-02 01:45:15 +00:00
|
|
|
static LinkageInfo getLVForDecl(const NamedDecl *D, LVFlags Flags) {
|
2010-04-20 23:15:35 +00:00
|
|
|
// Objective-C: treat all Objective-C declarations as having external
|
|
|
|
// linkage.
|
2010-10-29 00:29:13 +00:00
|
|
|
switch (D->getKind()) {
|
2010-04-20 23:15:35 +00:00
|
|
|
default:
|
|
|
|
break;
|
2010-10-22 21:05:15 +00:00
|
|
|
case Decl::TemplateTemplateParm: // count these as external
|
|
|
|
case Decl::NonTypeTemplateParm:
|
2010-04-20 23:15:35 +00:00
|
|
|
case Decl::ObjCAtDefsField:
|
|
|
|
case Decl::ObjCCategory:
|
|
|
|
case Decl::ObjCCategoryImpl:
|
|
|
|
case Decl::ObjCCompatibleAlias:
|
|
|
|
case Decl::ObjCForwardProtocol:
|
|
|
|
case Decl::ObjCImplementation:
|
|
|
|
case Decl::ObjCMethod:
|
|
|
|
case Decl::ObjCProperty:
|
|
|
|
case Decl::ObjCPropertyImpl:
|
|
|
|
case Decl::ObjCProtocol:
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::external();
|
2010-04-20 23:15:35 +00:00
|
|
|
}
|
|
|
|
|
2009-11-25 22:24:25 +00:00
|
|
|
// Handle linkage for namespace-scope names.
|
2010-10-29 00:29:13 +00:00
|
|
|
if (D->getDeclContext()->getRedeclContext()->isFileContext())
|
2010-11-02 01:45:15 +00:00
|
|
|
return getLVForNamespaceScopeDecl(D, Flags);
|
2009-11-25 22:24:25 +00:00
|
|
|
|
|
|
|
// C++ [basic.link]p5:
|
|
|
|
// In addition, a member function, static data member, a named
|
|
|
|
// class or enumeration of class scope, or an unnamed class or
|
|
|
|
// enumeration defined in a class-scope typedef declaration such
|
|
|
|
// that the class or enumeration has the typedef name for linkage
|
|
|
|
// purposes (7.1.3), has external linkage if the name of the class
|
|
|
|
// has external linkage.
|
2010-10-29 00:29:13 +00:00
|
|
|
if (D->getDeclContext()->isRecord())
|
2010-11-02 01:45:15 +00:00
|
|
|
return getLVForClassMember(D, Flags);
|
2009-11-25 22:24:25 +00:00
|
|
|
|
|
|
|
// C++ [basic.link]p6:
|
|
|
|
// The name of a function declared in block scope and the name of
|
|
|
|
// an object declared by a block scope extern declaration have
|
|
|
|
// linkage. If there is a visible declaration of an entity with
|
|
|
|
// linkage having the same name and type, ignoring entities
|
|
|
|
// declared outside the innermost enclosing namespace scope, the
|
|
|
|
// block scope declaration declares that same entity and receives
|
|
|
|
// the linkage of the previous declaration. If there is more than
|
|
|
|
// one such matching entity, the program is ill-formed. Otherwise,
|
|
|
|
// if no matching entity is found, the block scope entity receives
|
|
|
|
// external linkage.
|
2010-10-29 00:29:13 +00:00
|
|
|
if (D->getLexicalDeclContext()->isFunctionOrMethod()) {
|
|
|
|
if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
|
2011-02-25 00:05:02 +00:00
|
|
|
if (Function->isInAnonymousNamespace() && !Function->isExternC())
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::uniqueExternal();
|
2010-10-22 21:05:15 +00:00
|
|
|
|
2010-10-30 11:50:40 +00:00
|
|
|
LinkageInfo LV;
|
2010-12-06 18:36:25 +00:00
|
|
|
if (Flags.ConsiderVisibilityAttributes) {
|
2011-03-26 12:10:19 +00:00
|
|
|
if (llvm::Optional<Visibility> Vis = Function->getExplicitVisibility())
|
|
|
|
LV.setVisibility(*Vis);
|
2010-12-06 18:36:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
if (const FunctionDecl *Prev = Function->getPreviousDeclaration()) {
|
2010-12-06 18:36:25 +00:00
|
|
|
LinkageInfo PrevLV = getLVForDecl(Prev, Flags);
|
2010-10-30 11:50:40 +00:00
|
|
|
if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage());
|
|
|
|
LV.mergeVisibility(PrevLV);
|
2010-10-22 21:05:15 +00:00
|
|
|
}
|
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
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
return LV;
|
2009-11-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-29 00:29:13 +00:00
|
|
|
if (const VarDecl *Var = dyn_cast<VarDecl>(D))
|
2010-08-26 03:08:43 +00:00
|
|
|
if (Var->getStorageClass() == SC_Extern ||
|
|
|
|
Var->getStorageClass() == SC_PrivateExtern) {
|
2011-02-25 00:05:02 +00:00
|
|
|
if (Var->isInAnonymousNamespace() && !Var->isExternC())
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::uniqueExternal();
|
2010-10-22 21:05:15 +00:00
|
|
|
|
2010-10-30 11:50:40 +00:00
|
|
|
LinkageInfo LV;
|
2010-10-22 21:05:15 +00:00
|
|
|
if (Var->getStorageClass() == SC_PrivateExtern)
|
2010-10-30 11:50:40 +00:00
|
|
|
LV.setVisibility(HiddenVisibility);
|
2010-12-06 18:36:25 +00:00
|
|
|
else if (Flags.ConsiderVisibilityAttributes) {
|
2011-03-26 12:10:19 +00:00
|
|
|
if (llvm::Optional<Visibility> Vis = Var->getExplicitVisibility())
|
|
|
|
LV.setVisibility(*Vis);
|
2010-12-06 18:36:25 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 21:05:15 +00:00
|
|
|
if (const VarDecl *Prev = Var->getPreviousDeclaration()) {
|
2010-12-06 18:36:25 +00:00
|
|
|
LinkageInfo PrevLV = getLVForDecl(Prev, Flags);
|
2010-10-30 11:50:40 +00:00
|
|
|
if (PrevLV.linkage()) LV.setLinkage(PrevLV.linkage());
|
|
|
|
LV.mergeVisibility(PrevLV);
|
2010-10-22 21:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return LV;
|
2009-11-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// C++ [basic.link]p6:
|
|
|
|
// Names not covered by these rules have no linkage.
|
2010-10-30 11:50:40 +00:00
|
|
|
return LinkageInfo::none();
|
2010-10-22 21:05:15 +00:00
|
|
|
}
|
2009-11-25 22:24:25 +00:00
|
|
|
|
2009-02-04 17:27:36 +00:00
|
|
|
std::string NamedDecl::getQualifiedNameAsString() const {
|
2009-09-08 18:24:21 +00:00
|
|
|
return getQualifiedNameAsString(getASTContext().getLangOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const {
|
2009-02-04 17:27:36 +00:00
|
|
|
const DeclContext *Ctx = getDeclContext();
|
|
|
|
|
|
|
|
if (Ctx->isFunctionOrMethod())
|
|
|
|
return getNameAsString();
|
|
|
|
|
2010-04-28 14:33:51 +00:00
|
|
|
typedef llvm::SmallVector<const DeclContext *, 8> ContextsTy;
|
|
|
|
ContextsTy Contexts;
|
|
|
|
|
|
|
|
// Collect contexts.
|
|
|
|
while (Ctx && isa<NamedDecl>(Ctx)) {
|
|
|
|
Contexts.push_back(Ctx);
|
|
|
|
Ctx = Ctx->getParent();
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string QualName;
|
|
|
|
llvm::raw_string_ostream OS(QualName);
|
|
|
|
|
|
|
|
for (ContextsTy::reverse_iterator I = Contexts.rbegin(), E = Contexts.rend();
|
|
|
|
I != E; ++I) {
|
2009-09-09 15:08:12 +00:00
|
|
|
if (const ClassTemplateSpecializationDecl *Spec
|
2010-04-28 14:33:51 +00:00
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(*I)) {
|
2009-05-18 17:01:57 +00:00
|
|
|
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
|
|
|
|
std::string TemplateArgsStr
|
|
|
|
= TemplateSpecializationType::PrintTemplateArgumentList(
|
2010-11-07 23:05:16 +00:00
|
|
|
TemplateArgs.data(),
|
|
|
|
TemplateArgs.size(),
|
2009-09-08 18:24:21 +00:00
|
|
|
P);
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << Spec->getName() << TemplateArgsStr;
|
|
|
|
} else if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(*I)) {
|
2009-12-24 23:15:03 +00:00
|
|
|
if (ND->isAnonymousNamespace())
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << "<anonymous namespace>";
|
2009-12-24 23:15:03 +00:00
|
|
|
else
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << ND;
|
|
|
|
} else if (const RecordDecl *RD = dyn_cast<RecordDecl>(*I)) {
|
|
|
|
if (!RD->getIdentifier())
|
|
|
|
OS << "<anonymous " << RD->getKindName() << '>';
|
|
|
|
else
|
|
|
|
OS << RD;
|
|
|
|
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*I)) {
|
2009-12-28 03:19:38 +00:00
|
|
|
const FunctionProtoType *FT = 0;
|
|
|
|
if (FD->hasWrittenPrototype())
|
|
|
|
FT = dyn_cast<FunctionProtoType>(FD->getType()->getAs<FunctionType>());
|
|
|
|
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << FD << '(';
|
2009-12-28 03:19:38 +00:00
|
|
|
if (FT) {
|
|
|
|
unsigned NumParams = FD->getNumParams();
|
|
|
|
for (unsigned i = 0; i < NumParams; ++i) {
|
|
|
|
if (i)
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << ", ";
|
2009-12-28 03:19:38 +00:00
|
|
|
std::string Param;
|
|
|
|
FD->getParamDecl(i)->getType().getAsStringInternal(Param, P);
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << Param;
|
2009-12-28 03:19:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FT->isVariadic()) {
|
|
|
|
if (NumParams > 0)
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << ", ";
|
|
|
|
OS << "...";
|
2009-12-28 03:19:38 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << ')';
|
|
|
|
} else {
|
|
|
|
OS << cast<NamedDecl>(*I);
|
|
|
|
}
|
|
|
|
OS << "::";
|
2009-02-04 17:27:36 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 21:48:18 +00:00
|
|
|
if (getDeclName())
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << this;
|
2010-03-16 21:48:18 +00:00
|
|
|
else
|
2010-04-28 14:33:51 +00:00
|
|
|
OS << "<anonymous>";
|
2009-02-04 17:27:36 +00:00
|
|
|
|
2010-04-28 14:33:51 +00:00
|
|
|
return OS.str();
|
2009-02-04 17:27:36 +00:00
|
|
|
}
|
|
|
|
|
2009-01-20 01:17:11 +00:00
|
|
|
bool NamedDecl::declarationReplaces(NamedDecl *OldD) const {
|
2008-12-23 21:05:05 +00:00
|
|
|
assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch");
|
|
|
|
|
2009-02-03 19:21:40 +00:00
|
|
|
// UsingDirectiveDecl's are not really NamedDecl's, and all have same name.
|
|
|
|
// We want to keep it, unless it nominates same namespace.
|
|
|
|
if (getKind() == Decl::UsingDirective) {
|
2011-02-25 16:33:46 +00:00
|
|
|
return cast<UsingDirectiveDecl>(this)->getNominatedNamespace()
|
|
|
|
->getOriginalNamespace() ==
|
|
|
|
cast<UsingDirectiveDecl>(OldD)->getNominatedNamespace()
|
|
|
|
->getOriginalNamespace();
|
2009-02-03 19:21:40 +00:00
|
|
|
}
|
2009-09-09 15:08:12 +00:00
|
|
|
|
2008-12-23 21:05:05 +00:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(this))
|
|
|
|
// For function declarations, we keep track of redeclarations.
|
|
|
|
return FD->getPreviousDeclaration() == OldD;
|
|
|
|
|
2009-06-25 22:08:12 +00:00
|
|
|
// For function templates, the underlying function declarations are linked.
|
|
|
|
if (const FunctionTemplateDecl *FunctionTemplate
|
|
|
|
= dyn_cast<FunctionTemplateDecl>(this))
|
|
|
|
if (const FunctionTemplateDecl *OldFunctionTemplate
|
|
|
|
= dyn_cast<FunctionTemplateDecl>(OldD))
|
|
|
|
return FunctionTemplate->getTemplatedDecl()
|
|
|
|
->declarationReplaces(OldFunctionTemplate->getTemplatedDecl());
|
2009-09-09 15:08:12 +00:00
|
|
|
|
2009-02-22 19:35:57 +00:00
|
|
|
// For method declarations, we keep track of redeclarations.
|
|
|
|
if (isa<ObjCMethodDecl>(this))
|
|
|
|
return false;
|
2009-09-09 15:08:12 +00:00
|
|
|
|
2009-10-09 21:13:30 +00:00
|
|
|
if (isa<ObjCInterfaceDecl>(this) && isa<ObjCCompatibleAliasDecl>(OldD))
|
|
|
|
return true;
|
|
|
|
|
2009-11-17 05:59:44 +00:00
|
|
|
if (isa<UsingShadowDecl>(this) && isa<UsingShadowDecl>(OldD))
|
|
|
|
return cast<UsingShadowDecl>(this)->getTargetDecl() ==
|
|
|
|
cast<UsingShadowDecl>(OldD)->getTargetDecl();
|
|
|
|
|
2011-02-25 00:36:19 +00:00
|
|
|
if (isa<UsingDecl>(this) && isa<UsingDecl>(OldD)) {
|
|
|
|
ASTContext &Context = getASTContext();
|
|
|
|
return Context.getCanonicalNestedNameSpecifier(
|
|
|
|
cast<UsingDecl>(this)->getQualifier()) ==
|
|
|
|
Context.getCanonicalNestedNameSpecifier(
|
|
|
|
cast<UsingDecl>(OldD)->getQualifier());
|
|
|
|
}
|
2010-11-04 08:48:52 +00:00
|
|
|
|
2008-12-23 21:05:05 +00:00
|
|
|
// For non-function declarations, if the declarations are of the
|
|
|
|
// same kind then this must be a redeclaration, or semantic analysis
|
|
|
|
// would not have given us the new declaration.
|
|
|
|
return this->getKind() == OldD->getKind();
|
|
|
|
}
|
|
|
|
|
2009-02-24 20:03:32 +00:00
|
|
|
bool NamedDecl::hasLinkage() const {
|
2009-11-25 22:24:25 +00:00
|
|
|
return getLinkage() != NoLinkage;
|
2009-02-24 20:03:32 +00:00
|
|
|
}
|
2009-01-20 01:17:11 +00:00
|
|
|
|
2009-06-26 06:29:23 +00:00
|
|
|
NamedDecl *NamedDecl::getUnderlyingDecl() {
|
|
|
|
NamedDecl *ND = this;
|
|
|
|
while (true) {
|
2009-11-17 05:59:44 +00:00
|
|
|
if (UsingShadowDecl *UD = dyn_cast<UsingShadowDecl>(ND))
|
2009-06-26 06:29:23 +00:00
|
|
|
ND = UD->getTargetDecl();
|
|
|
|
else if (ObjCCompatibleAliasDecl *AD
|
|
|
|
= dyn_cast<ObjCCompatibleAliasDecl>(ND))
|
|
|
|
return AD->getClassInterface();
|
|
|
|
else
|
|
|
|
return ND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 21:38:20 +00:00
|
|
|
bool NamedDecl::isCXXInstanceMember() const {
|
|
|
|
assert(isCXXClassMember() &&
|
|
|
|
"checking whether non-member is instance member");
|
|
|
|
|
|
|
|
const NamedDecl *D = this;
|
|
|
|
if (isa<UsingShadowDecl>(D))
|
|
|
|
D = cast<UsingShadowDecl>(D)->getTargetDecl();
|
|
|
|
|
2010-11-21 06:08:52 +00:00
|
|
|
if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D))
|
2010-04-06 21:38:20 +00:00
|
|
|
return true;
|
|
|
|
if (isa<CXXMethodDecl>(D))
|
|
|
|
return cast<CXXMethodDecl>(D)->isInstance();
|
|
|
|
if (isa<FunctionTemplateDecl>(D))
|
|
|
|
return cast<CXXMethodDecl>(cast<FunctionTemplateDecl>(D)
|
|
|
|
->getTemplatedDecl())->isInstance();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-21 00:31:54 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DeclaratorDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-07-06 18:42:40 +00:00
|
|
|
template <typename DeclT>
|
|
|
|
static SourceLocation getTemplateOrInnerLocStart(const DeclT *decl) {
|
|
|
|
if (decl->getNumTemplateParameterLists() > 0)
|
|
|
|
return decl->getTemplateParameterList(0)->getTemplateLoc();
|
|
|
|
else
|
|
|
|
return decl->getInnerLocStart();
|
|
|
|
}
|
|
|
|
|
2009-08-21 00:31:54 +00:00
|
|
|
SourceLocation DeclaratorDecl::getTypeSpecStartLoc() const {
|
2010-05-28 23:32:21 +00:00
|
|
|
TypeSourceInfo *TSI = getTypeSourceInfo();
|
|
|
|
if (TSI) return TSI->getTypeLoc().getBeginLoc();
|
2009-08-21 00:31:54 +00:00
|
|
|
return SourceLocation();
|
|
|
|
}
|
|
|
|
|
2011-02-25 02:25:35 +00:00
|
|
|
void DeclaratorDecl::setQualifierInfo(NestedNameSpecifierLoc QualifierLoc) {
|
|
|
|
if (QualifierLoc) {
|
2010-03-15 10:12:16 +00:00
|
|
|
// Make sure the extended decl info is allocated.
|
|
|
|
if (!hasExtInfo()) {
|
|
|
|
// Save (non-extended) type source info pointer.
|
|
|
|
TypeSourceInfo *savedTInfo = DeclInfo.get<TypeSourceInfo*>();
|
|
|
|
// Allocate external info struct.
|
|
|
|
DeclInfo = new (getASTContext()) ExtInfo;
|
|
|
|
// Restore savedTInfo into (extended) decl info.
|
|
|
|
getExtInfo()->TInfo = savedTInfo;
|
|
|
|
}
|
|
|
|
// Set qualifier info.
|
2011-02-25 02:25:35 +00:00
|
|
|
getExtInfo()->QualifierLoc = QualifierLoc;
|
2010-03-15 10:12:16 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Here Qualifier == 0, i.e., we are removing the qualifier (if any).
|
|
|
|
if (hasExtInfo()) {
|
2011-03-18 15:16:37 +00:00
|
|
|
if (getExtInfo()->NumTemplParamLists == 0) {
|
|
|
|
// Save type source info pointer.
|
|
|
|
TypeSourceInfo *savedTInfo = getExtInfo()->TInfo;
|
|
|
|
// Deallocate the extended decl info.
|
|
|
|
getASTContext().Deallocate(getExtInfo());
|
|
|
|
// Restore savedTInfo into (non-extended) decl info.
|
|
|
|
DeclInfo = savedTInfo;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
getExtInfo()->QualifierLoc = QualifierLoc;
|
2010-03-15 10:12:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 15:16:37 +00:00
|
|
|
void
|
|
|
|
DeclaratorDecl::setTemplateParameterListsInfo(ASTContext &Context,
|
|
|
|
unsigned NumTPLists,
|
|
|
|
TemplateParameterList **TPLists) {
|
|
|
|
assert(NumTPLists > 0);
|
|
|
|
// Make sure the extended decl info is allocated.
|
|
|
|
if (!hasExtInfo()) {
|
|
|
|
// Save (non-extended) type source info pointer.
|
|
|
|
TypeSourceInfo *savedTInfo = DeclInfo.get<TypeSourceInfo*>();
|
|
|
|
// Allocate external info struct.
|
|
|
|
DeclInfo = new (getASTContext()) ExtInfo;
|
|
|
|
// Restore savedTInfo into (extended) decl info.
|
|
|
|
getExtInfo()->TInfo = savedTInfo;
|
|
|
|
}
|
|
|
|
// Set the template parameter lists info.
|
|
|
|
getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists);
|
|
|
|
}
|
|
|
|
|
2010-07-06 18:42:40 +00:00
|
|
|
SourceLocation DeclaratorDecl::getOuterLocStart() const {
|
|
|
|
return getTemplateOrInnerLocStart(this);
|
|
|
|
}
|
|
|
|
|
2011-03-08 16:41:52 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Helper function: returns true if QT is or contains a type
|
|
|
|
// having a postfix component.
|
|
|
|
bool typeIsPostfix(clang::QualType QT) {
|
|
|
|
while (true) {
|
|
|
|
const Type* T = QT.getTypePtr();
|
|
|
|
switch (T->getTypeClass()) {
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
case Type::Pointer:
|
|
|
|
QT = cast<PointerType>(T)->getPointeeType();
|
|
|
|
break;
|
|
|
|
case Type::BlockPointer:
|
|
|
|
QT = cast<BlockPointerType>(T)->getPointeeType();
|
|
|
|
break;
|
|
|
|
case Type::MemberPointer:
|
|
|
|
QT = cast<MemberPointerType>(T)->getPointeeType();
|
|
|
|
break;
|
|
|
|
case Type::LValueReference:
|
|
|
|
case Type::RValueReference:
|
|
|
|
QT = cast<ReferenceType>(T)->getPointeeType();
|
|
|
|
break;
|
|
|
|
case Type::PackExpansion:
|
|
|
|
QT = cast<PackExpansionType>(T)->getPattern();
|
|
|
|
break;
|
|
|
|
case Type::Paren:
|
|
|
|
case Type::ConstantArray:
|
|
|
|
case Type::DependentSizedArray:
|
|
|
|
case Type::IncompleteArray:
|
|
|
|
case Type::VariableArray:
|
|
|
|
case Type::FunctionProto:
|
|
|
|
case Type::FunctionNoProto:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
SourceRange DeclaratorDecl::getSourceRange() const {
|
|
|
|
SourceLocation RangeEnd = getLocation();
|
|
|
|
if (TypeSourceInfo *TInfo = getTypeSourceInfo()) {
|
|
|
|
if (typeIsPostfix(TInfo->getType()))
|
|
|
|
RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
|
|
|
|
}
|
|
|
|
return SourceRange(getOuterLocStart(), RangeEnd);
|
|
|
|
}
|
|
|
|
|
2010-06-12 08:15:14 +00:00
|
|
|
void
|
2010-06-15 17:44:38 +00:00
|
|
|
QualifierInfo::setTemplateParameterListsInfo(ASTContext &Context,
|
|
|
|
unsigned NumTPLists,
|
2010-06-12 08:15:14 +00:00
|
|
|
TemplateParameterList **TPLists) {
|
|
|
|
assert((NumTPLists == 0 || TPLists != 0) &&
|
|
|
|
"Empty array of template parameters with positive size!");
|
|
|
|
|
|
|
|
// Free previous template parameters (if any).
|
|
|
|
if (NumTemplParamLists > 0) {
|
2010-06-15 17:44:38 +00:00
|
|
|
Context.Deallocate(TemplParamLists);
|
2010-06-12 08:15:14 +00:00
|
|
|
TemplParamLists = 0;
|
|
|
|
NumTemplParamLists = 0;
|
|
|
|
}
|
|
|
|
// Set info on matched template parameter lists (if any).
|
|
|
|
if (NumTPLists > 0) {
|
2010-06-15 17:44:38 +00:00
|
|
|
TemplParamLists = new (Context) TemplateParameterList*[NumTPLists];
|
2010-06-12 08:15:14 +00:00
|
|
|
NumTemplParamLists = NumTPLists;
|
|
|
|
for (unsigned i = NumTPLists; i-- > 0; )
|
|
|
|
TemplParamLists[i] = TPLists[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-17 23:39:55 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VarDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
const char *VarDecl::getStorageClassSpecifierString(StorageClass SC) {
|
|
|
|
switch (SC) {
|
2010-08-26 03:08:43 +00:00
|
|
|
case SC_None: break;
|
|
|
|
case SC_Auto: return "auto"; break;
|
|
|
|
case SC_Extern: return "extern"; break;
|
|
|
|
case SC_PrivateExtern: return "__private_extern__"; break;
|
|
|
|
case SC_Register: return "register"; break;
|
|
|
|
case SC_Static: return "static"; break;
|
2010-01-26 22:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(0 && "Invalid storage class");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-08 08:55:46 +00:00
|
|
|
VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation StartL, SourceLocation IdL,
|
2009-12-07 02:54:59 +00:00
|
|
|
IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
|
2010-04-19 22:54:31 +00:00
|
|
|
StorageClass S, StorageClass SCAsWritten) {
|
2011-03-08 08:55:46 +00:00
|
|
|
return new (C) VarDecl(Var, DC, StartL, IdL, Id, T, TInfo, S, SCAsWritten);
|
2008-12-17 23:39:55 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 18:36:25 +00:00
|
|
|
void VarDecl::setStorageClass(StorageClass SC) {
|
|
|
|
assert(isLegalForVariable(SC));
|
|
|
|
if (getStorageClass() != SC)
|
|
|
|
ClearLinkageCache();
|
|
|
|
|
|
|
|
SClass = SC;
|
|
|
|
}
|
|
|
|
|
2010-07-06 18:42:40 +00:00
|
|
|
SourceRange VarDecl::getSourceRange() const {
|
2009-06-20 08:09:14 +00:00
|
|
|
if (getInit())
|
2010-07-06 18:42:40 +00:00
|
|
|
return SourceRange(getOuterLocStart(), getInit()->getLocEnd());
|
2011-03-08 16:41:52 +00:00
|
|
|
return DeclaratorDecl::getSourceRange();
|
2009-06-20 08:09:14 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
bool VarDecl::isExternC() const {
|
|
|
|
ASTContext &Context = getASTContext();
|
|
|
|
if (!Context.getLangOptions().CPlusPlus)
|
|
|
|
return (getDeclContext()->isTranslationUnit() &&
|
2010-08-26 03:08:43 +00:00
|
|
|
getStorageClass() != SC_Static) ||
|
2010-01-26 22:01:41 +00:00
|
|
|
(getDeclContext()->isFunctionOrMethod() && hasExternalStorage());
|
|
|
|
|
2011-02-25 00:05:02 +00:00
|
|
|
const DeclContext *DC = getDeclContext();
|
|
|
|
if (DC->isFunctionOrMethod())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (; !DC->isTranslationUnit(); DC = DC->getParent()) {
|
2010-01-26 22:01:41 +00:00
|
|
|
if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) {
|
|
|
|
if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
|
2010-08-26 03:08:43 +00:00
|
|
|
return getStorageClass() != SC_Static;
|
2010-01-26 22:01:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *VarDecl::getCanonicalDecl() {
|
|
|
|
return getFirstDeclaration();
|
|
|
|
}
|
|
|
|
|
2010-01-31 22:27:38 +00:00
|
|
|
VarDecl::DefinitionKind VarDecl::isThisDeclarationADefinition() const {
|
|
|
|
// C++ [basic.def]p2:
|
|
|
|
// A declaration is a definition unless [...] it contains the 'extern'
|
|
|
|
// specifier or a linkage-specification and neither an initializer [...],
|
|
|
|
// it declares a static data member in a class declaration [...].
|
|
|
|
// C++ [temp.expl.spec]p15:
|
|
|
|
// An explicit specialization of a static data member of a template is a
|
|
|
|
// definition if the declaration includes an initializer; otherwise, it is
|
|
|
|
// a declaration.
|
|
|
|
if (isStaticDataMember()) {
|
|
|
|
if (isOutOfLine() && (hasInit() ||
|
|
|
|
getTemplateSpecializationKind() != TSK_ExplicitSpecialization))
|
|
|
|
return Definition;
|
|
|
|
else
|
|
|
|
return DeclarationOnly;
|
|
|
|
}
|
|
|
|
// C99 6.7p5:
|
|
|
|
// A definition of an identifier is a declaration for that identifier that
|
|
|
|
// [...] causes storage to be reserved for that object.
|
|
|
|
// Note: that applies for all non-file-scope objects.
|
|
|
|
// C99 6.9.2p1:
|
|
|
|
// If the declaration of an identifier for an object has file scope and an
|
|
|
|
// initializer, the declaration is an external definition for the identifier
|
|
|
|
if (hasInit())
|
|
|
|
return Definition;
|
|
|
|
// AST for 'extern "C" int foo;' is annotated with 'extern'.
|
|
|
|
if (hasExternalStorage())
|
|
|
|
return DeclarationOnly;
|
2010-06-21 16:08:37 +00:00
|
|
|
|
2010-08-26 03:08:43 +00:00
|
|
|
if (getStorageClassAsWritten() == SC_Extern ||
|
|
|
|
getStorageClassAsWritten() == SC_PrivateExtern) {
|
2010-06-21 16:08:37 +00:00
|
|
|
for (const VarDecl *PrevVar = getPreviousDeclaration();
|
|
|
|
PrevVar; PrevVar = PrevVar->getPreviousDeclaration()) {
|
|
|
|
if (PrevVar->getLinkage() == InternalLinkage && PrevVar->hasInit())
|
|
|
|
return DeclarationOnly;
|
|
|
|
}
|
|
|
|
}
|
2010-01-31 22:27:38 +00:00
|
|
|
// C99 6.9.2p2:
|
|
|
|
// A declaration of an object that has file scope without an initializer,
|
|
|
|
// and without a storage class specifier or the scs 'static', constitutes
|
|
|
|
// a tentative definition.
|
|
|
|
// No such thing in C++.
|
|
|
|
if (!getASTContext().getLangOptions().CPlusPlus && isFileVarDecl())
|
|
|
|
return TentativeDefinition;
|
|
|
|
|
|
|
|
// What's left is (in C, block-scope) declarations without initializers or
|
|
|
|
// external storage. These are definitions.
|
|
|
|
return Definition;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *VarDecl::getActingDefinition() {
|
|
|
|
DefinitionKind Kind = isThisDeclarationADefinition();
|
|
|
|
if (Kind != TentativeDefinition)
|
|
|
|
return 0;
|
|
|
|
|
2010-06-14 18:31:46 +00:00
|
|
|
VarDecl *LastTentative = 0;
|
2010-01-31 22:27:38 +00:00
|
|
|
VarDecl *First = getFirstDeclaration();
|
|
|
|
for (redecl_iterator I = First->redecls_begin(), E = First->redecls_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
Kind = (*I)->isThisDeclarationADefinition();
|
|
|
|
if (Kind == Definition)
|
|
|
|
return 0;
|
|
|
|
else if (Kind == TentativeDefinition)
|
|
|
|
LastTentative = *I;
|
|
|
|
}
|
|
|
|
return LastTentative;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VarDecl::isTentativeDefinitionNow() const {
|
|
|
|
DefinitionKind Kind = isThisDeclarationADefinition();
|
|
|
|
if (Kind != TentativeDefinition)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) {
|
|
|
|
if ((*I)->isThisDeclarationADefinition() == Definition)
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-01 20:16:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *VarDecl::getDefinition() {
|
2010-02-02 17:55:12 +00:00
|
|
|
VarDecl *First = getFirstDeclaration();
|
|
|
|
for (redecl_iterator I = First->redecls_begin(), E = First->redecls_end();
|
|
|
|
I != E; ++I) {
|
2010-02-01 20:16:42 +00:00
|
|
|
if ((*I)->isThisDeclarationADefinition() == Definition)
|
|
|
|
return *I;
|
|
|
|
}
|
|
|
|
return 0;
|
2010-01-31 22:27:38 +00:00
|
|
|
}
|
|
|
|
|
2010-10-29 22:22:43 +00:00
|
|
|
VarDecl::DefinitionKind VarDecl::hasDefinition() const {
|
|
|
|
DefinitionKind Kind = DeclarationOnly;
|
|
|
|
|
|
|
|
const VarDecl *First = getFirstDeclaration();
|
|
|
|
for (redecl_iterator I = First->redecls_begin(), E = First->redecls_end();
|
|
|
|
I != E; ++I)
|
|
|
|
Kind = std::max(Kind, (*I)->isThisDeclarationADefinition());
|
|
|
|
|
|
|
|
return Kind;
|
|
|
|
}
|
|
|
|
|
2010-02-01 20:16:42 +00:00
|
|
|
const Expr *VarDecl::getAnyInitializer(const VarDecl *&D) const {
|
2010-01-26 22:01:41 +00:00
|
|
|
redecl_iterator I = redecls_begin(), E = redecls_end();
|
|
|
|
while (I != E && !I->getInit())
|
|
|
|
++I;
|
|
|
|
|
|
|
|
if (I != E) {
|
2010-02-01 20:16:42 +00:00
|
|
|
D = *I;
|
2010-01-26 22:01:41 +00:00
|
|
|
return I->getInit();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-14 21:29:40 +00:00
|
|
|
bool VarDecl::isOutOfLine() const {
|
2011-02-19 18:51:44 +00:00
|
|
|
if (Decl::isOutOfLine())
|
2009-10-14 21:29:40 +00:00
|
|
|
return true;
|
2010-02-21 07:08:09 +00:00
|
|
|
|
|
|
|
if (!isStaticDataMember())
|
|
|
|
return false;
|
|
|
|
|
2009-10-14 21:29:40 +00:00
|
|
|
// If this static data member was instantiated from a static data member of
|
|
|
|
// a class template, check whether that static data member was defined
|
|
|
|
// out-of-line.
|
|
|
|
if (VarDecl *VD = getInstantiatedFromStaticDataMember())
|
|
|
|
return VD->isOutOfLine();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-27 18:42:08 +00:00
|
|
|
VarDecl *VarDecl::getOutOfLineDefinition() {
|
|
|
|
if (!isStaticDataMember())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (VarDecl::redecl_iterator RD = redecls_begin(), RDEnd = redecls_end();
|
|
|
|
RD != RDEnd; ++RD) {
|
|
|
|
if (RD->getLexicalDeclContext()->isFileContext())
|
|
|
|
return *RD;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-11 01:19:42 +00:00
|
|
|
void VarDecl::setInit(Expr *I) {
|
2010-01-26 22:01:41 +00:00
|
|
|
if (EvaluatedStmt *Eval = Init.dyn_cast<EvaluatedStmt *>()) {
|
|
|
|
Eval->~EvaluatedStmt();
|
2010-02-11 01:19:42 +00:00
|
|
|
getASTContext().Deallocate(Eval);
|
2010-01-26 22:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Init = I;
|
|
|
|
}
|
|
|
|
|
2009-10-14 21:29:40 +00:00
|
|
|
VarDecl *VarDecl::getInstantiatedFromStaticDataMember() const {
|
2009-10-12 20:18:28 +00:00
|
|
|
if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo())
|
2009-10-08 07:24:58 +00:00
|
|
|
return cast<VarDecl>(MSI->getInstantiatedFrom());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-14 20:14:33 +00:00
|
|
|
TemplateSpecializationKind VarDecl::getTemplateSpecializationKind() const {
|
2010-01-31 22:27:38 +00:00
|
|
|
if (MemberSpecializationInfo *MSI = getMemberSpecializationInfo())
|
2009-10-08 07:24:58 +00:00
|
|
|
return MSI->getTemplateSpecializationKind();
|
|
|
|
|
|
|
|
return TSK_Undeclared;
|
|
|
|
}
|
|
|
|
|
2009-10-14 21:29:40 +00:00
|
|
|
MemberSpecializationInfo *VarDecl::getMemberSpecializationInfo() const {
|
2009-10-12 20:18:28 +00:00
|
|
|
return getASTContext().getInstantiatedFromStaticDataMember(this);
|
|
|
|
}
|
|
|
|
|
2009-10-15 17:21:20 +00:00
|
|
|
void VarDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK,
|
|
|
|
SourceLocation PointOfInstantiation) {
|
2009-10-12 20:18:28 +00:00
|
|
|
MemberSpecializationInfo *MSI = getMemberSpecializationInfo();
|
2009-10-08 07:24:58 +00:00
|
|
|
assert(MSI && "Not an instantiated static data member?");
|
|
|
|
MSI->setTemplateSpecializationKind(TSK);
|
2009-10-15 17:21:20 +00:00
|
|
|
if (TSK != TSK_ExplicitSpecialization &&
|
|
|
|
PointOfInstantiation.isValid() &&
|
|
|
|
MSI->getPointOfInstantiation().isInvalid())
|
|
|
|
MSI->setPointOfInstantiation(PointOfInstantiation);
|
2009-07-24 20:34:43 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ParmVarDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-03-10 23:43:53 +00:00
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
|
2011-03-08 08:55:46 +00:00
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc, IdentifierInfo *Id,
|
2010-01-26 22:01:41 +00:00
|
|
|
QualType T, TypeSourceInfo *TInfo,
|
2010-04-19 22:54:31 +00:00
|
|
|
StorageClass S, StorageClass SCAsWritten,
|
|
|
|
Expr *DefArg) {
|
2011-03-08 08:55:46 +00:00
|
|
|
return new (C) ParmVarDecl(ParmVar, DC, StartLoc, IdLoc, Id, T, TInfo,
|
2010-04-19 22:54:31 +00:00
|
|
|
S, SCAsWritten, DefArg);
|
2009-03-10 23:43:53 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
Expr *ParmVarDecl::getDefaultArg() {
|
|
|
|
assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!");
|
|
|
|
assert(!hasUninstantiatedDefaultArg() &&
|
|
|
|
"Default argument is not yet instantiated!");
|
|
|
|
|
|
|
|
Expr *Arg = getInit();
|
2010-12-06 08:20:24 +00:00
|
|
|
if (ExprWithCleanups *E = dyn_cast_or_null<ExprWithCleanups>(Arg))
|
2010-01-26 22:01:41 +00:00
|
|
|
return E->getSubExpr();
|
|
|
|
|
|
|
|
return Arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ParmVarDecl::getNumDefaultArgTemporaries() const {
|
2010-12-06 08:20:24 +00:00
|
|
|
if (const ExprWithCleanups *E = dyn_cast<ExprWithCleanups>(getInit()))
|
2010-01-26 22:01:41 +00:00
|
|
|
return E->getNumTemporaries();
|
2009-03-10 23:43:53 +00:00
|
|
|
|
2009-07-14 03:20:21 +00:00
|
|
|
return 0;
|
2009-03-10 23:43:53 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
CXXTemporary *ParmVarDecl::getDefaultArgTemporary(unsigned i) {
|
|
|
|
assert(getNumDefaultArgTemporaries() &&
|
|
|
|
"Default arguments does not have any temporaries!");
|
|
|
|
|
2010-12-06 08:20:24 +00:00
|
|
|
ExprWithCleanups *E = cast<ExprWithCleanups>(getInit());
|
2010-01-26 22:01:41 +00:00
|
|
|
return E->getTemporary(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceRange ParmVarDecl::getDefaultArgRange() const {
|
|
|
|
if (const Expr *E = getInit())
|
|
|
|
return E->getSourceRange();
|
|
|
|
|
|
|
|
if (hasUninstantiatedDefaultArg())
|
|
|
|
return getUninstantiatedDefaultArg()->getSourceRange();
|
|
|
|
|
|
|
|
return SourceRange();
|
2009-07-05 22:21:56 +00:00
|
|
|
}
|
|
|
|
|
2011-01-05 21:11:38 +00:00
|
|
|
bool ParmVarDecl::isParameterPack() const {
|
|
|
|
return isa<PackExpansionType>(getType());
|
|
|
|
}
|
|
|
|
|
2008-11-09 23:41:00 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-03-31 00:36:02 +00:00
|
|
|
// FunctionDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-19 18:51:44 +00:00
|
|
|
void FunctionDecl::getNameForDiagnostic(std::string &S,
|
|
|
|
const PrintingPolicy &Policy,
|
|
|
|
bool Qualified) const {
|
|
|
|
NamedDecl::getNameForDiagnostic(S, Policy, Qualified);
|
|
|
|
const TemplateArgumentList *TemplateArgs = getTemplateSpecializationArgs();
|
|
|
|
if (TemplateArgs)
|
|
|
|
S += TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
TemplateArgs->data(),
|
|
|
|
TemplateArgs->size(),
|
|
|
|
Policy);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-04-29 16:49:01 +00:00
|
|
|
bool FunctionDecl::isVariadic() const {
|
|
|
|
if (const FunctionProtoType *FT = getType()->getAs<FunctionProtoType>())
|
|
|
|
return FT->isVariadic();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-07 11:31:19 +00:00
|
|
|
bool FunctionDecl::hasBody(const FunctionDecl *&Definition) const {
|
|
|
|
for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) {
|
|
|
|
if (I->Body) {
|
|
|
|
Definition = *I;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-30 02:35:26 +00:00
|
|
|
Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
|
2009-07-14 03:20:21 +00:00
|
|
|
for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) {
|
|
|
|
if (I->Body) {
|
|
|
|
Definition = *I;
|
|
|
|
return I->Body.get(getASTContext().getExternalSource());
|
2008-04-21 02:02:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-01-21 07:42:07 +00:00
|
|
|
}
|
|
|
|
|
2009-06-20 08:09:14 +00:00
|
|
|
void FunctionDecl::setBody(Stmt *B) {
|
|
|
|
Body = B;
|
2010-12-06 17:49:01 +00:00
|
|
|
if (B)
|
2009-06-20 08:09:14 +00:00
|
|
|
EndRangeLoc = B->getLocEnd();
|
|
|
|
}
|
|
|
|
|
2010-09-28 21:55:22 +00:00
|
|
|
void FunctionDecl::setPure(bool P) {
|
|
|
|
IsPure = P;
|
|
|
|
if (P)
|
|
|
|
if (CXXRecordDecl *Parent = dyn_cast<CXXRecordDecl>(getDeclContext()))
|
|
|
|
Parent->markedVirtualFunctionPure();
|
|
|
|
}
|
|
|
|
|
2009-09-12 00:17:51 +00:00
|
|
|
bool FunctionDecl::isMain() const {
|
|
|
|
ASTContext &Context = getASTContext();
|
2009-08-15 02:09:25 +00:00
|
|
|
return !Context.getLangOptions().Freestanding &&
|
2010-08-31 00:36:30 +00:00
|
|
|
getDeclContext()->getRedeclContext()->isTranslationUnit() &&
|
2009-02-24 01:23:02 +00:00
|
|
|
getIdentifier() && getIdentifier()->isStr("main");
|
|
|
|
}
|
|
|
|
|
2009-09-12 00:17:51 +00:00
|
|
|
bool FunctionDecl::isExternC() const {
|
|
|
|
ASTContext &Context = getASTContext();
|
2009-03-02 00:19:53 +00:00
|
|
|
// In C, any non-static, non-overloadable function has external
|
|
|
|
// linkage.
|
|
|
|
if (!Context.getLangOptions().CPlusPlus)
|
2010-08-26 03:08:43 +00:00
|
|
|
return getStorageClass() != SC_Static && !getAttr<OverloadableAttr>();
|
2009-03-02 00:19:53 +00:00
|
|
|
|
2011-02-25 00:05:02 +00:00
|
|
|
const DeclContext *DC = getDeclContext();
|
|
|
|
if (DC->isRecord())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (; !DC->isTranslationUnit(); DC = DC->getParent()) {
|
2009-03-02 00:19:53 +00:00
|
|
|
if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) {
|
|
|
|
if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
|
2010-08-26 03:08:43 +00:00
|
|
|
return getStorageClass() != SC_Static &&
|
2009-06-30 02:34:44 +00:00
|
|
|
!getAttr<OverloadableAttr>();
|
2009-03-02 00:19:53 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-21 16:57:46 +00:00
|
|
|
return isMain();
|
2009-03-02 00:19:53 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 16:35:03 +00:00
|
|
|
bool FunctionDecl::isGlobal() const {
|
|
|
|
if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(this))
|
|
|
|
return Method->isStatic();
|
|
|
|
|
2010-08-26 03:08:43 +00:00
|
|
|
if (getStorageClass() == SC_Static)
|
2009-03-31 16:35:03 +00:00
|
|
|
return false;
|
|
|
|
|
2009-09-09 15:08:12 +00:00
|
|
|
for (const DeclContext *DC = getDeclContext();
|
2009-03-31 16:35:03 +00:00
|
|
|
DC->isNamespace();
|
|
|
|
DC = DC->getParent()) {
|
|
|
|
if (const NamespaceDecl *Namespace = cast<NamespaceDecl>(DC)) {
|
|
|
|
if (!Namespace->getDeclName())
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
void
|
|
|
|
FunctionDecl::setPreviousDeclaration(FunctionDecl *PrevDecl) {
|
|
|
|
redeclarable_base::setPreviousDeclaration(PrevDecl);
|
|
|
|
|
|
|
|
if (FunctionTemplateDecl *FunTmpl = getDescribedFunctionTemplate()) {
|
|
|
|
FunctionTemplateDecl *PrevFunTmpl
|
|
|
|
= PrevDecl? PrevDecl->getDescribedFunctionTemplate() : 0;
|
|
|
|
assert((!PrevDecl || PrevFunTmpl) && "Function/function template mismatch");
|
|
|
|
FunTmpl->setPreviousDeclaration(PrevFunTmpl);
|
|
|
|
}
|
2010-12-09 16:59:22 +00:00
|
|
|
|
|
|
|
if (PrevDecl->IsInline)
|
|
|
|
IsInline = true;
|
2010-01-26 22:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const FunctionDecl *FunctionDecl::getCanonicalDecl() const {
|
|
|
|
return getFirstDeclaration();
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionDecl *FunctionDecl::getCanonicalDecl() {
|
|
|
|
return getFirstDeclaration();
|
|
|
|
}
|
|
|
|
|
2010-12-06 18:36:25 +00:00
|
|
|
void FunctionDecl::setStorageClass(StorageClass SC) {
|
|
|
|
assert(isLegalForFunction(SC));
|
|
|
|
if (getStorageClass() != SC)
|
|
|
|
ClearLinkageCache();
|
|
|
|
|
|
|
|
SClass = SC;
|
|
|
|
}
|
|
|
|
|
Implicitly declare certain C library functions (malloc, strcpy, memmove,
etc.) when we perform name lookup on them. This ensures that we
produce the correct signature for these functions, which has two
practical impacts:
1) When we're supporting the "implicit function declaration" feature
of C99, these functions will be implicitly declared with the right
signature rather than as a function returning "int" with no
prototype. See PR3541 for the reason why this is important (hint:
GCC always predeclares these functions).
2) If users attempt to redeclare one of these library functions with
an incompatible signature, we produce a hard error.
This patch does a little bit of work to give reasonable error
messages. For example, when we hit case #1 we complain that we're
implicitly declaring this function with a specific signature, and then
we give a note that asks the user to include the appropriate header
(e.g., "please include <stdlib.h> or explicitly declare 'malloc'"). In
case #2, we show the type of the implicit builtin that was incorrectly
declared, so the user can see the problem. We could do better here:
for example, when displaying this latter error message we say
something like:
'strcpy' was implicitly declared here with type 'char *(char *, char
const *)'
but we should really print out a fake code line showing the
declaration, like this:
'strcpy' was implicitly declared here as:
char *strcpy(char *, char const *)
This would also be good for printing built-in candidates with C++
operator overloading.
The set of C library functions supported by this patch includes all
functions from the C99 specification's <stdlib.h> and <string.h> that
(a) are predefined by GCC and (b) have signatures that could cause
codegen issues if they are treated as functions with no prototype
returning and int. Future work could extend this set of functions to
other C library functions that we know about.
llvm-svn: 64504
2009-02-13 23:20:09 +00:00
|
|
|
/// \brief Returns a value indicating whether this function
|
|
|
|
/// corresponds to a builtin function.
|
|
|
|
///
|
|
|
|
/// The function corresponds to a built-in function if it is
|
|
|
|
/// declared at translation scope or within an extern "C" block and
|
|
|
|
/// its name matches with the name of a builtin. The returned value
|
|
|
|
/// will be 0 for functions that do not correspond to a builtin, a
|
2009-09-09 15:08:12 +00:00
|
|
|
/// value of type \c Builtin::ID if in the target-independent range
|
Implicitly declare certain C library functions (malloc, strcpy, memmove,
etc.) when we perform name lookup on them. This ensures that we
produce the correct signature for these functions, which has two
practical impacts:
1) When we're supporting the "implicit function declaration" feature
of C99, these functions will be implicitly declared with the right
signature rather than as a function returning "int" with no
prototype. See PR3541 for the reason why this is important (hint:
GCC always predeclares these functions).
2) If users attempt to redeclare one of these library functions with
an incompatible signature, we produce a hard error.
This patch does a little bit of work to give reasonable error
messages. For example, when we hit case #1 we complain that we're
implicitly declaring this function with a specific signature, and then
we give a note that asks the user to include the appropriate header
(e.g., "please include <stdlib.h> or explicitly declare 'malloc'"). In
case #2, we show the type of the implicit builtin that was incorrectly
declared, so the user can see the problem. We could do better here:
for example, when displaying this latter error message we say
something like:
'strcpy' was implicitly declared here with type 'char *(char *, char
const *)'
but we should really print out a fake code line showing the
declaration, like this:
'strcpy' was implicitly declared here as:
char *strcpy(char *, char const *)
This would also be good for printing built-in candidates with C++
operator overloading.
The set of C library functions supported by this patch includes all
functions from the C99 specification's <stdlib.h> and <string.h> that
(a) are predefined by GCC and (b) have signatures that could cause
codegen issues if they are treated as functions with no prototype
returning and int. Future work could extend this set of functions to
other C library functions that we know about.
llvm-svn: 64504
2009-02-13 23:20:09 +00:00
|
|
|
/// \c [1,Builtin::First), or a target-specific builtin value.
|
2009-09-12 00:22:50 +00:00
|
|
|
unsigned FunctionDecl::getBuiltinID() const {
|
|
|
|
ASTContext &Context = getASTContext();
|
2009-02-14 18:57:46 +00:00
|
|
|
if (!getIdentifier() || !getIdentifier()->getBuiltinID())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unsigned BuiltinID = getIdentifier()->getBuiltinID();
|
|
|
|
if (!Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
|
|
|
|
return BuiltinID;
|
|
|
|
|
|
|
|
// This function has the name of a known C library
|
|
|
|
// function. Determine whether it actually refers to the C library
|
|
|
|
// function or whether it just has the same name.
|
|
|
|
|
2009-02-17 03:23:10 +00:00
|
|
|
// If this is a static function, it's not a builtin.
|
2010-08-26 03:08:43 +00:00
|
|
|
if (getStorageClass() == SC_Static)
|
2009-02-17 03:23:10 +00:00
|
|
|
return 0;
|
|
|
|
|
2009-02-14 18:57:46 +00:00
|
|
|
// If this function is at translation-unit scope and we're not in
|
|
|
|
// C++, it refers to the C library function.
|
|
|
|
if (!Context.getLangOptions().CPlusPlus &&
|
|
|
|
getDeclContext()->isTranslationUnit())
|
|
|
|
return BuiltinID;
|
|
|
|
|
|
|
|
// If the function is in an extern "C" linkage specification and is
|
|
|
|
// not marked "overloadable", it's the real function.
|
|
|
|
if (isa<LinkageSpecDecl>(getDeclContext()) &&
|
2009-09-09 15:08:12 +00:00
|
|
|
cast<LinkageSpecDecl>(getDeclContext())->getLanguage()
|
2009-02-14 18:57:46 +00:00
|
|
|
== LinkageSpecDecl::lang_c &&
|
2009-06-30 02:34:44 +00:00
|
|
|
!getAttr<OverloadableAttr>())
|
2009-02-14 18:57:46 +00:00
|
|
|
return BuiltinID;
|
|
|
|
|
|
|
|
// Not a builtin
|
Implicitly declare certain C library functions (malloc, strcpy, memmove,
etc.) when we perform name lookup on them. This ensures that we
produce the correct signature for these functions, which has two
practical impacts:
1) When we're supporting the "implicit function declaration" feature
of C99, these functions will be implicitly declared with the right
signature rather than as a function returning "int" with no
prototype. See PR3541 for the reason why this is important (hint:
GCC always predeclares these functions).
2) If users attempt to redeclare one of these library functions with
an incompatible signature, we produce a hard error.
This patch does a little bit of work to give reasonable error
messages. For example, when we hit case #1 we complain that we're
implicitly declaring this function with a specific signature, and then
we give a note that asks the user to include the appropriate header
(e.g., "please include <stdlib.h> or explicitly declare 'malloc'"). In
case #2, we show the type of the implicit builtin that was incorrectly
declared, so the user can see the problem. We could do better here:
for example, when displaying this latter error message we say
something like:
'strcpy' was implicitly declared here with type 'char *(char *, char
const *)'
but we should really print out a fake code line showing the
declaration, like this:
'strcpy' was implicitly declared here as:
char *strcpy(char *, char const *)
This would also be good for printing built-in candidates with C++
operator overloading.
The set of C library functions supported by this patch includes all
functions from the C99 specification's <stdlib.h> and <string.h> that
(a) are predefined by GCC and (b) have signatures that could cause
codegen issues if they are treated as functions with no prototype
returning and int. Future work could extend this set of functions to
other C library functions that we know about.
llvm-svn: 64504
2009-02-13 23:20:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-25 06:03:53 +00:00
|
|
|
/// getNumParams - Return the number of parameters this function must have
|
2011-01-10 18:23:55 +00:00
|
|
|
/// based on its FunctionType. This is the length of the ParamInfo array
|
2009-04-25 06:03:53 +00:00
|
|
|
/// after it has been created.
|
|
|
|
unsigned FunctionDecl::getNumParams() const {
|
2009-09-21 23:43:11 +00:00
|
|
|
const FunctionType *FT = getType()->getAs<FunctionType>();
|
2009-02-26 23:50:07 +00:00
|
|
|
if (isa<FunctionNoProtoType>(FT))
|
2008-03-15 05:43:15 +00:00
|
|
|
return 0;
|
2009-02-26 23:50:07 +00:00
|
|
|
return cast<FunctionProtoType>(FT)->getNumArgs();
|
2009-09-09 15:08:12 +00:00
|
|
|
|
2007-01-21 07:42:07 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 19:31:22 +00:00
|
|
|
void FunctionDecl::setParams(ASTContext &C,
|
|
|
|
ParmVarDecl **NewParamInfo, unsigned NumParams) {
|
2007-01-21 07:42:07 +00:00
|
|
|
assert(ParamInfo == 0 && "Already has param info!");
|
2009-04-25 06:12:16 +00:00
|
|
|
assert(NumParams == getNumParams() && "Parameter count mismatch!");
|
2009-09-09 15:08:12 +00:00
|
|
|
|
2007-01-21 19:04:10 +00:00
|
|
|
// Zero params -> null pointer.
|
|
|
|
if (NumParams) {
|
2010-09-08 19:31:22 +00:00
|
|
|
void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams);
|
2009-01-14 00:42:25 +00:00
|
|
|
ParamInfo = new (Mem) ParmVarDecl*[NumParams];
|
2007-06-13 20:44:40 +00:00
|
|
|
memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
|
2009-06-20 08:09:14 +00:00
|
|
|
|
2009-06-23 00:42:00 +00:00
|
|
|
// Update source range. The check below allows us to set EndRangeLoc before
|
|
|
|
// setting the parameters.
|
2009-06-23 00:42:15 +00:00
|
|
|
if (EndRangeLoc.isInvalid() || EndRangeLoc == getLocation())
|
2009-06-20 08:09:14 +00:00
|
|
|
EndRangeLoc = NewParamInfo[NumParams-1]->getLocEnd();
|
2007-01-21 19:04:10 +00:00
|
|
|
}
|
2007-01-21 07:42:07 +00:00
|
|
|
}
|
2007-01-25 04:52:46 +00:00
|
|
|
|
2008-04-10 02:22:51 +00:00
|
|
|
/// getMinRequiredArguments - Returns the minimum number of arguments
|
|
|
|
/// needed to call this function. This may be fewer than the number of
|
|
|
|
/// function parameters, if some of the parameters have default
|
2011-01-06 22:09:01 +00:00
|
|
|
/// arguments (in C++) or the last parameter is a parameter pack.
|
2008-04-10 02:22:51 +00:00
|
|
|
unsigned FunctionDecl::getMinRequiredArguments() const {
|
2011-01-11 01:52:23 +00:00
|
|
|
if (!getASTContext().getLangOptions().CPlusPlus)
|
|
|
|
return getNumParams();
|
|
|
|
|
2011-01-06 22:09:01 +00:00
|
|
|
unsigned NumRequiredArgs = getNumParams();
|
|
|
|
|
|
|
|
// If the last parameter is a parameter pack, we don't need an argument for
|
|
|
|
// it.
|
|
|
|
if (NumRequiredArgs > 0 &&
|
|
|
|
getParamDecl(NumRequiredArgs - 1)->isParameterPack())
|
|
|
|
--NumRequiredArgs;
|
|
|
|
|
|
|
|
// If this parameter has a default argument, we don't need an argument for
|
|
|
|
// it.
|
|
|
|
while (NumRequiredArgs > 0 &&
|
|
|
|
getParamDecl(NumRequiredArgs-1)->hasDefaultArg())
|
2008-04-10 02:22:51 +00:00
|
|
|
--NumRequiredArgs;
|
|
|
|
|
2011-01-11 01:52:23 +00:00
|
|
|
// We might have parameter packs before the end. These can't be deduced,
|
|
|
|
// but they can still handle multiple arguments.
|
|
|
|
unsigned ArgIdx = NumRequiredArgs;
|
|
|
|
while (ArgIdx > 0) {
|
|
|
|
if (getParamDecl(ArgIdx - 1)->isParameterPack())
|
|
|
|
NumRequiredArgs = ArgIdx;
|
|
|
|
|
|
|
|
--ArgIdx;
|
|
|
|
}
|
|
|
|
|
2008-04-10 02:22:51 +00:00
|
|
|
return NumRequiredArgs;
|
|
|
|
}
|
|
|
|
|
2009-10-27 21:11:48 +00:00
|
|
|
bool FunctionDecl::isInlined() const {
|
2010-12-09 16:59:22 +00:00
|
|
|
if (IsInline)
|
2009-10-27 23:26:40 +00:00
|
|
|
return true;
|
2009-12-04 22:35:50 +00:00
|
|
|
|
|
|
|
if (isa<CXXMethodDecl>(this)) {
|
|
|
|
if (!isOutOfLine() || getCanonicalDecl()->isInlineSpecified())
|
|
|
|
return true;
|
|
|
|
}
|
2009-10-27 23:26:40 +00:00
|
|
|
|
|
|
|
switch (getTemplateSpecializationKind()) {
|
|
|
|
case TSK_Undeclared:
|
|
|
|
case TSK_ExplicitSpecialization:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TSK_ImplicitInstantiation:
|
|
|
|
case TSK_ExplicitInstantiationDeclaration:
|
|
|
|
case TSK_ExplicitInstantiationDefinition:
|
|
|
|
// Handle below.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FunctionDecl *PatternDecl = getTemplateInstantiationPattern();
|
2010-07-07 11:31:19 +00:00
|
|
|
bool HasPattern = false;
|
2009-10-27 23:26:40 +00:00
|
|
|
if (PatternDecl)
|
2010-07-07 11:31:19 +00:00
|
|
|
HasPattern = PatternDecl->hasBody(PatternDecl);
|
2009-10-27 23:26:40 +00:00
|
|
|
|
2010-07-07 11:31:19 +00:00
|
|
|
if (HasPattern && PatternDecl)
|
2009-10-27 23:26:40 +00:00
|
|
|
return PatternDecl->isInlined();
|
|
|
|
|
|
|
|
return false;
|
2009-10-27 21:11:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 23:26:40 +00:00
|
|
|
/// \brief For an inline function definition in C or C++, determine whether the
|
2009-09-13 07:46:26 +00:00
|
|
|
/// definition will be externally visible.
|
|
|
|
///
|
|
|
|
/// Inline function definitions are always available for inlining optimizations.
|
|
|
|
/// However, depending on the language dialect, declaration specifiers, and
|
|
|
|
/// attributes, the definition of an inline function may or may not be
|
|
|
|
/// "externally" visible to other translation units in the program.
|
|
|
|
///
|
|
|
|
/// In C99, inline definitions are not externally visible by default. However,
|
2010-01-06 02:05:39 +00:00
|
|
|
/// if even one of the global-scope declarations is marked "extern inline", the
|
2009-09-13 07:46:26 +00:00
|
|
|
/// inline definition becomes externally visible (C99 6.7.4p6).
|
|
|
|
///
|
|
|
|
/// In GNU89 mode, or if the gnu_inline attribute is attached to the function
|
|
|
|
/// definition, we use the GNU semantics for inline, which are nearly the
|
|
|
|
/// opposite of C99 semantics. In particular, "inline" by itself will create
|
|
|
|
/// an externally visible symbol, but "extern inline" will not create an
|
|
|
|
/// externally visible symbol.
|
|
|
|
bool FunctionDecl::isInlineDefinitionExternallyVisible() const {
|
|
|
|
assert(isThisDeclarationADefinition() && "Must have the function definition");
|
2009-10-27 21:11:48 +00:00
|
|
|
assert(isInlined() && "Function must be inline");
|
2009-10-27 23:26:40 +00:00
|
|
|
ASTContext &Context = getASTContext();
|
2009-09-13 07:46:26 +00:00
|
|
|
|
2009-10-27 23:26:40 +00:00
|
|
|
if (!Context.getLangOptions().C99 || hasAttr<GNUInlineAttr>()) {
|
2010-12-09 16:59:22 +00:00
|
|
|
// If it's not the case that both 'inline' and 'extern' are
|
|
|
|
// specified on the definition, then this inline definition is
|
|
|
|
// externally visible.
|
|
|
|
if (!(isInlineSpecified() && getStorageClassAsWritten() == SC_Extern))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If any declaration is 'inline' but not 'extern', then this definition
|
|
|
|
// is externally visible.
|
2009-09-13 07:46:26 +00:00
|
|
|
for (redecl_iterator Redecl = redecls_begin(), RedeclEnd = redecls_end();
|
|
|
|
Redecl != RedeclEnd;
|
|
|
|
++Redecl) {
|
2010-12-09 16:59:22 +00:00
|
|
|
if (Redecl->isInlineSpecified() &&
|
|
|
|
Redecl->getStorageClassAsWritten() != SC_Extern)
|
2009-09-13 07:46:26 +00:00
|
|
|
return true;
|
2010-12-09 16:59:22 +00:00
|
|
|
}
|
2009-09-13 07:46:26 +00:00
|
|
|
|
2009-04-28 06:37:30 +00:00
|
|
|
return false;
|
2009-09-13 07:46:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// C99 6.7.4p6:
|
|
|
|
// [...] If all of the file scope declarations for a function in a
|
|
|
|
// translation unit include the inline function specifier without extern,
|
|
|
|
// then the definition in that translation unit is an inline definition.
|
|
|
|
for (redecl_iterator Redecl = redecls_begin(), RedeclEnd = redecls_end();
|
|
|
|
Redecl != RedeclEnd;
|
|
|
|
++Redecl) {
|
|
|
|
// Only consider file-scope declarations in this test.
|
|
|
|
if (!Redecl->getLexicalDeclContext()->isTranslationUnit())
|
|
|
|
continue;
|
|
|
|
|
2010-08-26 03:08:43 +00:00
|
|
|
if (!Redecl->isInlineSpecified() || Redecl->getStorageClass() == SC_Extern)
|
2009-09-13 07:46:26 +00:00
|
|
|
return true; // Not an inline definition
|
|
|
|
}
|
|
|
|
|
|
|
|
// C99 6.7.4p6:
|
|
|
|
// An inline definition does not provide an external definition for the
|
|
|
|
// function, and does not forbid an external definition in another
|
|
|
|
// translation unit.
|
2009-04-28 06:37:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-11-06 22:13:31 +00:00
|
|
|
/// getOverloadedOperator - Which C++ overloaded operator this
|
|
|
|
/// function represents, if any.
|
|
|
|
OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const {
|
Extend DeclarationName to support C++ overloaded operators, e.g.,
operator+, directly, using the same mechanism as all other special
names.
Removed the "special" identifiers for the overloaded operators from
the identifier table and IdentifierInfo data structure. IdentifierInfo
is back to representing only real identifiers.
Added a new Action, ActOnOperatorFunctionIdExpr, that builds an
expression from an parsed operator-function-id (e.g., "operator
+"). ActOnIdentifierExpr used to do this job, but
operator-function-ids are no longer represented by IdentifierInfo's.
Extended Declarator to store overloaded operator names.
Sema::GetNameForDeclarator now knows how to turn the operator
name into a DeclarationName for the overloaded operator.
Except for (perhaps) consolidating the functionality of
ActOnIdentifier, ActOnOperatorFunctionIdExpr, and
ActOnConversionFunctionExpr into a common routine that builds an
appropriate DeclRefExpr by looking up a DeclarationName, all of the
work on normalizing declaration names should be complete with this
commit.
llvm-svn: 59526
2008-11-18 14:39:36 +00:00
|
|
|
if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName)
|
|
|
|
return getDeclName().getCXXOverloadedOperator();
|
2008-11-06 22:13:31 +00:00
|
|
|
else
|
|
|
|
return OO_None;
|
|
|
|
}
|
|
|
|
|
2010-01-13 09:01:02 +00:00
|
|
|
/// getLiteralIdentifier - The literal suffix identifier this function
|
|
|
|
/// represents, if any.
|
|
|
|
const IdentifierInfo *FunctionDecl::getLiteralIdentifier() const {
|
|
|
|
if (getDeclName().getNameKind() == DeclarationName::CXXLiteralOperatorName)
|
|
|
|
return getDeclName().getCXXLiteralIdentifier();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-22 09:54:51 +00:00
|
|
|
FunctionDecl::TemplatedKind FunctionDecl::getTemplatedKind() const {
|
|
|
|
if (TemplateOrSpecialization.isNull())
|
|
|
|
return TK_NonTemplate;
|
|
|
|
if (TemplateOrSpecialization.is<FunctionTemplateDecl *>())
|
|
|
|
return TK_FunctionTemplate;
|
|
|
|
if (TemplateOrSpecialization.is<MemberSpecializationInfo *>())
|
|
|
|
return TK_MemberSpecialization;
|
|
|
|
if (TemplateOrSpecialization.is<FunctionTemplateSpecializationInfo *>())
|
|
|
|
return TK_FunctionTemplateSpecialization;
|
|
|
|
if (TemplateOrSpecialization.is
|
|
|
|
<DependentFunctionTemplateSpecializationInfo*>())
|
|
|
|
return TK_DependentFunctionTemplateSpecialization;
|
|
|
|
|
|
|
|
assert(false && "Did we miss a TemplateOrSpecialization type?");
|
|
|
|
return TK_NonTemplate;
|
|
|
|
}
|
|
|
|
|
2009-10-07 23:56:10 +00:00
|
|
|
FunctionDecl *FunctionDecl::getInstantiatedFromMemberFunction() const {
|
2009-10-12 20:18:28 +00:00
|
|
|
if (MemberSpecializationInfo *Info = getMemberSpecializationInfo())
|
2009-10-07 23:56:10 +00:00
|
|
|
return cast<FunctionDecl>(Info->getInstantiatedFrom());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-12 20:18:28 +00:00
|
|
|
MemberSpecializationInfo *FunctionDecl::getMemberSpecializationInfo() const {
|
|
|
|
return TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>();
|
|
|
|
}
|
|
|
|
|
2009-10-07 23:56:10 +00:00
|
|
|
void
|
2010-09-08 19:31:22 +00:00
|
|
|
FunctionDecl::setInstantiationOfMemberFunction(ASTContext &C,
|
|
|
|
FunctionDecl *FD,
|
2009-10-07 23:56:10 +00:00
|
|
|
TemplateSpecializationKind TSK) {
|
|
|
|
assert(TemplateOrSpecialization.isNull() &&
|
|
|
|
"Member function is already a specialization");
|
|
|
|
MemberSpecializationInfo *Info
|
2010-09-08 19:31:22 +00:00
|
|
|
= new (C) MemberSpecializationInfo(FD, TSK);
|
2009-10-07 23:56:10 +00:00
|
|
|
TemplateOrSpecialization = Info;
|
|
|
|
}
|
|
|
|
|
2009-10-27 20:53:28 +00:00
|
|
|
bool FunctionDecl::isImplicitlyInstantiable() const {
|
2010-05-17 17:34:56 +00:00
|
|
|
// If the function is invalid, it can't be implicitly instantiated.
|
|
|
|
if (isInvalidDecl())
|
2009-10-27 20:53:28 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (getTemplateSpecializationKind()) {
|
|
|
|
case TSK_Undeclared:
|
|
|
|
case TSK_ExplicitSpecialization:
|
|
|
|
case TSK_ExplicitInstantiationDefinition:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case TSK_ImplicitInstantiation:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case TSK_ExplicitInstantiationDeclaration:
|
|
|
|
// Handled below.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the actual template from which we will instantiate.
|
|
|
|
const FunctionDecl *PatternDecl = getTemplateInstantiationPattern();
|
2010-07-07 11:31:19 +00:00
|
|
|
bool HasPattern = false;
|
2009-10-27 20:53:28 +00:00
|
|
|
if (PatternDecl)
|
2010-07-07 11:31:19 +00:00
|
|
|
HasPattern = PatternDecl->hasBody(PatternDecl);
|
2009-10-27 20:53:28 +00:00
|
|
|
|
|
|
|
// C++0x [temp.explicit]p9:
|
|
|
|
// Except for inline functions, other explicit instantiation declarations
|
|
|
|
// have the effect of suppressing the implicit instantiation of the entity
|
|
|
|
// to which they refer.
|
2010-07-07 11:31:19 +00:00
|
|
|
if (!HasPattern || !PatternDecl)
|
2009-10-27 20:53:28 +00:00
|
|
|
return true;
|
|
|
|
|
2009-10-27 21:11:48 +00:00
|
|
|
return PatternDecl->isInlined();
|
2009-10-27 20:53:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FunctionDecl *FunctionDecl::getTemplateInstantiationPattern() const {
|
|
|
|
if (FunctionTemplateDecl *Primary = getPrimaryTemplate()) {
|
|
|
|
while (Primary->getInstantiatedFromMemberTemplate()) {
|
|
|
|
// If we have hit a point where the user provided a specialization of
|
|
|
|
// this template, we're done looking.
|
|
|
|
if (Primary->isMemberSpecialization())
|
|
|
|
break;
|
|
|
|
|
|
|
|
Primary = Primary->getInstantiatedFromMemberTemplate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Primary->getTemplatedDecl();
|
|
|
|
}
|
|
|
|
|
|
|
|
return getInstantiatedFromMemberFunction();
|
|
|
|
}
|
|
|
|
|
2009-06-29 17:30:29 +00:00
|
|
|
FunctionTemplateDecl *FunctionDecl::getPrimaryTemplate() const {
|
2009-09-09 15:08:12 +00:00
|
|
|
if (FunctionTemplateSpecializationInfo *Info
|
2009-06-29 17:30:29 +00:00
|
|
|
= TemplateOrSpecialization
|
|
|
|
.dyn_cast<FunctionTemplateSpecializationInfo*>()) {
|
2009-06-29 22:39:32 +00:00
|
|
|
return Info->Template.getPointer();
|
2009-06-29 17:30:29 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TemplateArgumentList *
|
|
|
|
FunctionDecl::getTemplateSpecializationArgs() const {
|
2009-09-09 15:08:12 +00:00
|
|
|
if (FunctionTemplateSpecializationInfo *Info
|
2009-10-13 16:30:37 +00:00
|
|
|
= TemplateOrSpecialization
|
|
|
|
.dyn_cast<FunctionTemplateSpecializationInfo*>()) {
|
2009-06-29 17:30:29 +00:00
|
|
|
return Info->TemplateArguments;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-20 15:32:11 +00:00
|
|
|
const TemplateArgumentListInfo *
|
|
|
|
FunctionDecl::getTemplateSpecializationArgsAsWritten() const {
|
|
|
|
if (FunctionTemplateSpecializationInfo *Info
|
|
|
|
= TemplateOrSpecialization
|
|
|
|
.dyn_cast<FunctionTemplateSpecializationInfo*>()) {
|
|
|
|
return Info->TemplateArgumentsAsWritten;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-09 15:08:12 +00:00
|
|
|
void
|
2010-09-08 19:31:22 +00:00
|
|
|
FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
|
|
|
|
FunctionTemplateDecl *Template,
|
2009-06-29 20:59:39 +00:00
|
|
|
const TemplateArgumentList *TemplateArgs,
|
2009-09-24 23:14:47 +00:00
|
|
|
void *InsertPos,
|
2010-05-20 15:32:11 +00:00
|
|
|
TemplateSpecializationKind TSK,
|
2010-07-05 10:37:55 +00:00
|
|
|
const TemplateArgumentListInfo *TemplateArgsAsWritten,
|
|
|
|
SourceLocation PointOfInstantiation) {
|
2009-09-24 23:14:47 +00:00
|
|
|
assert(TSK != TSK_Undeclared &&
|
|
|
|
"Must specify the type of function template specialization");
|
2009-09-09 15:08:12 +00:00
|
|
|
FunctionTemplateSpecializationInfo *Info
|
2009-06-29 17:30:29 +00:00
|
|
|
= TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>();
|
2009-06-26 00:10:03 +00:00
|
|
|
if (!Info)
|
2010-09-09 11:28:23 +00:00
|
|
|
Info = FunctionTemplateSpecializationInfo::Create(C, this, Template, TSK,
|
|
|
|
TemplateArgs,
|
|
|
|
TemplateArgsAsWritten,
|
|
|
|
PointOfInstantiation);
|
2009-06-26 00:10:03 +00:00
|
|
|
TemplateOrSpecialization = Info;
|
2009-09-09 15:08:12 +00:00
|
|
|
|
2009-06-29 20:59:39 +00:00
|
|
|
// Insert this function template specialization into the set of known
|
2009-09-24 23:14:47 +00:00
|
|
|
// function template specializations.
|
|
|
|
if (InsertPos)
|
|
|
|
Template->getSpecializations().InsertNode(Info, InsertPos);
|
|
|
|
else {
|
2010-07-20 13:59:58 +00:00
|
|
|
// Try to insert the new node. If there is an existing node, leave it, the
|
|
|
|
// set will contain the canonical decls while
|
|
|
|
// FunctionTemplateDecl::findSpecialization will return
|
|
|
|
// the most recent redeclarations.
|
2009-09-24 23:14:47 +00:00
|
|
|
FunctionTemplateSpecializationInfo *Existing
|
|
|
|
= Template->getSpecializations().GetOrInsertNode(Info);
|
2010-07-20 13:59:58 +00:00
|
|
|
(void)Existing;
|
|
|
|
assert((!Existing || Existing->Function->isCanonicalDecl()) &&
|
|
|
|
"Set is supposed to only contain canonical decls");
|
2009-09-24 23:14:47 +00:00
|
|
|
}
|
2009-06-26 00:10:03 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 09:05:18 +00:00
|
|
|
void
|
|
|
|
FunctionDecl::setDependentTemplateSpecialization(ASTContext &Context,
|
|
|
|
const UnresolvedSetImpl &Templates,
|
|
|
|
const TemplateArgumentListInfo &TemplateArgs) {
|
|
|
|
assert(TemplateOrSpecialization.isNull());
|
|
|
|
size_t Size = sizeof(DependentFunctionTemplateSpecializationInfo);
|
|
|
|
Size += Templates.size() * sizeof(FunctionTemplateDecl*);
|
2010-04-13 22:18:28 +00:00
|
|
|
Size += TemplateArgs.size() * sizeof(TemplateArgumentLoc);
|
2010-04-08 09:05:18 +00:00
|
|
|
void *Buffer = Context.Allocate(Size);
|
|
|
|
DependentFunctionTemplateSpecializationInfo *Info =
|
|
|
|
new (Buffer) DependentFunctionTemplateSpecializationInfo(Templates,
|
|
|
|
TemplateArgs);
|
|
|
|
TemplateOrSpecialization = Info;
|
|
|
|
}
|
|
|
|
|
|
|
|
DependentFunctionTemplateSpecializationInfo::
|
|
|
|
DependentFunctionTemplateSpecializationInfo(const UnresolvedSetImpl &Ts,
|
|
|
|
const TemplateArgumentListInfo &TArgs)
|
|
|
|
: AngleLocs(TArgs.getLAngleLoc(), TArgs.getRAngleLoc()) {
|
|
|
|
|
|
|
|
d.NumTemplates = Ts.size();
|
|
|
|
d.NumArgs = TArgs.size();
|
|
|
|
|
|
|
|
FunctionTemplateDecl **TsArray =
|
|
|
|
const_cast<FunctionTemplateDecl**>(getTemplates());
|
|
|
|
for (unsigned I = 0, E = Ts.size(); I != E; ++I)
|
|
|
|
TsArray[I] = cast<FunctionTemplateDecl>(Ts[I]->getUnderlyingDecl());
|
|
|
|
|
|
|
|
TemplateArgumentLoc *ArgsArray =
|
|
|
|
const_cast<TemplateArgumentLoc*>(getTemplateArgs());
|
|
|
|
for (unsigned I = 0, E = TArgs.size(); I != E; ++I)
|
|
|
|
new (&ArgsArray[I]) TemplateArgumentLoc(TArgs[I]);
|
|
|
|
}
|
|
|
|
|
2009-09-04 22:48:11 +00:00
|
|
|
TemplateSpecializationKind FunctionDecl::getTemplateSpecializationKind() const {
|
2009-09-09 15:08:12 +00:00
|
|
|
// For a function template specialization, query the specialization
|
2009-09-04 22:48:11 +00:00
|
|
|
// information object.
|
2009-10-07 23:56:10 +00:00
|
|
|
FunctionTemplateSpecializationInfo *FTSInfo
|
2009-06-29 22:39:32 +00:00
|
|
|
= TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>();
|
2009-10-07 23:56:10 +00:00
|
|
|
if (FTSInfo)
|
|
|
|
return FTSInfo->getTemplateSpecializationKind();
|
2009-09-04 22:48:11 +00:00
|
|
|
|
2009-10-07 23:56:10 +00:00
|
|
|
MemberSpecializationInfo *MSInfo
|
|
|
|
= TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>();
|
|
|
|
if (MSInfo)
|
|
|
|
return MSInfo->getTemplateSpecializationKind();
|
|
|
|
|
|
|
|
return TSK_Undeclared;
|
2009-06-29 22:39:32 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 15:08:12 +00:00
|
|
|
void
|
2009-10-15 17:21:20 +00:00
|
|
|
FunctionDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK,
|
|
|
|
SourceLocation PointOfInstantiation) {
|
2009-10-07 23:56:10 +00:00
|
|
|
if (FunctionTemplateSpecializationInfo *FTSInfo
|
|
|
|
= TemplateOrSpecialization.dyn_cast<
|
2009-10-15 17:21:20 +00:00
|
|
|
FunctionTemplateSpecializationInfo*>()) {
|
2009-10-07 23:56:10 +00:00
|
|
|
FTSInfo->setTemplateSpecializationKind(TSK);
|
2009-10-15 17:21:20 +00:00
|
|
|
if (TSK != TSK_ExplicitSpecialization &&
|
|
|
|
PointOfInstantiation.isValid() &&
|
|
|
|
FTSInfo->getPointOfInstantiation().isInvalid())
|
|
|
|
FTSInfo->setPointOfInstantiation(PointOfInstantiation);
|
|
|
|
} else if (MemberSpecializationInfo *MSInfo
|
|
|
|
= TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>()) {
|
2009-10-07 23:56:10 +00:00
|
|
|
MSInfo->setTemplateSpecializationKind(TSK);
|
2009-10-15 17:21:20 +00:00
|
|
|
if (TSK != TSK_ExplicitSpecialization &&
|
|
|
|
PointOfInstantiation.isValid() &&
|
|
|
|
MSInfo->getPointOfInstantiation().isInvalid())
|
|
|
|
MSInfo->setPointOfInstantiation(PointOfInstantiation);
|
|
|
|
} else
|
2009-10-07 23:56:10 +00:00
|
|
|
assert(false && "Function cannot have a template specialization kind");
|
2009-06-29 22:39:32 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 17:21:20 +00:00
|
|
|
SourceLocation FunctionDecl::getPointOfInstantiation() const {
|
|
|
|
if (FunctionTemplateSpecializationInfo *FTSInfo
|
|
|
|
= TemplateOrSpecialization.dyn_cast<
|
|
|
|
FunctionTemplateSpecializationInfo*>())
|
|
|
|
return FTSInfo->getPointOfInstantiation();
|
|
|
|
else if (MemberSpecializationInfo *MSInfo
|
|
|
|
= TemplateOrSpecialization.dyn_cast<MemberSpecializationInfo*>())
|
|
|
|
return MSInfo->getPointOfInstantiation();
|
|
|
|
|
|
|
|
return SourceLocation();
|
|
|
|
}
|
|
|
|
|
2009-09-11 20:15:17 +00:00
|
|
|
bool FunctionDecl::isOutOfLine() const {
|
2011-02-19 18:51:44 +00:00
|
|
|
if (Decl::isOutOfLine())
|
2009-09-11 20:15:17 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// If this function was instantiated from a member function of a
|
|
|
|
// class template, check whether that member function was defined out-of-line.
|
|
|
|
if (FunctionDecl *FD = getInstantiatedFromMemberFunction()) {
|
|
|
|
const FunctionDecl *Definition;
|
2010-07-07 11:31:19 +00:00
|
|
|
if (FD->hasBody(Definition))
|
2009-09-11 20:15:17 +00:00
|
|
|
return Definition->isOutOfLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this function was instantiated from a function template,
|
|
|
|
// check whether that function template was defined out-of-line.
|
|
|
|
if (FunctionTemplateDecl *FunTmpl = getPrimaryTemplate()) {
|
|
|
|
const FunctionDecl *Definition;
|
2010-07-07 11:31:19 +00:00
|
|
|
if (FunTmpl->getTemplatedDecl()->hasBody(Definition))
|
2009-09-11 20:15:17 +00:00
|
|
|
return Definition->isOutOfLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-08 16:41:52 +00:00
|
|
|
SourceRange FunctionDecl::getSourceRange() const {
|
|
|
|
return SourceRange(getOuterLocStart(), EndRangeLoc);
|
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FieldDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-12 09:06:06 +00:00
|
|
|
FieldDecl *FieldDecl::Create(const ASTContext &C, DeclContext *DC,
|
2011-03-08 08:55:46 +00:00
|
|
|
SourceLocation StartLoc, SourceLocation IdLoc,
|
|
|
|
IdentifierInfo *Id, QualType T,
|
2010-01-26 22:01:41 +00:00
|
|
|
TypeSourceInfo *TInfo, Expr *BW, bool Mutable) {
|
2011-03-08 08:55:46 +00:00
|
|
|
return new (C) FieldDecl(Decl::Field, DC, StartLoc, IdLoc, Id, T, TInfo,
|
|
|
|
BW, Mutable);
|
2010-01-26 22:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FieldDecl::isAnonymousStructOrUnion() const {
|
|
|
|
if (!isImplicit() || getDeclName())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (const RecordType *Record = getType()->getAs<RecordType>())
|
|
|
|
return Record->getDecl()->isAnonymousStructOrUnion();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-20 07:57:12 +00:00
|
|
|
unsigned FieldDecl::getFieldIndex() const {
|
|
|
|
if (CachedFieldIndex) return CachedFieldIndex - 1;
|
|
|
|
|
|
|
|
unsigned index = 0;
|
|
|
|
RecordDecl::field_iterator
|
|
|
|
i = getParent()->field_begin(), e = getParent()->field_end();
|
|
|
|
while (true) {
|
|
|
|
assert(i != e && "failed to find field in parent!");
|
|
|
|
if (*i == this)
|
|
|
|
break;
|
|
|
|
|
|
|
|
++i;
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
|
|
|
CachedFieldIndex = index + 1;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2011-03-08 11:07:11 +00:00
|
|
|
SourceRange FieldDecl::getSourceRange() const {
|
2011-03-08 16:41:52 +00:00
|
|
|
if (isBitField())
|
|
|
|
return SourceRange(getInnerLocStart(), BitWidth->getLocEnd());
|
|
|
|
return DeclaratorDecl::getSourceRange();
|
2011-03-08 11:07:11 +00:00
|
|
|
}
|
|
|
|
|
Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
2008-09-05 17:16:31 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-01-07 00:43:41 +00:00
|
|
|
// TagDecl Implementation
|
Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
2008-09-05 17:16:31 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-07-06 18:42:40 +00:00
|
|
|
SourceLocation TagDecl::getOuterLocStart() const {
|
|
|
|
return getTemplateOrInnerLocStart(this);
|
|
|
|
}
|
|
|
|
|
2009-07-14 03:17:17 +00:00
|
|
|
SourceRange TagDecl::getSourceRange() const {
|
|
|
|
SourceLocation E = RBraceLoc.isValid() ? RBraceLoc : getLocation();
|
2010-07-06 18:42:40 +00:00
|
|
|
return SourceRange(getOuterLocStart(), E);
|
2009-07-14 03:17:17 +00:00
|
|
|
}
|
|
|
|
|
2009-07-18 00:34:07 +00:00
|
|
|
TagDecl* TagDecl::getCanonicalDecl() {
|
2009-07-29 23:36:44 +00:00
|
|
|
return getFirstDeclaration();
|
2009-07-18 00:34:07 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 18:39:18 +00:00
|
|
|
void TagDecl::setTypedefForAnonDecl(TypedefDecl *TDD) {
|
|
|
|
TypedefDeclOrQualifier = TDD;
|
|
|
|
if (TypeForDecl)
|
2011-01-19 06:33:43 +00:00
|
|
|
const_cast<Type*>(TypeForDecl)->ClearLinkageCache();
|
2010-12-06 18:36:25 +00:00
|
|
|
ClearLinkageCache();
|
2010-05-19 18:39:18 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 00:42:38 +00:00
|
|
|
void TagDecl::startDefinition() {
|
2010-08-02 18:27:05 +00:00
|
|
|
IsBeingDefined = true;
|
2010-02-04 22:26:26 +00:00
|
|
|
|
|
|
|
if (isa<CXXRecordDecl>(this)) {
|
|
|
|
CXXRecordDecl *D = cast<CXXRecordDecl>(this);
|
|
|
|
struct CXXRecordDecl::DefinitionData *Data =
|
|
|
|
new (getASTContext()) struct CXXRecordDecl::DefinitionData(D);
|
2010-03-26 21:56:38 +00:00
|
|
|
for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I)
|
|
|
|
cast<CXXRecordDecl>(*I)->DefinitionData = Data;
|
2010-02-04 22:26:26 +00:00
|
|
|
}
|
2009-01-17 00:42:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TagDecl::completeDefinition() {
|
2010-02-05 01:33:36 +00:00
|
|
|
assert((!isa<CXXRecordDecl>(this) ||
|
|
|
|
cast<CXXRecordDecl>(this)->hasDefinition()) &&
|
|
|
|
"definition completed but not started");
|
|
|
|
|
2009-01-17 00:42:38 +00:00
|
|
|
IsDefinition = true;
|
2010-08-02 18:27:05 +00:00
|
|
|
IsBeingDefined = false;
|
2010-10-24 17:26:50 +00:00
|
|
|
|
|
|
|
if (ASTMutationListener *L = getASTMutationListener())
|
|
|
|
L->CompletedTagDefinition(this);
|
2009-01-17 00:42:38 +00:00
|
|
|
}
|
|
|
|
|
2010-02-11 01:04:33 +00:00
|
|
|
TagDecl* TagDecl::getDefinition() const {
|
2009-07-29 23:36:44 +00:00
|
|
|
if (isDefinition())
|
|
|
|
return const_cast<TagDecl *>(this);
|
2010-10-19 21:54:32 +00:00
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(this))
|
|
|
|
return CXXRD->getDefinition();
|
2009-09-09 15:08:12 +00:00
|
|
|
|
|
|
|
for (redecl_iterator R = redecls_begin(), REnd = redecls_end();
|
2009-07-29 23:36:44 +00:00
|
|
|
R != REnd; ++R)
|
|
|
|
if (R->isDefinition())
|
|
|
|
return *R;
|
2009-09-09 15:08:12 +00:00
|
|
|
|
2009-07-29 23:36:44 +00:00
|
|
|
return 0;
|
Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
2008-09-05 17:16:31 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 02:25:35 +00:00
|
|
|
void TagDecl::setQualifierInfo(NestedNameSpecifierLoc QualifierLoc) {
|
|
|
|
if (QualifierLoc) {
|
2010-03-15 10:12:16 +00:00
|
|
|
// Make sure the extended qualifier info is allocated.
|
|
|
|
if (!hasExtInfo())
|
|
|
|
TypedefDeclOrQualifier = new (getASTContext()) ExtInfo;
|
|
|
|
// Set qualifier info.
|
2011-02-25 02:25:35 +00:00
|
|
|
getExtInfo()->QualifierLoc = QualifierLoc;
|
2010-03-15 10:12:16 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Here Qualifier == 0, i.e., we are removing the qualifier (if any).
|
|
|
|
if (hasExtInfo()) {
|
2011-03-18 15:16:37 +00:00
|
|
|
if (getExtInfo()->NumTemplParamLists == 0) {
|
|
|
|
getASTContext().Deallocate(getExtInfo());
|
|
|
|
TypedefDeclOrQualifier = (TypedefDecl*) 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
getExtInfo()->QualifierLoc = QualifierLoc;
|
2010-03-15 10:12:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 15:16:37 +00:00
|
|
|
void TagDecl::setTemplateParameterListsInfo(ASTContext &Context,
|
|
|
|
unsigned NumTPLists,
|
|
|
|
TemplateParameterList **TPLists) {
|
|
|
|
assert(NumTPLists > 0);
|
|
|
|
// Make sure the extended decl info is allocated.
|
|
|
|
if (!hasExtInfo())
|
|
|
|
// Allocate external info struct.
|
|
|
|
TypedefDeclOrQualifier = new (getASTContext()) ExtInfo;
|
|
|
|
// Set the template parameter lists info.
|
|
|
|
getExtInfo()->setTemplateParameterListsInfo(Context, NumTPLists, TPLists);
|
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// EnumDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-03-09 14:09:51 +00:00
|
|
|
EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation StartLoc, SourceLocation IdLoc,
|
|
|
|
IdentifierInfo *Id,
|
2010-12-03 18:54:17 +00:00
|
|
|
EnumDecl *PrevDecl, bool IsScoped,
|
|
|
|
bool IsScopedUsingClassTag, bool IsFixed) {
|
2011-03-09 14:09:51 +00:00
|
|
|
EnumDecl *Enum = new (C) EnumDecl(DC, StartLoc, IdLoc, Id, PrevDecl,
|
2010-12-03 18:54:17 +00:00
|
|
|
IsScoped, IsScopedUsingClassTag, IsFixed);
|
2010-01-26 22:01:41 +00:00
|
|
|
C.getTypeDeclType(Enum, PrevDecl);
|
|
|
|
return Enum;
|
|
|
|
}
|
|
|
|
|
2010-07-02 11:54:55 +00:00
|
|
|
EnumDecl *EnumDecl::Create(ASTContext &C, EmptyShell Empty) {
|
2011-03-09 14:09:51 +00:00
|
|
|
return new (C) EnumDecl(0, SourceLocation(), SourceLocation(), 0, 0,
|
2010-12-03 18:54:17 +00:00
|
|
|
false, false, false);
|
2010-07-02 11:54:55 +00:00
|
|
|
}
|
|
|
|
|
2010-02-11 01:19:42 +00:00
|
|
|
void EnumDecl::completeDefinition(QualType NewType,
|
2010-05-06 08:49:23 +00:00
|
|
|
QualType NewPromotionType,
|
|
|
|
unsigned NumPositiveBits,
|
|
|
|
unsigned NumNegativeBits) {
|
2010-01-26 22:01:41 +00:00
|
|
|
assert(!isDefinition() && "Cannot redefine enums!");
|
2010-10-08 23:50:27 +00:00
|
|
|
if (!IntegerType)
|
|
|
|
IntegerType = NewType.getTypePtr();
|
2010-01-26 22:01:41 +00:00
|
|
|
PromotionType = NewPromotionType;
|
2010-05-06 08:49:23 +00:00
|
|
|
setNumPositiveBits(NumPositiveBits);
|
|
|
|
setNumNegativeBits(NumNegativeBits);
|
2010-01-26 22:01:41 +00:00
|
|
|
TagDecl::completeDefinition();
|
|
|
|
}
|
|
|
|
|
2008-03-31 00:36:02 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// RecordDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-01-25 04:52:46 +00:00
|
|
|
|
2011-03-09 14:09:51 +00:00
|
|
|
RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
|
|
|
|
SourceLocation StartLoc, SourceLocation IdLoc,
|
|
|
|
IdentifierInfo *Id, RecordDecl *PrevDecl)
|
|
|
|
: TagDecl(DK, TK, DC, IdLoc, Id, PrevDecl, StartLoc) {
|
2008-09-02 21:12:32 +00:00
|
|
|
HasFlexibleArrayMember = false;
|
2009-01-07 00:43:41 +00:00
|
|
|
AnonymousStructOrUnion = false;
|
2009-07-08 01:18:33 +00:00
|
|
|
HasObjectMember = false;
|
2010-10-14 20:14:34 +00:00
|
|
|
LoadedFieldsFromExternalStorage = false;
|
2008-09-02 21:12:32 +00:00
|
|
|
assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
|
|
|
|
}
|
|
|
|
|
2011-01-12 09:06:06 +00:00
|
|
|
RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC,
|
2011-03-09 14:09:51 +00:00
|
|
|
SourceLocation StartLoc, SourceLocation IdLoc,
|
|
|
|
IdentifierInfo *Id, RecordDecl* PrevDecl) {
|
|
|
|
RecordDecl* R = new (C) RecordDecl(Record, TK, DC, StartLoc, IdLoc, Id,
|
|
|
|
PrevDecl);
|
Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
2008-09-05 17:16:31 +00:00
|
|
|
C.getTypeDeclType(R, PrevDecl);
|
|
|
|
return R;
|
2008-09-02 21:12:32 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 09:06:06 +00:00
|
|
|
RecordDecl *RecordDecl::Create(const ASTContext &C, EmptyShell Empty) {
|
2011-03-09 14:09:51 +00:00
|
|
|
return new (C) RecordDecl(Record, TTK_Struct, 0, SourceLocation(),
|
|
|
|
SourceLocation(), 0, 0);
|
2010-07-02 11:54:55 +00:00
|
|
|
}
|
|
|
|
|
2009-03-25 15:59:44 +00:00
|
|
|
bool RecordDecl::isInjectedClassName() const {
|
2009-09-09 15:08:12 +00:00
|
|
|
return isImplicit() && getDeclName() && getDeclContext()->isRecord() &&
|
2009-03-25 15:59:44 +00:00
|
|
|
cast<RecordDecl>(getDeclContext())->getDeclName() == getDeclName();
|
|
|
|
}
|
|
|
|
|
2010-10-14 20:14:34 +00:00
|
|
|
RecordDecl::field_iterator RecordDecl::field_begin() const {
|
|
|
|
if (hasExternalLexicalStorage() && !LoadedFieldsFromExternalStorage)
|
|
|
|
LoadFieldsFromExternalStorage();
|
|
|
|
|
|
|
|
return field_iterator(decl_iterator(FirstDecl));
|
|
|
|
}
|
|
|
|
|
2011-02-19 18:51:44 +00:00
|
|
|
/// completeDefinition - Notes that the definition of this type is now
|
|
|
|
/// complete.
|
|
|
|
void RecordDecl::completeDefinition() {
|
|
|
|
assert(!isDefinition() && "Cannot redefine record!");
|
|
|
|
TagDecl::completeDefinition();
|
|
|
|
}
|
|
|
|
|
2010-10-14 20:14:34 +00:00
|
|
|
void RecordDecl::LoadFieldsFromExternalStorage() const {
|
|
|
|
ExternalASTSource *Source = getASTContext().getExternalSource();
|
|
|
|
assert(hasExternalLexicalStorage() && Source && "No external storage?");
|
|
|
|
|
|
|
|
// Notify that we have a RecordDecl doing some initialization.
|
|
|
|
ExternalASTSource::Deserializing TheFields(Source);
|
|
|
|
|
|
|
|
llvm::SmallVector<Decl*, 64> Decls;
|
|
|
|
if (Source->FindExternalLexicalDeclsBy<FieldDecl>(this, Decls))
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// Check that all decls we got were FieldDecls.
|
|
|
|
for (unsigned i=0, e=Decls.size(); i != e; ++i)
|
|
|
|
assert(isa<FieldDecl>(Decls[i]));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LoadedFieldsFromExternalStorage = true;
|
|
|
|
|
|
|
|
if (Decls.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
llvm::tie(FirstDecl, LastDecl) = BuildDeclChain(Decls);
|
|
|
|
}
|
|
|
|
|
2008-10-08 17:01:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BlockDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-02-11 01:19:42 +00:00
|
|
|
void BlockDecl::setParams(ParmVarDecl **NewParamInfo,
|
2009-03-13 16:56:44 +00:00
|
|
|
unsigned NParms) {
|
|
|
|
assert(ParamInfo == 0 && "Already has param info!");
|
2009-09-09 15:08:12 +00:00
|
|
|
|
2009-03-13 16:56:44 +00:00
|
|
|
// Zero params -> null pointer.
|
|
|
|
if (NParms) {
|
|
|
|
NumParams = NParms;
|
2010-02-11 01:19:42 +00:00
|
|
|
void *Mem = getASTContext().Allocate(sizeof(ParmVarDecl*)*NumParams);
|
2009-03-13 16:56:44 +00:00
|
|
|
ParamInfo = new (Mem) ParmVarDecl*[NumParams];
|
|
|
|
memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-07 10:33:21 +00:00
|
|
|
void BlockDecl::setCaptures(ASTContext &Context,
|
|
|
|
const Capture *begin,
|
|
|
|
const Capture *end,
|
|
|
|
bool capturesCXXThis) {
|
2011-02-02 13:00:07 +00:00
|
|
|
CapturesCXXThis = capturesCXXThis;
|
|
|
|
|
|
|
|
if (begin == end) {
|
2011-02-07 10:33:21 +00:00
|
|
|
NumCaptures = 0;
|
|
|
|
Captures = 0;
|
2011-02-02 13:00:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-07 10:33:21 +00:00
|
|
|
NumCaptures = end - begin;
|
|
|
|
|
|
|
|
// Avoid new Capture[] because we don't want to provide a default
|
|
|
|
// constructor.
|
|
|
|
size_t allocationSize = NumCaptures * sizeof(Capture);
|
|
|
|
void *buffer = Context.Allocate(allocationSize, /*alignment*/sizeof(void*));
|
|
|
|
memcpy(buffer, begin, allocationSize);
|
|
|
|
Captures = static_cast<Capture*>(buffer);
|
2009-03-13 16:56:44 +00:00
|
|
|
}
|
2010-01-26 22:01:41 +00:00
|
|
|
|
2010-12-21 16:27:07 +00:00
|
|
|
SourceRange BlockDecl::getSourceRange() const {
|
|
|
|
return SourceRange(getLocation(), Body? Body->getLocEnd() : getLocation());
|
|
|
|
}
|
2010-01-26 22:01:41 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Other Decl Allocation/Deallocation Method Implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) {
|
|
|
|
return new (C) TranslationUnitDecl(C);
|
|
|
|
}
|
|
|
|
|
2011-02-17 07:39:24 +00:00
|
|
|
LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
|
2011-03-05 18:21:20 +00:00
|
|
|
SourceLocation IdentL, IdentifierInfo *II) {
|
|
|
|
return new (C) LabelDecl(DC, IdentL, II, 0, IdentL);
|
|
|
|
}
|
|
|
|
|
|
|
|
LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation IdentL, IdentifierInfo *II,
|
|
|
|
SourceLocation GnuLabelL) {
|
|
|
|
assert(GnuLabelL != IdentL && "Use this only for GNU local labels");
|
|
|
|
return new (C) LabelDecl(DC, IdentL, II, 0, GnuLabelL);
|
2011-02-17 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
|
2011-03-08 12:38:20 +00:00
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation IdLoc, IdentifierInfo *Id) {
|
|
|
|
return new (C) NamespaceDecl(DC, StartLoc, IdLoc, Id);
|
2010-01-26 22:01:41 +00:00
|
|
|
}
|
|
|
|
|
2010-10-27 19:49:05 +00:00
|
|
|
NamespaceDecl *NamespaceDecl::getNextNamespace() {
|
|
|
|
return dyn_cast_or_null<NamespaceDecl>(
|
|
|
|
NextNamespace.get(getASTContext().getExternalSource()));
|
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
|
2011-03-08 08:55:46 +00:00
|
|
|
SourceLocation IdLoc,
|
|
|
|
IdentifierInfo *Id,
|
|
|
|
QualType Type) {
|
|
|
|
return new (C) ImplicitParamDecl(DC, IdLoc, Id, Type);
|
2010-01-26 22:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
|
2011-03-08 08:55:46 +00:00
|
|
|
SourceLocation StartLoc,
|
2010-08-11 22:01:17 +00:00
|
|
|
const DeclarationNameInfo &NameInfo,
|
|
|
|
QualType T, TypeSourceInfo *TInfo,
|
2011-03-08 08:55:46 +00:00
|
|
|
StorageClass SC, StorageClass SCAsWritten,
|
2010-12-09 16:59:22 +00:00
|
|
|
bool isInlineSpecified,
|
|
|
|
bool hasWrittenPrototype) {
|
2011-03-08 08:55:46 +00:00
|
|
|
FunctionDecl *New = new (C) FunctionDecl(Function, DC, StartLoc, NameInfo,
|
|
|
|
T, TInfo, SC, SCAsWritten,
|
|
|
|
isInlineSpecified);
|
2010-01-26 22:01:41 +00:00
|
|
|
New->HasWrittenPrototype = hasWrittenPrototype;
|
|
|
|
return New;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
|
|
|
|
return new (C) BlockDecl(DC, L);
|
|
|
|
}
|
|
|
|
|
|
|
|
EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
|
|
|
|
SourceLocation L,
|
|
|
|
IdentifierInfo *Id, QualType T,
|
|
|
|
Expr *E, const llvm::APSInt &V) {
|
|
|
|
return new (C) EnumConstantDecl(CD, L, Id, T, E, V);
|
|
|
|
}
|
|
|
|
|
2010-11-21 14:11:41 +00:00
|
|
|
IndirectFieldDecl *
|
|
|
|
IndirectFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
|
|
|
|
IdentifierInfo *Id, QualType T, NamedDecl **CH,
|
|
|
|
unsigned CHS) {
|
2010-11-21 06:08:52 +00:00
|
|
|
return new (C) IndirectFieldDecl(DC, L, Id, T, CH, CHS);
|
|
|
|
}
|
|
|
|
|
2010-09-01 20:41:53 +00:00
|
|
|
SourceRange EnumConstantDecl::getSourceRange() const {
|
|
|
|
SourceLocation End = getLocation();
|
|
|
|
if (Init)
|
|
|
|
End = Init->getLocEnd();
|
|
|
|
return SourceRange(getLocation(), End);
|
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
|
2011-03-06 15:48:19 +00:00
|
|
|
SourceLocation StartLoc, SourceLocation IdLoc,
|
|
|
|
IdentifierInfo *Id, TypeSourceInfo *TInfo) {
|
|
|
|
return new (C) TypedefDecl(DC, StartLoc, IdLoc, Id, TInfo);
|
2010-01-26 22:01:41 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 16:41:52 +00:00
|
|
|
SourceRange TypedefDecl::getSourceRange() const {
|
|
|
|
SourceLocation RangeEnd = getLocation();
|
|
|
|
if (TypeSourceInfo *TInfo = getTypeSourceInfo()) {
|
|
|
|
if (typeIsPostfix(TInfo->getType()))
|
|
|
|
RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
|
|
|
|
}
|
|
|
|
return SourceRange(getLocStart(), RangeEnd);
|
|
|
|
}
|
|
|
|
|
2010-01-26 22:01:41 +00:00
|
|
|
FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC,
|
2011-03-03 14:20:18 +00:00
|
|
|
StringLiteral *Str,
|
|
|
|
SourceLocation AsmLoc,
|
|
|
|
SourceLocation RParenLoc) {
|
|
|
|
return new (C) FileScopeAsmDecl(DC, Str, AsmLoc, RParenLoc);
|
2010-01-26 22:01:41 +00:00
|
|
|
}
|