This is an archive of the discontinued LLVM Phabricator instance.

Make dead return statement detection more robust against changes in the CFG.
ClosedPublic

Authored by klimek on May 7 2014, 3:08 AM.

Details

Summary

This change is a precondition to the proposed change
http://reviews.llvm.org/D3627. I think it's also generally helpful, as it
reduces the number of invariants of the CFG this code relies on.

The idea is to explicitly search for the next return that doesn't have other
paths into it (that is, if the current block is dead, the block containing the
return must be dead, too).

Diff Detail

Event Timeline

klimek updated this revision to Diff 9151.May 7 2014, 3:08 AM
klimek updated this revision to Diff 9152.
klimek retitled this revision from to Make dead return statement detection more robust against changes in the CFG..
klimek updated this object.
klimek edited the test plan for this revision. (Show Details)
klimek added reviewers: jordan_rose, krememek.
klimek added subscribers: alexmc, Unknown Object (MLST).

Wordsmithing.

jordan_rose added inline comments.May 21 2014, 8:34 PM
lib/Analysis/ReachableCode.cpp
84

If the block does contain a statement, and it's not a return, then we don't want to keep searching, do we?

klimek added inline comments.May 22 2014, 3:35 AM
lib/Analysis/ReachableCode.cpp
84

Why? As long as the statement doesn't add control flow, the next return statement would still be dead, and we'd want to warn on the dead return instead (at least that's how I understood what we're trying to do here :)

jordan_rose accepted this revision.May 22 2014, 9:42 AM
jordan_rose edited edge metadata.

Okay, I think I understand now. If the first dead statement is the first expression in a return statement, and then there's a temporary destructors block, and then the return statement, then we'd still want to treat that as part of the return statement. And that happens right now because we don't optimize out the case with no control flow.

I'm worried, though, that this will catch something in a dead else block and go sailing off the end to look for a return statement, build a parent map, and then not actually find anything (of course). It seems like a fair amount of extra work. Then again, we have already decided to emit a diagnostic at this point, so I guess it's okay.

This revision is now accepted and ready to land.May 22 2014, 9:42 AM

Just saw that you "accepted" this in phab together with your "so I guess
it's okay" comment ;)

Submitted as r209531.

klimek closed this revision.May 23 2014, 10:17 AM