summaryrefslogtreecommitdiff
path: root/contrib/llvm/tools/clang/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-12-26 20:36:37 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-12-26 20:36:37 +0000
commitb6d42e34c27d79488e27db71466f4e5cece05910 (patch)
treeab60b4cdd6e430dda1f292a46a77ddb744723f31 /contrib/llvm/tools/clang/lib/AST/DeclBase.cpp
parentd76705554f5443404be5a5e89f2f5f5ebf42cf98 (diff)
downloadsrc-test2-b6d42e34c27d79488e27db71466f4e5cece05910.tar.gz
src-test2-b6d42e34c27d79488e27db71466f4e5cece05910.zip
Notes
Diffstat (limited to 'contrib/llvm/tools/clang/lib/AST/DeclBase.cpp')
-rw-r--r--contrib/llvm/tools/clang/lib/AST/DeclBase.cpp68
1 files changed, 55 insertions, 13 deletions
diff --git a/contrib/llvm/tools/clang/lib/AST/DeclBase.cpp b/contrib/llvm/tools/clang/lib/AST/DeclBase.cpp
index 72587e388e47..bfb7d02b2955 100644
--- a/contrib/llvm/tools/clang/lib/AST/DeclBase.cpp
+++ b/contrib/llvm/tools/clang/lib/AST/DeclBase.cpp
@@ -46,7 +46,7 @@ void Decl::updateOutOfDate(IdentifierInfo &II) const {
}
#define DECL(DERIVED, BASE) \
- static_assert(Decl::DeclObjAlignment >= \
+ static_assert(llvm::AlignOf<Decl>::Alignment >= \
llvm::AlignOf<DERIVED##Decl>::Alignment, \
"Alignment sufficient after objects prepended to " #DERIVED);
#define ABSTRACT_DECL(DECL)
@@ -56,7 +56,7 @@ void *Decl::operator new(std::size_t Size, const ASTContext &Context,
unsigned ID, std::size_t Extra) {
// Allocate an extra 8 bytes worth of storage, which ensures that the
// resulting pointer will still be 8-byte aligned.
- static_assert(sizeof(unsigned) * 2 >= DeclObjAlignment,
+ static_assert(sizeof(unsigned) * 2 >= llvm::AlignOf<Decl>::Alignment,
"Decl won't be misaligned");
void *Start = Context.Allocate(Size + Extra + 8);
void *Result = (char*)Start + 8;
@@ -81,7 +81,8 @@ void *Decl::operator new(std::size_t Size, const ASTContext &Ctx,
// Ensure required alignment of the resulting object by adding extra
// padding at the start if required.
size_t ExtraAlign =
- llvm::OffsetToAlignment(sizeof(Module *), DeclObjAlignment);
+ llvm::OffsetToAlignment(sizeof(Module *),
+ llvm::AlignOf<Decl>::Alignment);
char *Buffer = reinterpret_cast<char *>(
::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx));
Buffer += ExtraAlign;
@@ -196,6 +197,17 @@ bool Decl::isTemplateDecl() const {
return isa<TemplateDecl>(this);
}
+TemplateDecl *Decl::getDescribedTemplate() const {
+ if (auto *FD = dyn_cast<FunctionDecl>(this))
+ return FD->getDescribedFunctionTemplate();
+ else if (auto *RD = dyn_cast<CXXRecordDecl>(this))
+ return RD->getDescribedClassTemplate();
+ else if (auto *VD = dyn_cast<VarDecl>(this))
+ return VD->getDescribedVarTemplate();
+
+ return nullptr;
+}
+
const DeclContext *Decl::getParentFunctionOrMethod() const {
for (const DeclContext *DC = getDeclContext();
DC && !DC->isTranslationUnit() && !DC->isNamespace();
@@ -329,25 +341,29 @@ unsigned Decl::getMaxAlignment() const {
return Align;
}
-bool Decl::isUsed(bool CheckUsedAttr) const {
- if (Used)
+bool Decl::isUsed(bool CheckUsedAttr) const {
+ const Decl *CanonD = getCanonicalDecl();
+ if (CanonD->Used)
return true;
-
+
// Check for used attribute.
- if (CheckUsedAttr && hasAttr<UsedAttr>())
+ // Ask the most recent decl, since attributes accumulate in the redecl chain.
+ if (CheckUsedAttr && getMostRecentDecl()->hasAttr<UsedAttr>())
return true;
- return false;
+ // The information may have not been deserialized yet. Force deserialization
+ // to complete the needed information.
+ return getMostRecentDecl()->getCanonicalDecl()->Used;
}
void Decl::markUsed(ASTContext &C) {
- if (Used)
+ if (isUsed(false))
return;
if (C.getASTMutationListener())
C.getASTMutationListener()->DeclarationMarkedUsed(this);
- Used = true;
+ setIsUsed();
}
bool Decl::isReferenced() const {
@@ -362,6 +378,18 @@ bool Decl::isReferenced() const {
return false;
}
+bool Decl::hasDefiningAttr() const {
+ return hasAttr<AliasAttr>() || hasAttr<IFuncAttr>();
+}
+
+const Attr *Decl::getDefiningAttr() const {
+ if (AliasAttr *AA = getAttr<AliasAttr>())
+ return AA;
+ if (IFuncAttr *IFA = getAttr<IFuncAttr>())
+ return IFA;
+ return nullptr;
+}
+
/// \brief Determine the availability of the given declaration based on
/// the target platform.
///
@@ -432,7 +460,7 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,
<< VTI << HintMessage;
}
- return AR_NotYetIntroduced;
+ return A->getStrict() ? AR_Unavailable : AR_NotYetIntroduced;
}
// Make sure that this declaration hasn't been obsoleted.
@@ -467,6 +495,9 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,
}
AvailabilityResult Decl::getAvailability(std::string *Message) const {
+ if (auto *FTD = dyn_cast<FunctionTemplateDecl>(this))
+ return FTD->getTemplatedDecl()->getAvailability(Message);
+
AvailabilityResult Result = AR_Available;
std::string ResultMessage;
@@ -563,6 +594,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
case Function:
case CXXMethod:
case CXXConstructor:
+ case ConstructorUsingShadow:
case CXXDestructor:
case CXXConversion:
case EnumConstant:
@@ -630,6 +662,9 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
case TemplateTemplateParm:
return IDNS_Ordinary | IDNS_Tag | IDNS_Type;
+ case OMPDeclareReduction:
+ return IDNS_OMPReduction;
+
// Never have names.
case Friend:
case FriendTemplate:
@@ -638,6 +673,8 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
case FileScopeAsm:
case StaticAssert:
case ObjCPropertyImpl:
+ case PragmaComment:
+ case PragmaDetectMismatch:
case Block:
case Captured:
case TranslationUnit:
@@ -655,6 +692,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
case ObjCCategoryImpl:
case Import:
case OMPThreadPrivate:
+ case OMPCapturedExpr:
case Empty:
// Never looked up by name.
return 0;
@@ -957,6 +995,7 @@ DeclContext *DeclContext::getPrimaryContext() {
case Decl::LinkageSpec:
case Decl::Block:
case Decl::Captured:
+ case Decl::OMPDeclareReduction:
// There is only one DeclContext for these entities.
return this;
@@ -1549,9 +1588,12 @@ void DeclContext::makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
bool Recoverable) {
assert(this == getPrimaryContext() && "expected a primary DC");
- // Skip declarations within functions.
- if (isFunctionOrMethod())
+ if (!isLookupContext()) {
+ if (isTransparentContext())
+ getParent()->getPrimaryContext()
+ ->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
return;
+ }
// Skip declarations which should be invisible to name lookup.
if (shouldBeHidden(D))