This is an archive of the discontinued LLVM Phabricator instance.

Utils: Fix DomTree update for entry block
ClosedPublic

Authored by arsenm on Jan 22 2018, 7:10 PM.

Details

Summary

If SplitBlockPredecessors was used on a function entry block,
it wouldn't update the dominator tree.

Diff Detail

Event Timeline

arsenm created this revision.Jan 22 2018, 7:10 PM
kuhar added inline comments.Jan 22 2018, 7:52 PM
lib/Transforms/Utils/BasicBlockUtils.cpp
513

Shouldn't this be handled in UpdateAnalysisInformation?
I think that it would also make sense to assert that BB used to be the first BB in the function -- this would only fire when someone passed in an already incorrect DomTree. Otherwise, this can hide this kind of bugs.

We should also try to get this fix into 6.0, the surrounding lines are not new. In fact, they were last modified 9-10 years ago. I wonder why it stayed unnoticed for so long.

davide added inline comments.Jan 23 2018, 7:51 AM
lib/Transforms/Utils/BasicBlockUtils.cpp
513

agree with Kuba

I too am curious how this managed to not be found for several years. @arsenm how did you discover this?

arsenm updated this revision to Diff 131089.Jan 23 2018, 8:45 AM

Move into UpdateAnalysisInformation and add assert

I too am curious how this managed to not be found for several years. @arsenm how did you discover this?

I'm working on a replacement for StructurizeCFG which needs to insert a block before certain blocks. Sometimes that ends up picking the entry block

brzycki accepted this revision.Jan 23 2018, 10:54 AM

I too am curious how this managed to not be found for several years. @arsenm how did you discover this?

I'm working on a replacement for StructurizeCFG which needs to insert a block before certain blocks. Sometimes that ends up picking the entry block

Thanks @arsenm for the explanation. I was curious to know if you found this with a specific .c/.cpp file or if it was from changing the middle-end. The latter makes a lot more sense to discover a latent bug like this.

LGTM.

This revision is now accepted and ready to land.Jan 23 2018, 10:54 AM
kuhar added inline comments.Jan 23 2018, 11:07 AM
lib/Transforms/Utils/BasicBlockUtils.cpp
324

Can you also add a comment explaining why we need this special case here? I think the reason is that DT.splitBlock expects NewBB to have a non-empty set of predecessors.

327

Without the patch, was the crash happening inside Split in GenericDomTree.h? If it doesn't support it, maybe it would make sense to assert in DT->split that NewBB != getRootNode() for (forward) dominators?

I too am curious how this managed to not be found for several years. @arsenm how did you discover this?

I'm working on a replacement for StructurizeCFG which needs to insert a block before certain blocks. Sometimes that ends up picking the entry block

lib/Transforms/Utils/BasicBlockUtils.cpp
327

It was hitting
Assertion failed: (!PredBlocks.empty() && "No predblocks?"), function Split, file ../include/llvm/Support/GenericDomTree.h, line 808.

arsenm closed this revision.Jan 31 2018, 2:56 PM

r323928