diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -780,18 +780,19 @@ /// all declarations in a global module fragment are unowned. Module *getOwningModuleForLinkage(bool IgnoreLinkage = false) const; - /// Determine whether this declaration might be hidden from name - /// lookup. Note that the declaration might be visible even if this returns - /// \c false, if the owning module is visible within the query context. - // FIXME: Rename this to make it clearer what it does. - bool isHidden() const { - return (int)getModuleOwnershipKind() > (int)ModuleOwnershipKind::Visible; + /// Determine whether this declaration is definitely visible to name lookup, + /// independent of whether the owning module is visible. + /// Note: The declaration may be visible even if this returns \c false if the + /// owning module is visible within the query context. This is a low-level + /// helper function; most code should be calling Sema::isVisible() instead. + bool isUnconditionallyVisible() const { + return (int)getModuleOwnershipKind() <= (int)ModuleOwnershipKind::Visible; } /// Set that this declaration is globally visible, even if it came from a /// module that is not visible. void setVisibleDespiteOwningModule() { - if (isHidden()) + if (!isUnconditionallyVisible()) setModuleOwnershipKind(ModuleOwnershipKind::Visible); } diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -2883,11 +2883,11 @@ } inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) { - return !Cat->isHidden(); + return Cat->isUnconditionallyVisible(); } inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) { - return Cat->IsClassExtension() && !Cat->isHidden(); + return Cat->IsClassExtension() && Cat->isUnconditionallyVisible(); } inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) { diff --git a/clang/include/clang/Sema/Lookup.h b/clang/include/clang/Sema/Lookup.h --- a/clang/include/clang/Sema/Lookup.h +++ b/clang/include/clang/Sema/Lookup.h @@ -348,7 +348,7 @@ /// program. static bool isVisible(Sema &SemaRef, NamedDecl *D) { // If this declaration is not hidden, it's visible. - if (!D->isHidden()) + if (D->isUnconditionallyVisible()) return true; // During template instantiation, we can refer to hidden declarations, if diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -1862,7 +1862,7 @@ /// Determine whether a declaration is visible to name lookup. bool isVisible(const NamedDecl *D) { - return !D->isHidden() || isVisibleSlow(D); + return D->isUnconditionallyVisible() || isVisibleSlow(D); } /// Determine whether any declaration of an entity is visible. diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp --- a/clang/lib/AST/ASTDumper.cpp +++ b/clang/lib/AST/ASTDumper.cpp @@ -54,7 +54,7 @@ NodeDumper.AddChild([=] { NodeDumper.dumpBareDeclRef(*RI); - if ((*RI)->isHidden()) + if (!(*RI)->isUnconditionallyVisible()) OS << " hidden"; // If requested, dump the redecl chain for this lookup. diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -94,7 +94,7 @@ // methods there. if (const auto *Proto = dyn_cast(this)) { if (const ObjCProtocolDecl *Def = Proto->getDefinition()) - if (Def->isHidden() && !AllowHidden) + if (!Def->isUnconditionallyVisible() && !AllowHidden) return nullptr; } @@ -181,7 +181,7 @@ // property. if (const auto *Proto = dyn_cast(DC)) { if (const ObjCProtocolDecl *Def = Proto->getDefinition()) - if (Def->isHidden()) + if (!Def->isUnconditionallyVisible()) return nullptr; } @@ -239,7 +239,7 @@ // Don't find properties within hidden protocol definitions. if (const auto *Proto = dyn_cast(this)) { if (const ObjCProtocolDecl *Def = Proto->getDefinition()) - if (Def->isHidden()) + if (!Def->isUnconditionallyVisible()) return nullptr; } @@ -1919,7 +1919,7 @@ // If there is no definition or the definition is hidden, we don't find // anything. const ObjCProtocolDecl *Def = getDefinition(); - if (!Def || Def->isHidden()) + if (!Def || !Def->isUnconditionallyVisible()) return nullptr; if ((MethodDecl = getMethod(Sel, isInstance))) diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -111,7 +111,7 @@ JOS.attribute("isReferenced", true); if (const auto *ND = dyn_cast(D)) - attributeOnlyIfTrue("isHidden", ND->isHidden()); + attributeOnlyIfTrue("isHidden", !ND->isUnconditionallyVisible()); if (D->getLexicalDeclContext() != D->getDeclContext()) { // Because of multiple inheritance, a DeclContext pointer does not produce diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp --- a/clang/lib/AST/TextNodeDumper.cpp +++ b/clang/lib/AST/TextNodeDumper.cpp @@ -252,7 +252,7 @@ const_cast(ND))) AddChild([=] { OS << "also in " << M->getFullModuleName(); }); if (const NamedDecl *ND = dyn_cast(D)) - if (ND->isHidden()) + if (!ND->isUnconditionallyVisible()) OS << " hidden"; if (D->isImplicit()) OS << " implicit"; diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -1272,7 +1272,8 @@ static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl, ObjCProtocolDecl *&UndefinedProtocol) { - if (!PDecl->hasDefinition() || PDecl->getDefinition()->isHidden()) { + if (!PDecl->hasDefinition() || + !PDecl->getDefinition()->isUnconditionallyVisible()) { UndefinedProtocol = PDecl; return true; } @@ -3235,7 +3236,7 @@ return false; // If either is hidden, it is not considered to match. - if (left->isHidden() || right->isHidden()) + if (!left->isUnconditionallyVisible() || !right->isUnconditionallyVisible()) return false; if (left->isDirectMethod() != right->isDirectMethod()) @@ -3494,7 +3495,7 @@ ObjCMethodList &MethList = InstanceFirst ? Pos->second.first : Pos->second.second; for (ObjCMethodList *M = &MethList; M; M = M->getNext()) - if (M->getMethod() && !M->getMethod()->isHidden()) { + if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) { if (FilterMethodsByTypeBound(M->getMethod(), TypeBound)) Methods.push_back(M->getMethod()); } @@ -3510,7 +3511,7 @@ ObjCMethodList &MethList2 = InstanceFirst ? Pos->second.second : Pos->second.first; for (ObjCMethodList *M = &MethList2; M; M = M->getNext()) - if (M->getMethod() && !M->getMethod()->isHidden()) { + if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) { if (FilterMethodsByTypeBound(M->getMethod(), TypeBound)) Methods.push_back(M->getMethod()); } @@ -3557,7 +3558,7 @@ ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second; SmallVector Methods; for (ObjCMethodList *M = &MethList; M; M = M->getNext()) { - if (M->getMethod() && !M->getMethod()->isHidden()) + if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) return M->getMethod(); } return nullptr; diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -1710,7 +1710,8 @@ /// path (by instantiating a template, you allow it to see the declarations that /// your module can see, including those later on in your module). bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) { - assert(D->isHidden() && "should not call this: not in slow case"); + assert(!D->isUnconditionallyVisible() && + "should not call this: not in slow case"); Module *DeclModule = SemaRef.getOwningModule(D); assert(DeclModule && "hidden decl has no owning module"); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -4038,7 +4038,7 @@ void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?"); for (Decl *D : Names) { - bool wasHidden = D->isHidden(); + bool wasHidden = !D->isUnconditionallyVisible(); D->setVisibleDespiteOwningModule(); if (wasHidden && SemaObj) { @@ -4100,9 +4100,9 @@ /// visible. void ASTReader::mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef) { - if (Def->isHidden()) { + if (!Def->isUnconditionallyVisible()) { // If MergedDef is visible or becomes visible, make the definition visible. - if (!MergedDef->isHidden()) + if (MergedDef->isUnconditionallyVisible()) Def->setVisibleDespiteOwningModule(); else { getContext().mergeDefinitionIntoModule( diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -6057,7 +6057,7 @@ void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { if (Chain && Chain->isProcessingUpdateRecords()) return; assert(!WritingAST && "Already writing the AST!"); - assert(D->isHidden() && "expected a hidden declaration"); + assert(!D->isUnconditionallyVisible() && "expected a hidden declaration"); DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); }