[SimplifyCFG] avoid crash on degenerate loop
authorSanjay Patel <spatel@rotateright.com>
Fri, 11 Jun 2021 13:33:32 +0000 (09:33 -0400)
committerSanjay Patel <spatel@rotateright.com>
Fri, 11 Jun 2021 13:37:06 +0000 (09:37 -0400)
commit602ab248335e1540e82667e74fea44b7f042e112
treece9b0e7dadaaac707881f21c1b464adf7a306a31
parent4295c222a8f12f0d97a7c03f884c5d3f7c93aaa0
[SimplifyCFG] avoid crash on degenerate loop

The problematic code pattern in the test is based on:
https://llvm.org/PR50638

If the IfCond is itself the phi that we are trying to remove,
then the loop around line 2835 can end up with something like:
%cmp = select i1 %cmp, i1 false, i1 true

That can then lead to a use-after-free and assert (although
I'm still not seeing that locally in my release + asserts build).

I think this can only happen with unreachable code.

Differential Revision: https://reviews.llvm.org/D104063
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/two-entry-phi-return.ll