[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations
arphaman created this revision. The unguarded availability warnings in the protocol requirements of a protocol/class/category declaration can be avoided. This matches the behaviour of Swift's diagnostics. Repository: rL LLVM https://reviews.llvm.org/D35061 Files: include/clang/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp test/SemaObjC/unguarded-availability.m Index: test/SemaObjC/unguarded-availability.m === --- test/SemaObjC/unguarded-availability.m +++ test/SemaObjC/unguarded-availability.m @@ -263,3 +263,27 @@ new_int x; // expected-warning{{'new_int' is partial}} }; } + +// rdar://33156429: +// Avoid the warning on protocol requirements. + +AVAILABLE_10_12 +@protocol NewProtocol // expected-note {{'NewProtocol' has been explicitly marked partial here}} +@end + +@protocol ProtocolWithNewProtocolRequirement // expected-note {{annotate 'ProtocolWithNewProtocolRequirement' with an availability attribute to silence}} + +@property(copy) id prop; // expected-warning {{'NewProtocol' is partial: introduced in macOS 10.12}} + +@end + +@interface BaseClass +@end + +@interface ClassWithNewProtocolRequirement : BaseClass + +@end + +@interface BaseClass (CategoryWithNewProtocolRequirement) + +@end Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -128,7 +128,8 @@ static void DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, - bool ObjCPropertyAccess) { + bool ObjCPropertyAccess, + bool AvoidAvailabilityChecks = false) { std::string Message; AvailabilityResult Result; const NamedDecl* OffendingDecl; @@ -138,6 +139,8 @@ return; if (Result == AR_NotYetIntroduced) { +if (AvoidAvailabilityChecks) + return; if (S.getCurFunctionOrMethodDecl()) { S.getEnclosingFunction()->HasPotentialAvailabilityViolations = true; return; @@ -275,7 +278,8 @@ /// bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, - bool ObjCPropertyAccess) { + bool ObjCPropertyAccess, + bool AvoidAvailabilityChecks) { if (getLangOpts().CPlusPlus && isa(D)) { // If there were any diagnostics suppressed by template argument deduction, // emit them now. @@ -360,7 +364,7 @@ } DiagnoseAvailabilityOfDecl(*this, D, Loc, UnknownObjCClass, - ObjCPropertyAccess); + ObjCPropertyAccess, AvoidAvailabilityChecks); DiagnoseUnusedOfDecl(*this, D, Loc); Index: lib/Sema/SemaDeclObjC.cpp === --- lib/Sema/SemaDeclObjC.cpp +++ lib/Sema/SemaDeclObjC.cpp @@ -458,7 +458,10 @@ // Diagnose availability in the context of the ObjC container. Sema::ContextRAII SavedContext(TheSema, CD); for (unsigned i = 0; i < NumProtoRefs; ++i) { -(void)TheSema.DiagnoseUseOfDecl(ProtoRefs[i], ProtoLocs[i]); +(void)TheSema.DiagnoseUseOfDecl(ProtoRefs[i], ProtoLocs[i], +/*UnknownObjCClass=*/nullptr, +/*ObjCPropertyAccess=*/false, +/*AvoidAvailabilityChecks=*/true); } } Index: include/clang/Sema/Sema.h === --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -3900,8 +3900,9 @@ bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, - const ObjCInterfaceDecl *UnknownObjCClass=nullptr, - bool ObjCPropertyAccess=false); + const ObjCInterfaceDecl *UnknownObjCClass = nullptr, + bool ObjCPropertyAccess = false, + bool AvoidAvailabilityChecks = false); void NoteDeletedFunction(FunctionDecl *FD); void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations
erik.pilkington added inline comments. Comment at: lib/Sema/SemaExpr.cpp:142 if (Result == AR_NotYetIntroduced) { +if (AvoidAvailabilityChecks) + return; Why are we doing this just for partials? Doesn't this also apply to unavailable/deprecated? Repository: rL LLVM https://reviews.llvm.org/D35061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations
arphaman added inline comments. Comment at: lib/Sema/SemaExpr.cpp:142 if (Result == AR_NotYetIntroduced) { +if (AvoidAvailabilityChecks) + return; erik.pilkington wrote: > Why are we doing this just for partials? Doesn't this also apply to > unavailable/deprecated? We warned about the unavailable/deprecated protocols previously, so we should probably keep these warnings. The unguarded availability one is new, so we can drop it. Repository: rL LLVM https://reviews.llvm.org/D35061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations
erik.pilkington added inline comments. Comment at: lib/Sema/SemaExpr.cpp:142 if (Result == AR_NotYetIntroduced) { +if (AvoidAvailabilityChecks) + return; arphaman wrote: > erik.pilkington wrote: > > Why are we doing this just for partials? Doesn't this also apply to > > unavailable/deprecated? > We warned about the unavailable/deprecated protocols previously, so we should > probably keep these warnings. The unguarded availability one is new, so we > can drop it. But this is strictly less diagnostics, dropping diagnostics for unavail/depr here won't break anything outside of clang tests. So if they don't make sense to emit, then there isn't any reason to keep them around. Repository: rL LLVM https://reviews.llvm.org/D35061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations
arphaman added inline comments. Comment at: lib/Sema/SemaExpr.cpp:142 if (Result == AR_NotYetIntroduced) { +if (AvoidAvailabilityChecks) + return; erik.pilkington wrote: > arphaman wrote: > > erik.pilkington wrote: > > > Why are we doing this just for partials? Doesn't this also apply to > > > unavailable/deprecated? > > We warned about the unavailable/deprecated protocols previously, so we > > should probably keep these warnings. The unguarded availability one is new, > > so we can drop it. > But this is strictly less diagnostics, dropping diagnostics for unavail/depr > here won't break anything outside of clang tests. So if they don't make sense > to emit, then there isn't any reason to keep them around. Swift emits warnings about deprecated/unavailable protocols even in the list of protocol requirements. I'd prefer it if we had the same behaviour. Repository: rL LLVM https://reviews.llvm.org/D35061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations
erik.pilkington accepted this revision. erik.pilkington added a comment. This revision is now accepted and ready to land. LGTM, thanks! Comment at: lib/Sema/SemaExpr.cpp:132 + bool ObjCPropertyAccess, + bool AvoidAvailabilityChecks = false) { std::string Message; `AvoidPartialAvailabilityChecks`? Comment at: lib/Sema/SemaExpr.cpp:142 if (Result == AR_NotYetIntroduced) { +if (AvoidAvailabilityChecks) + return; arphaman wrote: > erik.pilkington wrote: > > arphaman wrote: > > > erik.pilkington wrote: > > > > Why are we doing this just for partials? Doesn't this also apply to > > > > unavailable/deprecated? > > > We warned about the unavailable/deprecated protocols previously, so we > > > should probably keep these warnings. The unguarded availability one is > > > new, so we can drop it. > > But this is strictly less diagnostics, dropping diagnostics for > > unavail/depr here won't break anything outside of clang tests. So if they > > don't make sense to emit, then there isn't any reason to keep them around. > Swift emits warnings about deprecated/unavailable protocols even in the list > of protocol requirements. I'd prefer it if we had the same behaviour. OK, I agree that we should conform to what swift does here. Repository: rL LLVM https://reviews.llvm.org/D35061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35061: [ObjC] Avoid the -Wunguarded-availability warnings for protocol requirements in protocol/class/category declarations
This revision was automatically updated to reflect the committed changes. arphaman marked an inline comment as done. Closed by commit rL307368: [ObjC] Avoid the -Wunguarded-availability warnings for protocol (authored by arphaman). Changed prior to commit: https://reviews.llvm.org/D35061?vs=105442&id=105601#toc Repository: rL LLVM https://reviews.llvm.org/D35061 Files: cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Sema/SemaDeclObjC.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/SemaObjC/unguarded-availability.m Index: cfe/trunk/lib/Sema/SemaExpr.cpp === --- cfe/trunk/lib/Sema/SemaExpr.cpp +++ cfe/trunk/lib/Sema/SemaExpr.cpp @@ -128,7 +128,8 @@ static void DiagnoseAvailabilityOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, - bool ObjCPropertyAccess) { + bool ObjCPropertyAccess, + bool AvoidPartialAvailabilityChecks = false) { std::string Message; AvailabilityResult Result; const NamedDecl* OffendingDecl; @@ -138,6 +139,8 @@ return; if (Result == AR_NotYetIntroduced) { +if (AvoidPartialAvailabilityChecks) + return; if (S.getCurFunctionOrMethodDecl()) { S.getEnclosingFunction()->HasPotentialAvailabilityViolations = true; return; @@ -275,7 +278,8 @@ /// bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, - bool ObjCPropertyAccess) { + bool ObjCPropertyAccess, + bool AvoidPartialAvailabilityChecks) { if (getLangOpts().CPlusPlus && isa(D)) { // If there were any diagnostics suppressed by template argument deduction, // emit them now. @@ -360,7 +364,8 @@ } DiagnoseAvailabilityOfDecl(*this, D, Loc, UnknownObjCClass, - ObjCPropertyAccess); + ObjCPropertyAccess, + AvoidPartialAvailabilityChecks); DiagnoseUnusedOfDecl(*this, D, Loc); Index: cfe/trunk/lib/Sema/SemaDeclObjC.cpp === --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp @@ -458,7 +458,10 @@ // Diagnose availability in the context of the ObjC container. Sema::ContextRAII SavedContext(TheSema, CD); for (unsigned i = 0; i < NumProtoRefs; ++i) { -(void)TheSema.DiagnoseUseOfDecl(ProtoRefs[i], ProtoLocs[i]); +(void)TheSema.DiagnoseUseOfDecl(ProtoRefs[i], ProtoLocs[i], +/*UnknownObjCClass=*/nullptr, +/*ObjCPropertyAccess=*/false, +/*AvoidPartialAvailabilityChecks=*/true); } } Index: cfe/trunk/include/clang/Sema/Sema.h === --- cfe/trunk/include/clang/Sema/Sema.h +++ cfe/trunk/include/clang/Sema/Sema.h @@ -3900,8 +3900,9 @@ bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, - const ObjCInterfaceDecl *UnknownObjCClass=nullptr, - bool ObjCPropertyAccess=false); + const ObjCInterfaceDecl *UnknownObjCClass = nullptr, + bool ObjCPropertyAccess = false, + bool AvoidPartialAvailabilityChecks = false); void NoteDeletedFunction(FunctionDecl *FD); void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); Index: cfe/trunk/test/SemaObjC/unguarded-availability.m === --- cfe/trunk/test/SemaObjC/unguarded-availability.m +++ cfe/trunk/test/SemaObjC/unguarded-availability.m @@ -263,3 +263,27 @@ new_int x; // expected-warning{{'new_int' is partial}} }; } + +// rdar://33156429: +// Avoid the warning on protocol requirements. + +AVAILABLE_10_12 +@protocol NewProtocol // expected-note {{'NewProtocol' has been explicitly marked partial here}} +@end + +@protocol ProtocolWithNewProtocolRequirement // expected-note {{annotate 'ProtocolWithNewProtocolRequirement' with an availability attribute to silence}} + +@property(copy) id prop; // expected-warning {{'NewProtocol' is partial: introduced in macOS 10.12}} + +@end + +@interface BaseClass +@end + +@interface ClassWithNewProtocolRequirement : BaseClass + +@end + +@interface BaseClass (CategoryWithNewProtocolRequirement) + +@end ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits