This is an archive of the discontinued LLVM Phabricator instance.

[Sema][ObjC] Fix a bug where -Wunguarded-availability was emitted at the wrong location
ClosedPublic

Authored by erik.pilkington on May 16 2017, 11:17 AM.

Details

Summary

Previously, we used TypeLocs to find the correct SourceLocations to emit -Wunguarded-availability. Unfortunately, TypeLocs can't be trusted as they sometimes have an an empty SourceLocation component. This new patch maintains the enclosing SourceLocation to be used instead.
Thanks for taking a look,
Erik

Diff Detail

Repository
rL LLVM

Event Timeline

Just noticed this can be simplified a bit, NFC compared to the last version of the diff.

arphaman edited edge metadata.May 17 2017, 9:11 AM

Hmm, I don't like how we end with a location that points to x instead of InterWithProp. Can we ignore the TypeLocs with invalid location and instead look at ObjCPropertyRefExprs with a class receiver?

arphaman added inline comments.May 17 2017, 9:17 AM
test/SemaObjC/unguarded-availability.m
141 ↗(On Diff #99235)

Should this be @property(class)?

Can we ignore the TypeLocs with invalid location and instead look at ObjCPropertyRefExprs with a class receiver?

Sure, good idea. This new patch does exactly that.

Thanks,
Erik

arphaman accepted this revision.May 22 2017, 6:57 AM

LGTM with one change below:

lib/Sema/SemaDeclAttr.cpp
7256 ↗(On Diff #99605)

getClassReceiver calls get in a PointerUnion, which will trigger an assertion when the PRE is not a class receiver. Please rewrite this if to something like:

if (PRE->isClassReceiver())
  DiagnoseDeclAvailability(PRE->getClassReceiver(), PRE->getReceiverLocation());
This revision is now accepted and ready to land.May 22 2017, 6:57 AM
This revision was automatically updated to reflect the committed changes.