This is an archive of the discontinued LLVM Phabricator instance.

[Sema][ObjC] Don't allow -Wunguarded-availability to be silenced with redeclarations
ClosedPublic

Authored by erik.pilkington on Jun 1 2017, 6:14 PM.

Details

Summary

This patch drops support for suppressing -Wunguarded-availability with redeclarations. This was behavior left over from the -Wpartial-availability days, where it was the only way of silencing the diagnostic. Now that we have @available and better support for annotating contexts with availability attributes, this behavior should be dropped.
This would emit warnings on code that used the old way of silencing the diagnostic, but this method:

  • Didn't have many users; it was clunky to use
  • Has a simple upgrade path that is mentioned in the diagnostics we emit
  • Allows for availability violations to go undetected

@thakis: I know the chromium project uses this warning, is this OK with you?

rdar://32388777

Thanks for taking a look,
Erik

Diff Detail

Repository
rL LLVM

Event Timeline

erik.pilkington created this revision.Jun 1 2017, 6:14 PM
arphaman edited edge metadata.Jun 16 2017, 1:53 PM

I find the change to the diagnostic for enum constants a bit off putting, since the warning can refer to the enum itself when an enum constant is used. I'd rather we say something like 'EnumConstant' is deprecated and keep the note that this patch uses ('Enum' has been explicitly marked deprecated here).

lib/Sema/SemaDeclAttr.cpp
7077 ↗(On Diff #101152)

You can use const auto * here.

lib/Sema/SemaExpr.cpp
115 ↗(On Diff #101152)

You can use auto * here.

118 ↗(On Diff #101152)

You can use auto * here as well.

Improve enum diagnostics, as @arphaman suggested. This causes a bit of churn throughout the availability diagnostic machinery, if it would make it at all easier to review, I would be happy to separate out these changes.
Thanks,
Erik

arphaman added a comment.EditedJun 26 2017, 3:00 AM

I don't think the new warning is ideal, e.g.:

#import <Cocoa/Cocoa.h>

__attribute__((visibility("default"))) __attribute__((availability(macosx,introduced=10_10)))
@interface Test : NSObject

@end

Test *testVar;

Results in:

test.m:13:1: warning: 'Test' is partial: introduced in macOS 10.10 [-Wunguarded-availability]
Test *testVar;
^
test.m:6:12: note: 'Test' has been explicitly marked partial here
@interface Test : NSObject
           ^
test.m:13:7: note: annotate 'Test' with an availability attribute to silence
Test *testVar;
      ^

We are telling the user to annotate the class 'Test' with an availability attribute, but that class is already annotated with the attribute in the framework!
We should either refer to the testVar declaration, or say something like annotate the declaration that uses 'Test' ......

Make the diagnostic reference the context declaration instead of the offending decl if no enclosing decl is found, fixing the diagnostic bug @arphaman pointed out.

arphaman added inline comments.Jun 26 2017, 9:03 AM
test/SemaObjC/unguarded-availability.m
243 ↗(On Diff #103958)

We should never have something like annotate '' presented to the user. This should be worded like 'annotate enclosing struct ...' .

Improve diagnostics for unnamed types.

arphaman accepted this revision.Jun 29 2017, 2:13 AM

LGTM. One last comment below:

include/clang/Basic/DiagnosticSemaKinds.td
2880 ↗(On Diff #104437)

I think that you can just use one note and select the text, e.g.

def note_partial_availability_silence : Note<
  "annotate %select{%1|anonymous %0}0 with an availability attribute to silence">;

And use it like:

enum class PartialAvailabilityNoteKind {
  Named,
  Anonymous
};

...

    S.Diag(Enclosing->getLocation(), diag::note_partial_availability_silence)
          <<  PartialAvailabilityNoteKind::Named << Enclosing;
This revision is now accepted and ready to land.Jun 29 2017, 2:13 AM
This revision was automatically updated to reflect the committed changes.