[PATCH] D25284: AvailabilityAttrs: Delay partial availability diagnostics
This revision was automatically updated to reflect the committed changes. Closed by commit rL285457: [Sema] Delay partial availability diagnostics, just like deprecated (authored by epilk). Changed prior to commit: https://reviews.llvm.org/D25284?vs=74738=76250#toc Repository: rL LLVM https://reviews.llvm.org/D25284 Files: cfe/trunk/include/clang/Sema/DelayedDiagnostic.h cfe/trunk/lib/Sema/DelayedDiagnostic.cpp cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/test/SemaObjC/unguarded-availability.m Index: cfe/trunk/test/SemaObjC/unguarded-availability.m === --- cfe/trunk/test/SemaObjC/unguarded-availability.m +++ cfe/trunk/test/SemaObjC/unguarded-availability.m @@ -63,7 +63,7 @@ #ifdef OBJCPP // expected-note@+2 {{marked partial here}} #endif -typedef int int_10_12 AVAILABLE_10_12; // expected-note 3 {{'int_10_12' has been explicitly marked partial here}} +typedef int int_10_12 AVAILABLE_10_12; // expected-note 2 {{'int_10_12' has been explicitly marked partial here}} void use_typedef() { int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}} @@ -127,8 +127,7 @@ void test_params(int_10_12 x); // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}} -// FIXME: This should be fine! -void test_params2(int_10_12 x) AVAILABLE_10_12; // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}} +void test_params2(int_10_12 x) AVAILABLE_10_12; // no warn #ifdef OBJCPP Index: cfe/trunk/lib/Sema/DelayedDiagnostic.cpp === --- cfe/trunk/lib/Sema/DelayedDiagnostic.cpp +++ cfe/trunk/lib/Sema/DelayedDiagnostic.cpp @@ -20,50 +20,41 @@ using namespace sema; DelayedDiagnostic -DelayedDiagnostic::makeAvailability(AvailabilityResult AD, +DelayedDiagnostic::makeAvailability(AvailabilityResult AR, SourceLocation Loc, const NamedDecl *D, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, StringRef Msg, bool ObjCPropertyAccess) { DelayedDiagnostic DD; - switch (AD) { - case AR_Deprecated: -DD.Kind = Deprecation; -break; - case AR_Unavailable: -DD.Kind = Unavailable; -break; - default: -llvm_unreachable("partial diags should not be delayed"); - } + DD.Kind = Availability; DD.Triggered = false; DD.Loc = Loc; - DD.DeprecationData.Decl = D; - DD.DeprecationData.UnknownObjCClass = UnknownObjCClass; - DD.DeprecationData.ObjCProperty = ObjCProperty; + DD.AvailabilityData.Decl = D; + DD.AvailabilityData.UnknownObjCClass = UnknownObjCClass; + DD.AvailabilityData.ObjCProperty = ObjCProperty; char *MessageData = nullptr; if (Msg.size()) { MessageData = new char [Msg.size()]; memcpy(MessageData, Msg.data(), Msg.size()); } - DD.DeprecationData.Message = MessageData; - DD.DeprecationData.MessageLen = Msg.size(); - DD.DeprecationData.ObjCPropertyAccess = ObjCPropertyAccess; + DD.AvailabilityData.Message = MessageData; + DD.AvailabilityData.MessageLen = Msg.size(); + DD.AvailabilityData.AR = AR; + DD.AvailabilityData.ObjCPropertyAccess = ObjCPropertyAccess; return DD; } void DelayedDiagnostic::Destroy() { - switch (static_cast(Kind)) { + switch (Kind) { case Access: getAccessData().~AccessedEntity(); break; - case Deprecation: - case Unavailable: -delete [] DeprecationData.Message; + case Availability: +delete[] AvailabilityData.Message; break; case ForbiddenType: Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp === --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp @@ -6510,9 +6510,6 @@ break; case AR_NotYetIntroduced: -assert(!S.getCurFunctionOrMethodDecl() && - "Function-level partial availablity should not be diagnosed here!"); - diag = diag::warn_partial_availability; diag_message = diag::warn_partial_message; diag_fwdclass_message = diag::warn_partial_fwdclass_message; @@ -6585,15 +6582,14 @@ static void handleDelayedAvailabilityCheck(Sema , DelayedDiagnostic , Decl *Ctx) { - assert(DD.Kind == DelayedDiagnostic::Deprecation || - DD.Kind == DelayedDiagnostic::Unavailable); - AvailabilityResult AR = DD.Kind == DelayedDiagnostic::Deprecation - ? AR_Deprecated - : AR_Unavailable; + assert(DD.Kind == DelayedDiagnostic::Availability && + "Expected an availability diagnostic
[PATCH] D25284: AvailabilityAttrs: Delay partial availability diagnostics
manmanren accepted this revision. manmanren added a comment. This revision is now accepted and ready to land. This is better than what I asked for :] Manman https://reviews.llvm.org/D25284 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25284: AvailabilityAttrs: Delay partial availability diagnostics
erik.pilkington updated this revision to Diff 74738. erik.pilkington added a comment. This new patch renames `DelayedDiagnostic::DeprecationData` to `DelayedDiagnostic::AvailabilityData`, because now that it can hold information about deprecated, unavailable, and partial diagnostics. Thanks, Erik https://reviews.llvm.org/D25284 Files: include/clang/Sema/DelayedDiagnostic.h lib/Sema/DelayedDiagnostic.cpp lib/Sema/SemaDeclAttr.cpp test/SemaObjC/unguarded-availability.m Index: test/SemaObjC/unguarded-availability.m === --- test/SemaObjC/unguarded-availability.m +++ test/SemaObjC/unguarded-availability.m @@ -63,7 +63,7 @@ #ifdef OBJCPP // expected-note@+2 {{marked partial here}} #endif -typedef int int_10_12 AVAILABLE_10_12; // expected-note 3 {{'int_10_12' has been explicitly marked partial here}} +typedef int int_10_12 AVAILABLE_10_12; // expected-note 2 {{'int_10_12' has been explicitly marked partial here}} void use_typedef() { int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}} @@ -127,8 +127,7 @@ void test_params(int_10_12 x); // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}} -// FIXME: This should be fine! -void test_params2(int_10_12 x) AVAILABLE_10_12; // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}} +void test_params2(int_10_12 x) AVAILABLE_10_12; // no warn #ifdef OBJCPP Index: lib/Sema/SemaDeclAttr.cpp === --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -6474,9 +6474,6 @@ break; case AR_NotYetIntroduced: -assert(!S.getCurFunctionOrMethodDecl() && - "Function-level partial availablity should not be diagnosed here!"); - diag = diag::warn_partial_availability; diag_message = diag::warn_partial_message; diag_fwdclass_message = diag::warn_partial_fwdclass_message; @@ -6549,15 +6546,14 @@ static void handleDelayedAvailabilityCheck(Sema , DelayedDiagnostic , Decl *Ctx) { - assert(DD.Kind == DelayedDiagnostic::Deprecation || - DD.Kind == DelayedDiagnostic::Unavailable); - AvailabilityResult AR = DD.Kind == DelayedDiagnostic::Deprecation - ? AR_Deprecated - : AR_Unavailable; + assert(DD.Kind == DelayedDiagnostic::Availability && + "Expected an availability diagnostic here"); + DD.Triggered = true; DoEmitAvailabilityWarning( - S, AR, Ctx, DD.getDeprecationDecl(), DD.getDeprecationMessage(), DD.Loc, - DD.getUnknownObjCClass(), DD.getObjCProperty(), false); + S, DD.getAvailabilityResult(), Ctx, DD.getAvailabilityDecl(), + DD.getAvailabilityMessage(), DD.Loc, DD.getUnknownObjCClass(), + DD.getObjCProperty(), false); } void Sema::PopParsingDeclaration(ParsingDeclState state, Decl *decl) { @@ -6587,8 +6583,7 @@ continue; switch (diag.Kind) { - case DelayedDiagnostic::Deprecation: - case DelayedDiagnostic::Unavailable: + case DelayedDiagnostic::Availability: // Don't bother giving deprecation/unavailable diagnostics if // the decl is invalid. if (!decl->isInvalidDecl()) @@ -6623,8 +6618,7 @@ const ObjCPropertyDecl *ObjCProperty, bool ObjCPropertyAccess) { // Delay if we're currently parsing a declaration. - if (DelayedDiagnostics.shouldDelayDiagnostics() && - AR != AR_NotYetIntroduced) { + if (DelayedDiagnostics.shouldDelayDiagnostics()) { DelayedDiagnostics.add(DelayedDiagnostic::makeAvailability( AR, Loc, D, UnknownObjCClass, ObjCProperty, Message, ObjCPropertyAccess)); Index: lib/Sema/DelayedDiagnostic.cpp === --- lib/Sema/DelayedDiagnostic.cpp +++ lib/Sema/DelayedDiagnostic.cpp @@ -20,50 +20,41 @@ using namespace sema; DelayedDiagnostic -DelayedDiagnostic::makeAvailability(AvailabilityResult AD, +DelayedDiagnostic::makeAvailability(AvailabilityResult AR, SourceLocation Loc, const NamedDecl *D, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, StringRef Msg, bool ObjCPropertyAccess) { DelayedDiagnostic DD; - switch (AD) { - case AR_Deprecated: -DD.Kind = Deprecation; -break; - case AR_Unavailable: -DD.Kind = Unavailable; -break; - default: -llvm_unreachable("partial diags should not be delayed"); - } + DD.Kind =
[PATCH] D25284: AvailabilityAttrs: Delay partial availability diagnostics
manmanren added a comment. Nice cleanup! Thanks for working on this, Manman Comment at: include/clang/Sema/DelayedDiagnostic.h:232 union { /// Deprecation struct DD DeprecationData; Can you update this comment now we have generalized this to handle all delayed availability checks? https://reviews.llvm.org/D25284 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25284: AvailabilityAttrs: Delay partial availability diagnostics
erik.pilkington created this revision. erik.pilkington added a reviewer: manmanren. erik.pilkington added a subscriber: cfe-commits. Note: this patch depends on: https://reviews.llvm.org/D25283 This patch delays handling of `AR_NotYetIntroduced` diagnostics, so that the following compiles with no warnings: typedef int new_int __attribute__((availability(macos, introduced=100))); new_int f() __attribute__((availability(macos, introduced=100))); This is done by treating `AR_NotYetIntroduced` diagnostics as delayed, just like `AR_Unavailable` and `AR_Deprecated`. This means that we emit the diagnostic once we finished parsing `f()`, at which point we have the context to determine if we should diagnose `new_int`. Thanks! https://reviews.llvm.org/D25284 Files: include/clang/Sema/DelayedDiagnostic.h lib/Sema/DelayedDiagnostic.cpp lib/Sema/SemaDeclAttr.cpp test/SemaObjC/unguarded-availability.m Index: test/SemaObjC/unguarded-availability.m === --- test/SemaObjC/unguarded-availability.m +++ test/SemaObjC/unguarded-availability.m @@ -63,7 +63,7 @@ #ifdef OBJCPP // expected-note@+2 {{marked partial here}} #endif -typedef int int_10_12 AVAILABLE_10_12; // expected-note 3 {{'int_10_12' has been explicitly marked partial here}} +typedef int int_10_12 AVAILABLE_10_12; // expected-note 2 {{'int_10_12' has been explicitly marked partial here}} void use_typedef() { int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}} @@ -127,8 +127,7 @@ void test_params(int_10_12 x); // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}} -// FIXME: This should be fine! -void test_params2(int_10_12 x) AVAILABLE_10_12; // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}} +void test_params2(int_10_12 x) AVAILABLE_10_12; // no warn #ifdef OBJCPP Index: lib/Sema/SemaDeclAttr.cpp === --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -6464,9 +6464,6 @@ break; case AR_NotYetIntroduced: -assert(!S.getCurFunctionOrMethodDecl() && - "Function-level partial availablity should not be diagnosed here!"); - diag = diag::warn_partial_availability; diag_message = diag::warn_partial_message; diag_fwdclass_message = diag::warn_partial_fwdclass_message; @@ -6539,15 +6536,14 @@ static void handleDelayedAvailabilityCheck(Sema , DelayedDiagnostic , Decl *Ctx) { - assert(DD.Kind == DelayedDiagnostic::Deprecation || - DD.Kind == DelayedDiagnostic::Unavailable); - AvailabilityResult AR = DD.Kind == DelayedDiagnostic::Deprecation - ? AR_Deprecated - : AR_Unavailable; + assert(DD.Kind == DelayedDiagnostic::Availability && + "Expected an availability diagnostic here"); + DD.Triggered = true; - DoEmitAvailabilityWarning( - S, AR, Ctx, DD.getDeprecationDecl(), DD.getDeprecationMessage(), DD.Loc, - DD.getUnknownObjCClass(), DD.getObjCProperty(), false); + DoEmitAvailabilityWarning(S, DD.getAvailabilityResult(), Ctx, +DD.getDeprecationDecl(), DD.getDeprecationMessage(), +DD.Loc, DD.getUnknownObjCClass(), +DD.getObjCProperty(), false); } void Sema::PopParsingDeclaration(ParsingDeclState state, Decl *decl) { @@ -6577,8 +6573,7 @@ continue; switch (diag.Kind) { - case DelayedDiagnostic::Deprecation: - case DelayedDiagnostic::Unavailable: + case DelayedDiagnostic::Availability: // Don't bother giving deprecation/unavailable diagnostics if // the decl is invalid. if (!decl->isInvalidDecl()) @@ -6613,8 +6608,7 @@ const ObjCPropertyDecl *ObjCProperty, bool ObjCPropertyAccess) { // Delay if we're currently parsing a declaration. - if (DelayedDiagnostics.shouldDelayDiagnostics() && - AR != AR_NotYetIntroduced) { + if (DelayedDiagnostics.shouldDelayDiagnostics()) { DelayedDiagnostics.add(DelayedDiagnostic::makeAvailability( AR, Loc, D, UnknownObjCClass, ObjCProperty, Message, ObjCPropertyAccess)); Index: lib/Sema/DelayedDiagnostic.cpp === --- lib/Sema/DelayedDiagnostic.cpp +++ lib/Sema/DelayedDiagnostic.cpp @@ -20,24 +20,15 @@ using namespace sema; DelayedDiagnostic -DelayedDiagnostic::makeAvailability(AvailabilityResult AD, +DelayedDiagnostic::makeAvailability(AvailabilityResult AR, SourceLocation Loc, const NamedDecl *D,