This is an archive of the discontinued LLVM Phabricator instance.

[CodeExtractor] Fix iterator invalidation in findOrCreateBlockForHoisting.
ClosedPublic

Authored by fhahn on Oct 19 2017, 11:05 PM.

Details

Summary

By replacing branches to CommonExitBlock, we remove the node from
CommonExitBlock's predecessors, invalidating the iterator. The problem
is exposed when the common exit block has multiple predecessors and
needs to sink lifetime info. The modification in the test case trigger
the issue.

Diff Detail

Event Timeline

fhahn created this revision.Oct 19 2017, 11:05 PM
davidxl accepted this revision.Oct 31 2017, 9:41 AM

lgtm

lib/Transforms/Utils/CodeExtractor.cpp
312

Move ++ into the for clause?

This revision is now accepted and ready to land.Oct 31 2017, 9:41 AM
fhahn added inline comments.Oct 31 2017, 2:37 PM
lib/Transforms/Utils/CodeExtractor.cpp
312

I think we have to increment the iterator at the beginning of the loop, as replaceUsesOfWith may remove the element PI references and then the iterator would become invalid and Transforms/CodeExtractor/live_shrink_hoist.ll crashes.

fhahn closed this revision.Nov 1 2017, 2:48 AM
fhahn added a comment.Nov 1 2017, 2:48 AM

Thank you very much for having a look :)