]> granicus.if.org Git - llvm/commitdiff
Make MergeBlockIntoPredecessor conformant to the precondition of calling DTU.applyUpdates
authorChijun Sima <simachijun@gmail.com>
Thu, 28 Feb 2019 16:47:18 +0000 (16:47 +0000)
committerChijun Sima <simachijun@gmail.com>
Thu, 28 Feb 2019 16:47:18 +0000 (16:47 +0000)
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

lib/Transforms/Utils/BasicBlockUtils.cpp

index 0557b7d74426b9326f27d401db6b00f2e6fb23a6..81031b1a61e42f4f71c07632622a6d5254cab0a8 100644 (file)
@@ -186,7 +186,9 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
     Updates.push_back({DominatorTree::Delete, PredBB, BB});
     for (auto I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
       Updates.push_back({DominatorTree::Delete, BB, *I});
-      Updates.push_back({DominatorTree::Insert, PredBB, *I});
+      // This successor of BB may already have PredBB as a predecessor.
+      if (llvm::find(successors(PredBB), *I) == succ_end(PredBB))
+        Updates.push_back({DominatorTree::Insert, PredBB, *I});
     }
   }