mboehme created this revision. mboehme added a reviewer: rsmith. mboehme added a project: clang. Herald added a subscriber: cfe-commits.
For context, see https://bugs.llvm.org/show_bug.cgi?id=46248 This handles only the easy cases in Sema/SemaDeclObjC.cpp. The cases in AST/DeclObjC.{h,cpp} will require much more work, but there's no reason not to get the easy work out of the way now. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D81732 Files: clang/lib/Sema/SemaDeclObjC.cpp Index: clang/lib/Sema/SemaDeclObjC.cpp =================================================================== --- clang/lib/Sema/SemaDeclObjC.cpp +++ clang/lib/Sema/SemaDeclObjC.cpp @@ -1270,16 +1270,16 @@ return ActOnObjCContainerStartDefinition(PDecl); } -static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl, - ObjCProtocolDecl *&UndefinedProtocol) { - if (!PDecl->hasDefinition() || - !PDecl->getDefinition()->isUnconditionallyVisible()) { +static bool +NestedProtocolHasNoDefinition(Sema &SemaRef, ObjCProtocolDecl *PDecl, + ObjCProtocolDecl *&UndefinedProtocol) { + if (!PDecl->hasDefinition() || !SemaRef.isVisible(PDecl->getDefinition())) { UndefinedProtocol = PDecl; return true; } for (auto *PI : PDecl->protocols()) - if (NestedProtocolHasNoDefinition(PI, UndefinedProtocol)) { + if (NestedProtocolHasNoDefinition(SemaRef, PI, UndefinedProtocol)) { UndefinedProtocol = PI; return true; } @@ -1325,7 +1325,7 @@ ObjCProtocolDecl *UndefinedProtocol; if (WarnOnDeclarations && - NestedProtocolHasNoDefinition(PDecl, UndefinedProtocol)) { + NestedProtocolHasNoDefinition(*this, PDecl, UndefinedProtocol)) { Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first; Diag(UndefinedProtocol->getLocation(), diag::note_protocol_decl_undefined) << UndefinedProtocol; @@ -1461,7 +1461,7 @@ // FIXME: Recover nicely in the hidden case. ObjCProtocolDecl *forwardDecl = nullptr; if (warnOnIncompleteProtocols && - NestedProtocolHasNoDefinition(proto, forwardDecl)) { + NestedProtocolHasNoDefinition(*this, proto, forwardDecl)) { Diag(identifierLocs[i], diag::warn_undef_protocolref) << proto->getDeclName(); Diag(forwardDecl->getLocation(), diag::note_protocol_decl_undefined) @@ -3236,7 +3236,7 @@ return false; // If either is hidden, it is not considered to match. - if (!left->isUnconditionallyVisible() || !right->isUnconditionallyVisible()) + if (!isVisible(left) || !isVisible(right)) return false; if (left->isDirectMethod() != right->isDirectMethod()) @@ -3495,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()->isUnconditionallyVisible()) { + if (M->getMethod() && isVisible(M->getMethod())) { if (FilterMethodsByTypeBound(M->getMethod(), TypeBound)) Methods.push_back(M->getMethod()); } @@ -3511,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()->isUnconditionallyVisible()) { + if (M->getMethod() && isVisible(M->getMethod())) { if (FilterMethodsByTypeBound(M->getMethod(), TypeBound)) Methods.push_back(M->getMethod()); } @@ -3558,7 +3558,7 @@ ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second; SmallVector<ObjCMethodDecl *, 4> Methods; for (ObjCMethodList *M = &MethList; M; M = M->getNext()) { - if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) + if (M->getMethod() && isVisible(M->getMethod())) return M->getMethod(); } return nullptr;
Index: clang/lib/Sema/SemaDeclObjC.cpp =================================================================== --- clang/lib/Sema/SemaDeclObjC.cpp +++ clang/lib/Sema/SemaDeclObjC.cpp @@ -1270,16 +1270,16 @@ return ActOnObjCContainerStartDefinition(PDecl); } -static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl, - ObjCProtocolDecl *&UndefinedProtocol) { - if (!PDecl->hasDefinition() || - !PDecl->getDefinition()->isUnconditionallyVisible()) { +static bool +NestedProtocolHasNoDefinition(Sema &SemaRef, ObjCProtocolDecl *PDecl, + ObjCProtocolDecl *&UndefinedProtocol) { + if (!PDecl->hasDefinition() || !SemaRef.isVisible(PDecl->getDefinition())) { UndefinedProtocol = PDecl; return true; } for (auto *PI : PDecl->protocols()) - if (NestedProtocolHasNoDefinition(PI, UndefinedProtocol)) { + if (NestedProtocolHasNoDefinition(SemaRef, PI, UndefinedProtocol)) { UndefinedProtocol = PI; return true; } @@ -1325,7 +1325,7 @@ ObjCProtocolDecl *UndefinedProtocol; if (WarnOnDeclarations && - NestedProtocolHasNoDefinition(PDecl, UndefinedProtocol)) { + NestedProtocolHasNoDefinition(*this, PDecl, UndefinedProtocol)) { Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first; Diag(UndefinedProtocol->getLocation(), diag::note_protocol_decl_undefined) << UndefinedProtocol; @@ -1461,7 +1461,7 @@ // FIXME: Recover nicely in the hidden case. ObjCProtocolDecl *forwardDecl = nullptr; if (warnOnIncompleteProtocols && - NestedProtocolHasNoDefinition(proto, forwardDecl)) { + NestedProtocolHasNoDefinition(*this, proto, forwardDecl)) { Diag(identifierLocs[i], diag::warn_undef_protocolref) << proto->getDeclName(); Diag(forwardDecl->getLocation(), diag::note_protocol_decl_undefined) @@ -3236,7 +3236,7 @@ return false; // If either is hidden, it is not considered to match. - if (!left->isUnconditionallyVisible() || !right->isUnconditionallyVisible()) + if (!isVisible(left) || !isVisible(right)) return false; if (left->isDirectMethod() != right->isDirectMethod()) @@ -3495,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()->isUnconditionallyVisible()) { + if (M->getMethod() && isVisible(M->getMethod())) { if (FilterMethodsByTypeBound(M->getMethod(), TypeBound)) Methods.push_back(M->getMethod()); } @@ -3511,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()->isUnconditionallyVisible()) { + if (M->getMethod() && isVisible(M->getMethod())) { if (FilterMethodsByTypeBound(M->getMethod(), TypeBound)) Methods.push_back(M->getMethod()); } @@ -3558,7 +3558,7 @@ ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second; SmallVector<ObjCMethodDecl *, 4> Methods; for (ObjCMethodList *M = &MethList; M; M = M->getNext()) { - if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) + if (M->getMethod() && isVisible(M->getMethod())) return M->getMethod(); } return nullptr;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits