[llvm] r357425 - Not all blocks are reachable from entry. Don't assume they are.
Nick Lewycky via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 1 13:03:17 PDT 2019
Author: nicholas
Date: Mon Apr 1 13:03:16 2019
New Revision: 357425
URL: http://llvm.org/viewvc/llvm-project?rev=357425&view=rev
Log:
Not all blocks are reachable from entry. Don't assume they are.
Fixes a bug in isPotentiallyReachable, noticed by inspection.
Modified:
llvm/trunk/lib/Analysis/CFG.cpp
llvm/trunk/unittests/Analysis/CFGTest.cpp
Modified: llvm/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFG.cpp?rev=357425&r1=357424&r2=357425&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFG.cpp (original)
+++ llvm/trunk/lib/Analysis/CFG.cpp Mon Apr 1 13:03:16 2019
@@ -226,10 +226,17 @@ bool llvm::isPotentiallyReachable(const
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);
Modified: llvm/trunk/unittests/Analysis/CFGTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/CFGTest.cpp?rev=357425&r1=357424&r2=357425&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/CFGTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/CFGTest.cpp Mon Apr 1 13:03:16 2019
@@ -385,3 +385,43 @@ TEST_F(IsPotentiallyReachableTest, Modif
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);
+}
More information about the llvm-commits
mailing list