Skip to content

Commit 86ddb2a

Browse files
committed
Make MergeBlockIntoPredecessor conformant to the precondition of calling DTU.applyUpdates
Summary: It is mentioned in the document of DTU that "It is illegal to submit any update that has already been submitted, i.e., you are supposed not to insert an existent edge or delete a nonexistent edge." It is dangerous to violet this rule because DomTree and PostDomTree occasionally crash on this scenario. This patch fixes `MergeBlockIntoPredecessor`, making it conformant to this precondition. Reviewers: kuhar, brzycki, chandlerc Reviewed By: brzycki Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58444 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355105 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 29724e2 commit 86ddb2a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
186186
Updates.push_back({DominatorTree::Delete, PredBB, BB});
187187
for (auto I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
188188
Updates.push_back({DominatorTree::Delete, BB, *I});
189-
Updates.push_back({DominatorTree::Insert, PredBB, *I});
189+
// This successor of BB may already have PredBB as a predecessor.
190+
if (llvm::find(successors(PredBB), *I) == succ_end(PredBB))
191+
Updates.push_back({DominatorTree::Insert, PredBB, *I});
190192
}
191193
}
192194

0 commit comments

Comments
 (0)