From 333403abbda5722724025cda1f8f52ef36d31505 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Fri, 3 May 2013 15:48:34 +0000 Subject: [PATCH] RegionInfo: Do not crash if unreachable block is found git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181025 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/RegionInfo.cpp | 3 ++- test/Analysis/RegionInfo/unreachable_bb.ll | 29 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/Analysis/RegionInfo/unreachable_bb.ll diff --git a/lib/Analysis/RegionInfo.cpp b/lib/Analysis/RegionInfo.cpp index 81ef6505e61..857702570f2 100644 --- a/lib/Analysis/RegionInfo.cpp +++ b/lib/Analysis/RegionInfo.cpp @@ -114,7 +114,8 @@ void Region::replaceExitRecursive(BasicBlock *NewExit) { bool Region::contains(const BasicBlock *B) const { BasicBlock *BB = const_cast(B); - assert(DT->getNode(BB) && "BB not part of the dominance tree"); + if (!DT->getNode(BB)) + return false; BasicBlock *entry = getEntry(), *exit = getExit(); diff --git a/test/Analysis/RegionInfo/unreachable_bb.ll b/test/Analysis/RegionInfo/unreachable_bb.ll new file mode 100644 index 00000000000..626ccbe304c --- /dev/null +++ b/test/Analysis/RegionInfo/unreachable_bb.ll @@ -0,0 +1,29 @@ +; RUN: opt -regions -analyze < %s | FileCheck %s + +; We should not crash if there are some bbs that are not reachable. +define void @f() { +entry: + br label %for.pre + +notintree: ; No predecessors! + br label %ret + +for.pre: ; preds = %entry + br label %for + +for: ; preds = %for.inc, %for.pre + %indvar = phi i64 [ 0, %for.pre ], [ %indvar.next, %for.inc ] + %exitcond = icmp ne i64 %indvar, 200 + br i1 %exitcond, label %for.inc, label %ret + +for.inc: ; preds = %for + %indvar.next = add i64 %indvar, 1 + br label %for + +ret: ; preds = %for, %notintree + ret void +} + +; CHECK: [0] entry => +; CHECK: [1] for => ret +