diff options
author | Eli Bendersky <eliben@google.com> | 2014-03-26 21:46:24 +0000 |
---|---|---|
committer | Eli Bendersky <eliben@google.com> | 2014-03-26 21:46:24 +0000 |
commit | d8f4993cc718d2b6dd0bfa1be37a48e8c7eb62e1 (patch) | |
tree | b25d22d8925b9f3d8d717a7649d653bbbf38ee0e /unittests | |
parent | 23463c9261c2c78d389e1acb76ae4b741f06034a (diff) | |
download | llvm-d8f4993cc718d2b6dd0bfa1be37a48e8c7eb62e1.tar.gz llvm-d8f4993cc718d2b6dd0bfa1be37a48e8c7eb62e1.tar.bz2 llvm-d8f4993cc718d2b6dd0bfa1be37a48e8c7eb62e1.tar.xz |
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
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/IR/InstructionsTest.cpp | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/unittests/IR/InstructionsTest.cpp b/unittests/IR/InstructionsTest.cpp index 39a7d77a10..e355d16d7e 100644 --- a/unittests/IR/InstructionsTest.cpp +++ b/unittests/IR/InstructionsTest.cpp @@ -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()); |