2013-07-27 03:24:00 +02:00
|
|
|
//===- CFGTest.cpp - CFG tests --------------------------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-07-27 03:24:00 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/CFG.h"
|
2019-04-02 03:05:48 +02:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2013-07-27 03:24:00 +02:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
2014-01-07 13:34:26 +01:00
|
|
|
#include "llvm/AsmParser/Parser.h"
|
2014-01-13 10:26:24 +01:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2013-07-27 03:24:00 +02:00
|
|
|
#include "llvm/IR/Function.h"
|
2014-03-04 11:30:26 +01:00
|
|
|
#include "llvm/IR/InstIterator.h"
|
2014-01-07 12:48:04 +01:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2017-06-06 13:06:56 +02:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
2013-07-27 03:24:00 +02:00
|
|
|
#include "llvm/IR/Module.h"
|
2019-11-14 03:19:54 +01:00
|
|
|
#include "llvm/InitializePasses.h"
|
2013-07-27 03:24:00 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/SourceMgr.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// This fixture assists in running the isPotentiallyReachable utility four ways
|
|
|
|
// and ensuring it produces the correct answer each time.
|
|
|
|
class IsPotentiallyReachableTest : public testing::Test {
|
|
|
|
protected:
|
|
|
|
void ParseAssembly(const char *Assembly) {
|
|
|
|
SMDiagnostic Error;
|
2016-04-14 23:59:01 +02:00
|
|
|
M = parseAssemblyString(Assembly, Error, Context);
|
2013-07-27 03:24:00 +02:00
|
|
|
|
|
|
|
std::string errMsg;
|
|
|
|
raw_string_ostream os(errMsg);
|
|
|
|
Error.print("", os);
|
|
|
|
|
2014-08-19 18:58:54 +02:00
|
|
|
// A failure here means that the test itself is buggy.
|
|
|
|
if (!M)
|
2013-07-27 03:24:00 +02:00
|
|
|
report_fatal_error(os.str().c_str());
|
|
|
|
|
|
|
|
Function *F = M->getFunction("test");
|
2014-06-09 00:29:17 +02:00
|
|
|
if (F == nullptr)
|
2013-07-27 03:24:00 +02:00
|
|
|
report_fatal_error("Test must have a function named @test");
|
|
|
|
|
2014-06-09 00:29:17 +02:00
|
|
|
A = B = nullptr;
|
2013-07-27 03:24:00 +02:00
|
|
|
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
|
|
|
|
if (I->hasName()) {
|
|
|
|
if (I->getName() == "A")
|
|
|
|
A = &*I;
|
|
|
|
else if (I->getName() == "B")
|
|
|
|
B = &*I;
|
|
|
|
}
|
|
|
|
}
|
2014-06-09 00:29:17 +02:00
|
|
|
if (A == nullptr)
|
2013-07-27 03:24:00 +02:00
|
|
|
report_fatal_error("@test must have an instruction %A");
|
2014-06-09 00:29:17 +02:00
|
|
|
if (B == nullptr)
|
2013-07-27 03:24:00 +02:00
|
|
|
report_fatal_error("@test must have an instruction %B");
|
2019-04-02 03:05:48 +02:00
|
|
|
|
|
|
|
assert(ExclusionSet.empty());
|
|
|
|
for (auto I = F->begin(), E = F->end(); I != E; ++I) {
|
|
|
|
if (I->hasName() && I->getName().startswith("excluded"))
|
|
|
|
ExclusionSet.insert(&*I);
|
|
|
|
}
|
2013-07-27 03:24:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExpectPath(bool ExpectedResult) {
|
|
|
|
static char ID;
|
|
|
|
class IsPotentiallyReachableTestPass : public FunctionPass {
|
|
|
|
public:
|
2019-04-02 03:05:48 +02:00
|
|
|
IsPotentiallyReachableTestPass(bool ExpectedResult, Instruction *A,
|
|
|
|
Instruction *B,
|
|
|
|
SmallPtrSet<BasicBlock *, 4> ExclusionSet)
|
|
|
|
: FunctionPass(ID), ExpectedResult(ExpectedResult), A(A), B(B),
|
|
|
|
ExclusionSet(ExclusionSet) {}
|
|
|
|
|
|
|
|
static int initialize() {
|
|
|
|
PassInfo *PI = new PassInfo("isPotentiallyReachable testing pass", "",
|
|
|
|
&ID, nullptr, true, true);
|
|
|
|
PassRegistry::getPassRegistry()->registerPass(*PI, false);
|
|
|
|
initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
initializeDominatorTreeWrapperPassPass(
|
|
|
|
*PassRegistry::getPassRegistry());
|
|
|
|
return 0;
|
2013-07-27 03:24:00 +02:00
|
|
|
}
|
|
|
|
|
2015-04-11 04:11:45 +02:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2013-07-27 03:24:00 +02:00
|
|
|
AU.setPreservesAll();
|
2015-01-17 15:16:18 +01:00
|
|
|
AU.addRequired<LoopInfoWrapperPass>();
|
2014-01-13 14:07:17 +01:00
|
|
|
AU.addRequired<DominatorTreeWrapperPass>();
|
2013-07-27 03:24:00 +02:00
|
|
|
}
|
|
|
|
|
2015-04-11 04:11:45 +02:00
|
|
|
bool runOnFunction(Function &F) override {
|
2013-07-27 03:24:00 +02:00
|
|
|
if (!F.hasName() || F.getName() != "test")
|
|
|
|
return false;
|
|
|
|
|
2015-01-17 15:16:18 +01:00
|
|
|
LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
2014-01-13 14:07:17 +01:00
|
|
|
DominatorTree *DT =
|
|
|
|
&getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
2019-04-02 03:05:48 +02:00
|
|
|
EXPECT_EQ(isPotentiallyReachable(A, B, &ExclusionSet, nullptr, nullptr),
|
|
|
|
ExpectedResult);
|
|
|
|
EXPECT_EQ(isPotentiallyReachable(A, B, &ExclusionSet, DT, nullptr),
|
|
|
|
ExpectedResult);
|
|
|
|
EXPECT_EQ(isPotentiallyReachable(A, B, &ExclusionSet, nullptr, LI),
|
|
|
|
ExpectedResult);
|
|
|
|
EXPECT_EQ(isPotentiallyReachable(A, B, &ExclusionSet, DT, LI),
|
2014-06-09 00:29:17 +02:00
|
|
|
ExpectedResult);
|
2013-07-27 03:24:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool ExpectedResult;
|
|
|
|
Instruction *A, *B;
|
2019-04-02 03:05:48 +02:00
|
|
|
SmallPtrSet<BasicBlock *, 4> ExclusionSet;
|
2013-07-27 03:24:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int initialize = IsPotentiallyReachableTestPass::initialize();
|
|
|
|
(void)initialize;
|
|
|
|
|
|
|
|
IsPotentiallyReachableTestPass *P =
|
2019-04-02 03:05:48 +02:00
|
|
|
new IsPotentiallyReachableTestPass(ExpectedResult, A, B, ExclusionSet);
|
2015-02-13 11:01:29 +01:00
|
|
|
legacy::PassManager PM;
|
2013-07-27 03:24:00 +02:00
|
|
|
PM.add(P);
|
|
|
|
PM.run(*M);
|
|
|
|
}
|
2014-02-10 15:17:42 +01:00
|
|
|
|
2016-04-14 23:59:01 +02:00
|
|
|
LLVMContext Context;
|
2014-03-06 06:51:42 +01:00
|
|
|
std::unique_ptr<Module> M;
|
2013-07-27 03:24:00 +02:00
|
|
|
Instruction *A, *B;
|
2019-04-02 03:05:48 +02:00
|
|
|
SmallPtrSet<BasicBlock *, 4> ExclusionSet;
|
2013-07-27 03:24:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, SameBlockNoPath) {
|
|
|
|
ParseAssembly(
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" bitcast i8 undef to i8\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" bitcast i8 undef to i8\n"
|
|
|
|
" bitcast i8 undef to i8\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}\n");
|
|
|
|
ExpectPath(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, SameBlockPath) {
|
|
|
|
ParseAssembly(
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" bitcast i8 undef to i8\n"
|
|
|
|
" bitcast i8 undef to i8\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}\n");
|
|
|
|
ExpectPath(true);
|
|
|
|
}
|
|
|
|
|
2013-08-13 02:03:47 +02:00
|
|
|
TEST_F(IsPotentiallyReachableTest, SameBlockNoLoop) {
|
|
|
|
ParseAssembly(
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" br label %middle\n"
|
|
|
|
"middle:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" bitcast i8 undef to i8\n"
|
|
|
|
" bitcast i8 undef to i8\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" br label %nextblock\n"
|
|
|
|
"nextblock:\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}\n");
|
|
|
|
ExpectPath(false);
|
|
|
|
}
|
|
|
|
|
2013-07-27 03:24:00 +02:00
|
|
|
TEST_F(IsPotentiallyReachableTest, StraightNoPath) {
|
|
|
|
ParseAssembly(
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" br label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, StraightPath) {
|
|
|
|
ParseAssembly(
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" br label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, DestUnreachable) {
|
|
|
|
ParseAssembly(
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" br label %midblock\n"
|
|
|
|
"midblock:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"unreachable:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" br label %midblock\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, BranchToReturn) {
|
|
|
|
ParseAssembly(
|
|
|
|
"define void @test(i1 %x) {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" br i1 %x, label %block1, label %block2\n"
|
|
|
|
"block1:\n"
|
|
|
|
" ret void\n"
|
|
|
|
"block2:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, SimpleLoop1) {
|
|
|
|
ParseAssembly(
|
|
|
|
"declare i1 @switch()\n"
|
|
|
|
"\n"
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" br label %loop\n"
|
|
|
|
"loop:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" %x = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %loop, label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, SimpleLoop2) {
|
|
|
|
ParseAssembly(
|
|
|
|
"declare i1 @switch()\n"
|
|
|
|
"\n"
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" br label %loop\n"
|
|
|
|
"loop:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" %x = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %loop, label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, SimpleLoop3) {
|
|
|
|
ParseAssembly(
|
|
|
|
"declare i1 @switch()\n"
|
|
|
|
"\n"
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" br label %loop\n"
|
|
|
|
"loop:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" %x = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %loop, label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, OneLoopAfterTheOther1) {
|
|
|
|
ParseAssembly(
|
|
|
|
"declare i1 @switch()\n"
|
|
|
|
"\n"
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" br label %loop1\n"
|
|
|
|
"loop1:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" %x = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %loop1, label %loop1exit\n"
|
|
|
|
"loop1exit:\n"
|
|
|
|
" br label %loop2\n"
|
|
|
|
"loop2:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" %y = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %loop2, label %loop2exit\n"
|
|
|
|
"loop2exit:"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, OneLoopAfterTheOther2) {
|
|
|
|
ParseAssembly(
|
|
|
|
"declare i1 @switch()\n"
|
|
|
|
"\n"
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" br label %loop1\n"
|
|
|
|
"loop1:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" %x = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %loop1, label %loop1exit\n"
|
|
|
|
"loop1exit:\n"
|
|
|
|
" br label %loop2\n"
|
|
|
|
"loop2:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" %y = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %loop2, label %loop2exit\n"
|
|
|
|
"loop2exit:"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, OneLoopAfterTheOtherInsideAThirdLoop) {
|
|
|
|
ParseAssembly(
|
|
|
|
"declare i1 @switch()\n"
|
|
|
|
"\n"
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" br label %outerloop3\n"
|
|
|
|
"outerloop3:\n"
|
|
|
|
" br label %innerloop1\n"
|
|
|
|
"innerloop1:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" %x = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %innerloop1, label %innerloop1exit\n"
|
|
|
|
"innerloop1exit:\n"
|
|
|
|
" br label %innerloop2\n"
|
|
|
|
"innerloop2:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" %y = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %innerloop2, label %innerloop2exit\n"
|
|
|
|
"innerloop2exit:"
|
|
|
|
" ;; In outer loop3 now.\n"
|
|
|
|
" %z = call i1 @switch()\n"
|
|
|
|
" br i1 %z, label %outerloop3, label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(true);
|
|
|
|
}
|
|
|
|
|
2014-02-10 15:17:42 +01:00
|
|
|
static const char *BranchInsideLoopIR =
|
|
|
|
"declare i1 @switch()\n"
|
|
|
|
"\n"
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" br label %loop\n"
|
|
|
|
"loop:\n"
|
|
|
|
" %x = call i1 @switch()\n"
|
|
|
|
" br i1 %x, label %nextloopblock, label %exit\n"
|
|
|
|
"nextloopblock:\n"
|
|
|
|
" %y = call i1 @switch()\n"
|
|
|
|
" br i1 %y, label %left, label %right\n"
|
|
|
|
"left:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" br label %loop\n"
|
|
|
|
"right:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" br label %loop\n"
|
|
|
|
"exit:\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}";
|
|
|
|
|
2013-07-27 03:24:00 +02:00
|
|
|
TEST_F(IsPotentiallyReachableTest, BranchInsideLoop) {
|
2014-02-10 15:17:42 +01:00
|
|
|
ParseAssembly(BranchInsideLoopIR);
|
|
|
|
ExpectPath(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, ModifyTest) {
|
|
|
|
ParseAssembly(BranchInsideLoopIR);
|
|
|
|
|
2015-10-20 20:30:20 +02:00
|
|
|
succ_iterator S = succ_begin(&*++M->getFunction("test")->begin());
|
2014-02-10 15:17:42 +01:00
|
|
|
BasicBlock *OldBB = S[0];
|
|
|
|
S[0] = S[1];
|
|
|
|
ExpectPath(false);
|
|
|
|
S[0] = OldBB;
|
2013-07-27 03:24:00 +02:00
|
|
|
ExpectPath(true);
|
|
|
|
}
|
2019-04-01 22:03:16 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2019-04-02 03:05:48 +02:00
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, SimpleExclusionTest) {
|
|
|
|
ParseAssembly("define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" br label %excluded\n"
|
|
|
|
"excluded:\n"
|
|
|
|
" br label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, DiamondExcludedTest) {
|
|
|
|
ParseAssembly("declare i1 @switch()\n"
|
|
|
|
"\n"
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" %x = call i1 @switch()\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" br i1 %x, label %excluded.1, label %excluded.2\n"
|
|
|
|
"excluded.1:\n"
|
|
|
|
" br label %exit\n"
|
|
|
|
"excluded.2:\n"
|
|
|
|
" br label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, DiamondOneSideExcludedTest) {
|
|
|
|
ParseAssembly("declare i1 @switch()\n"
|
|
|
|
"\n"
|
|
|
|
"define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" %x = call i1 @switch()\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" br i1 %x, label %excluded, label %diamond\n"
|
|
|
|
"excluded:\n"
|
|
|
|
" br label %exit\n"
|
|
|
|
"diamond:\n"
|
|
|
|
" br label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(true);
|
|
|
|
}
|
2019-04-05 01:09:40 +02:00
|
|
|
|
|
|
|
TEST_F(IsPotentiallyReachableTest, UnreachableToReachable) {
|
|
|
|
ParseAssembly("define void @test() {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" br label %exit\n"
|
|
|
|
"unreachableblock:\n"
|
|
|
|
" %A = bitcast i8 undef to i8\n"
|
|
|
|
" br label %exit\n"
|
|
|
|
"exit:\n"
|
|
|
|
" %B = bitcast i8 undef to i8\n"
|
|
|
|
" ret void\n"
|
|
|
|
"}");
|
|
|
|
ExpectPath(true);
|
|
|
|
}
|