Skip to content

Commit

Permalink
[SimplifyCFG] Sanity assert in iterativelySimplifyCFG
Browse files Browse the repository at this point in the history
We observe a hang within iterativelySimplifyCFG due to infinite
loop execution. Currently, there is no limit to this loop, so
in case of bug it just works forever. This patch adds an assert
that will break it after 1000 iterations if it didn't converge.
  • Loading branch information
xortator committed Oct 25, 2021
1 parent e6df795 commit a9b0776
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
Expand Up @@ -224,7 +224,11 @@ static bool iterativelySimplifyCFG(Function &F, const TargetTransformInfo &TTI,
SmallVector<WeakVH, 16> LoopHeaders(UniqueLoopHeaders.begin(),
UniqueLoopHeaders.end());

unsigned IterCnt = 0;
(void)IterCnt;
while (LocalChange) {
assert(IterCnt++ < 1000 &&
"Sanity: iterative simplification didn't converge!");
LocalChange = false;

// Loop over all of the basic blocks and remove them if they are unneeded.
Expand Down

0 comments on commit a9b0776

Please sign in to comment.