llvm.org GIT mirror llvm / 7ebc162
Not all blocks are reachable from entry. Don't assume they are. Fixes a bug in isPotentiallyReachable, noticed by inspection. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357425 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 4 months ago
2 changed file(s) with 51 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
225225 Worklist.push_back(const_cast(A->getParent()));
226226 }
227227
228 if (A->getParent() == &A->getParent()->getParent()->getEntryBlock())
229 return true;
230 if (B->getParent() == &A->getParent()->getParent()->getEntryBlock())
231 return false;
228 if (DT) {
229 if (DT->isReachableFromEntry(A->getParent()) !=
230 DT->isReachableFromEntry(B->getParent()))
231 return false;
232 if (A->getParent() == &A->getParent()->getParent()->getEntryBlock() &&
233 DT->isReachableFromEntry(B->getParent()))
234 return true;
235 if (B->getParent() == &A->getParent()->getParent()->getEntryBlock() &&
236 DT->isReachableFromEntry(A->getParent()))
237 return false;
238 }
232239
233240 return isPotentiallyReachableFromMany(
234241 Worklist, const_cast(B->getParent()), DT, LI);
384384 S[0] = OldBB;
385385 ExpectPath(true);
386386 }
387
388 TEST_F(IsPotentiallyReachableTest, UnreachableFromEntryTest) {
389 ParseAssembly("define void @test() {\n"
390 "entry:\n"
391 " %A = bitcast i8 undef to i8\n"
392 " ret void\n"
393 "not.reachable:\n"
394 " %B = bitcast i8 undef to i8\n"
395 " ret void\n"
396 "}");
397 ExpectPath(false);
398 }
399
400 TEST_F(IsPotentiallyReachableTest, UnreachableBlocksTest1) {
401 ParseAssembly("define void @test() {\n"
402 "entry:\n"
403 " ret void\n"
404 "not.reachable.1:\n"
405 " %A = bitcast i8 undef to i8\n"
406 " br label %not.reachable.2\n"
407 "not.reachable.2:\n"
408 " %B = bitcast i8 undef to i8\n"
409 " ret void\n"
410 "}");
411 ExpectPath(true);
412 }
413
414 TEST_F(IsPotentiallyReachableTest, UnreachableBlocksTest2) {
415 ParseAssembly("define void @test() {\n"
416 "entry:\n"
417 " ret void\n"
418 "not.reachable.1:\n"
419 " %B = bitcast i8 undef to i8\n"
420 " br label %not.reachable.2\n"
421 "not.reachable.2:\n"
422 " %A = bitcast i8 undef to i8\n"
423 " ret void\n"
424 "}");
425 ExpectPath(false);
426 }