This is an archive of the discontinued LLVM Phabricator instance.

[PartialInliner] Fix crash when inlining functions with unreachable blocks
ClosedPublic

Authored by davide on Apr 20 2017, 8:36 PM.

Details

Summary

CodeExtractor looks up the dominator node corresponding to return blocks when splitting them. If one of these blocks is unreachable, there's no node in the Dom and CodeExtractor crashes because it doesn't check for domtree node validity.
In theory, we could add just a check for skipping DTNode == nullptr in splitReturnBlock but the fix I propose here is slightly different. To the best of my knowledge, unreachable blocks are irrelevant for the algorithm, therefore we can just skip them when building the candidate set in the constructor.
I'm not 100% sure if any pass using CodeExtractor could make use of extracting an unreachable block (including bugpoint), in which case my fix would need to be adjusted.

Diff Detail

Event Timeline

davide created this revision.Apr 20 2017, 8:36 PM
davidxl accepted this revision.Apr 20 2017, 9:12 PM

The root cause of the problem is that the partial inliner split the newreturn block unconditionally -- even when there is no PHIs in them (creating unreachable block). I have included that fix in my patch, but this patch is fine too.

lgtm

This revision is now accepted and ready to land.Apr 20 2017, 9:12 PM
chandlerc accepted this revision.Apr 20 2017, 9:17 PM
chandlerc added a subscriber: chandlerc.

LGTM as well -- no sense doing anything with the unreachable blocks.

This revision was automatically updated to reflect the committed changes.