This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix -Wreturn-type false positive in @try statements
ClosedPublic

Authored by thakis on Nov 26 2021, 7:01 PM.

Details

Reviewers
hans
Summary

After 04f30795f16638, -Wreturn-type has an effect on functions that
contain @try/@catch statements. CheckFallThrough() was missing
a case for ObjCAtTryStmts, leading to a false positive.

(What about the other two places in CheckFallThrough() that handle
CXXTryStmt but not ObjCAtTryStmts?

  • I think the last use of CXXTryStmt is dead in practice: 04c6851cd made it so that calls never add edges to try bodies, and the CFG block for a try statement is always an empty block containing just the try element itself as terminator (the try body itself is part of the normal flow of the function and not connected to the block for the try statement itself. The try statment cfg block is only connected to the catch bodies, and only reachable from throw expressions within the try body.)
  • The first use of CXXTryStmt might be important. It looks similar to the code that adds all cfg blocks for try statements as roots of the reachability graph for the reachability warnings, but I can't find a way to trigger it. So I'm omitting it for now. The CXXTryStmt code path seems to only be hit by try statements that are function bodies without a surrounding compound statements (f() try { ... } catch ...), and those don't exist for ObjC @try statements.

)

Fixes PR52473.

Diff Detail

Event Timeline

thakis requested review of this revision.Nov 26 2021, 7:01 PM
thakis created this revision.
hans accepted this revision.Nov 28 2021, 9:52 AM

lgtm

This revision is now accepted and ready to land.Nov 28 2021, 9:52 AM

For future self, related changes I looked at:

https://reviews.llvm.org/rG04c6851cd6053 (made it so that calls don't add edges to try cfg blocks)
https://reviews.llvm.org/rG33979f75a0fd8 (added -Wreturn-type in the first place)
https://reviews.llvm.org/rG0c2ec779cf680d22831de618b32c6aad626c0b89 (moved all this code around)
https://reviews.llvm.org/rG918fe8498dfd7 (moved all this code around again, to its current location)

thakis closed this revision.Nov 28 2021, 10:19 AM