[PATCH] D60082: Not all blocks are reachable from entry. Don't assume they are.
Nick Lewycky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 1 11:41:08 PDT 2019
nicholas created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Fixes a bug in isPotentiallyReachable, noticed by inspection.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D60082
Files:
llvm/lib/Analysis/CFG.cpp
llvm/unittests/Analysis/CFGTest.cpp
Index: llvm/unittests/Analysis/CFGTest.cpp
===================================================================
--- llvm/unittests/Analysis/CFGTest.cpp
+++ llvm/unittests/Analysis/CFGTest.cpp
@@ -385,3 +385,43 @@
S[0] = OldBB;
ExpectPath(true);
}
+
+TEST_F(IsPotentiallyReachableTest, UnreachableFromEntryTest) {
+ ParseAssembly("define void @test() {\n"
+ "entry:\n"
+ " %A = bitcast i8 undef to i8\n"
+ " ret void\n"
+ "not.reachable:\n"
+ " %B = bitcast i8 undef to i8\n"
+ " ret void\n"
+ "}");
+ ExpectPath(false);
+}
+
+TEST_F(IsPotentiallyReachableTest, UnreachableBlocksTest1) {
+ ParseAssembly("define void @test() {\n"
+ "entry:\n"
+ " ret void\n"
+ "not.reachable.1:\n"
+ " %A = bitcast i8 undef to i8\n"
+ " br label %not.reachable.2\n"
+ "not.reachable.2:\n"
+ " %B = bitcast i8 undef to i8\n"
+ " ret void\n"
+ "}");
+ ExpectPath(true);
+}
+
+TEST_F(IsPotentiallyReachableTest, UnreachableBlocksTest2) {
+ ParseAssembly("define void @test() {\n"
+ "entry:\n"
+ " ret void\n"
+ "not.reachable.1:\n"
+ " %B = bitcast i8 undef to i8\n"
+ " br label %not.reachable.2\n"
+ "not.reachable.2:\n"
+ " %A = bitcast i8 undef to i8\n"
+ " ret void\n"
+ "}");
+ ExpectPath(false);
+}
Index: llvm/lib/Analysis/CFG.cpp
===================================================================
--- llvm/lib/Analysis/CFG.cpp
+++ llvm/lib/Analysis/CFG.cpp
@@ -226,10 +226,17 @@
Worklist.push_back(const_cast<BasicBlock*>(A->getParent()));
}
- if (A->getParent() == &A->getParent()->getParent()->getEntryBlock())
- return true;
- if (B->getParent() == &A->getParent()->getParent()->getEntryBlock())
- return false;
+ if (DT) {
+ if (DT->isReachableFromEntry(A->getParent()) !=
+ DT->isReachableFromEntry(B->getParent()))
+ return false;
+ if (A->getParent() == &A->getParent()->getParent()->getEntryBlock() &&
+ DT->isReachableFromEntry(B->getParent()))
+ return true;
+ if (B->getParent() == &A->getParent()->getParent()->getEntryBlock() &&
+ DT->isReachableFromEntry(A->getParent()))
+ return false;
+ }
return isPotentiallyReachableFromMany(
Worklist, const_cast<BasicBlock *>(B->getParent()), DT, LI);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60082.193141.patch
Type: text/x-patch
Size: 2574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190401/d0dadca3/attachment.bin>
More information about the llvm-commits
mailing list