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

Authored by erik.pilkington on Tue, May 16, 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

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

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.Wed, May 17, 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.Mon, May 22, 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.Mon, May 22, 6:57 AM
This revision was automatically updated to reflect the committed changes.