Add a unit test for Invoke iteration, similar to the one for Call

The tests are refactored to use the same fixture.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204860 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eli Bendersky 2014-03-26 21:46:24 +00:00
parent 23463c9261
commit d8f4993cc7

View File

@ -50,29 +50,58 @@ TEST(InstructionsTest, ReturnInst) {
delete r1;
}
TEST(InstructionsTest, CallInst) {
LLVMContext &C(getGlobalContext());
std::unique_ptr<Module> M(new Module("MyModule", C));
// Test fixture that provides a module and a single function within it. Useful
// for tests that need to refer to the function in some way.
class ModuleWithFunctionTest : public testing::Test {
protected:
ModuleWithFunctionTest()
: M(new Module("MyModule", Ctx)),
FArgTypes{Type::getInt8Ty(Ctx), Type::getInt32Ty(Ctx),
Type::getInt64Ty(Ctx)} {
FunctionType *FTy =
FunctionType::get(Type::getVoidTy(Ctx), FArgTypes, false);
F = Function::Create(FTy, Function::ExternalLinkage, "", M.get());
}
Type *ArgTypes[] = {Type::getInt8Ty(C), Type::getInt32Ty(C),
Type::getInt64Ty(C)};
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false);
Function *F = Function::Create(FTy, Function::ExternalLinkage, "", M.get());
LLVMContext Ctx;
std::unique_ptr<Module> M;
std::vector<Type *> FArgTypes;
Function *F;
};
Value *Args[] = {ConstantInt::get(Type::getInt8Ty(C), 20),
ConstantInt::get(Type::getInt32Ty(C), 9999),
ConstantInt::get(Type::getInt64Ty(C), 42)};
TEST_F(ModuleWithFunctionTest, CallInst) {
Value *Args[] = {ConstantInt::get(Type::getInt8Ty(Ctx), 20),
ConstantInt::get(Type::getInt32Ty(Ctx), 9999),
ConstantInt::get(Type::getInt64Ty(Ctx), 42)};
std::unique_ptr<CallInst> Call(CallInst::Create(F, Args));
// Make sure iteration over a call's arguments works as expected.
unsigned Idx = 0;
for (Value *Arg : Call->arg_operands()) {
EXPECT_EQ(ArgTypes[Idx], Arg->getType());
EXPECT_EQ(FArgTypes[Idx], Arg->getType());
EXPECT_EQ(Call->getArgOperand(Idx)->getType(), Arg->getType());
Idx++;
}
}
TEST_F(ModuleWithFunctionTest, InvokeInst) {
BasicBlock *BB1 = BasicBlock::Create(Ctx, "", F);
BasicBlock *BB2 = BasicBlock::Create(Ctx, "", F);
Value *Args[] = {ConstantInt::get(Type::getInt8Ty(Ctx), 20),
ConstantInt::get(Type::getInt32Ty(Ctx), 9999),
ConstantInt::get(Type::getInt64Ty(Ctx), 42)};
std::unique_ptr<InvokeInst> Invoke(InvokeInst::Create(F, BB1, BB2, Args));
// Make sure iteration over invoke's arguments works as expected.
unsigned Idx = 0;
for (Value *Arg : Invoke->arg_operands()) {
EXPECT_EQ(FArgTypes[Idx], Arg->getType());
EXPECT_EQ(Invoke->getArgOperand(Idx)->getType(), Arg->getType());
Idx++;
}
}
TEST(InstructionsTest, BranchInst) {
LLVMContext &C(getGlobalContext());