This is an archive of the discontinued LLVM Phabricator instance.

[ObjC] Avoid a @try/@finally/@autoreleasepool fixit when parsing an expression
ClosedPublic

Authored by arphaman on Nov 21 2016, 8:46 AM.

Details

Summary

This patch ensures that the typo fixit for the @try/@finally/@autoreleasepool { } directive is shown only when we're parsing an actual statement where such directives can actually be present.

Diff Detail

Repository
rL LLVM

Event Timeline

arphaman updated this revision to Diff 78728.Nov 21 2016, 8:46 AM
arphaman retitled this revision from to [ObjC] Avoid a @try/@finally/@autoreleasepool fixit when parsing an expression.
arphaman updated this object.
arphaman added reviewers: manmanren, bruno.
arphaman set the repository for this revision to rL LLVM.
arphaman added a subscriber: cfe-commits.
bruno edited edge metadata.Nov 28 2016, 12:59 PM

Hi Alex, thanks for working on this

lib/Parse/ParseObjc.cpp
2877 ↗(On Diff #78728)

Does this only triggers when Res.isInvalid() returns true in the first part of the patch? I wonder if it's also safe to allow ExprStatementTokLoc = AtLoc; for every path or only when it fails.

arphaman added inline comments.Nov 29 2016, 2:51 AM
lib/Parse/ParseObjc.cpp
2877 ↗(On Diff #78728)

Yes, this code will always flow to the body of the if with Res.isInvalid, but only after this code is executed, so we need to set ExprStatementTokLoc before the check for Res.isInvalid. As well as that, all users of ExprStatementTokLoc currently care only about the current location where the current statement is being parsed (they check to see if some expression location matches it), so it should be set before a method call like ParseExpressionWithLeadingAt, and it doesn't have to be cleared as the next statement will have a different location anyway. So it seems safe to set ExprStatementTokLoc = AtLoc as it follows the intended convention.

bruno accepted this revision.Nov 29 2016, 9:55 AM
bruno edited edge metadata.

Thanks for the explanation, LGTM

This revision is now accepted and ready to land.Nov 29 2016, 9:55 AM
This revision was automatically updated to reflect the committed changes.