[llvm] r204860 - Add a unit test for Invoke iteration, similar to the one for Call
Eli Bendersky
eliben at google.com
Wed Mar 26 14:46:25 PDT 2014
Author: eliben
Date: Wed Mar 26 16:46:24 2014
New Revision: 204860
URL: http://llvm.org/viewvc/llvm-project?rev=204860&view=rev
Log:
Add a unit test for Invoke iteration, similar to the one for Call
The tests are refactored to use the same fixture.
Modified:
llvm/trunk/unittests/IR/InstructionsTest.cpp
Modified: llvm/trunk/unittests/IR/InstructionsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/InstructionsTest.cpp?rev=204860&r1=204859&r2=204860&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/InstructionsTest.cpp (original)
+++ llvm/trunk/unittests/IR/InstructionsTest.cpp Wed Mar 26 16:46:24 2014
@@ -50,28 +50,57 @@ TEST(InstructionsTest, ReturnInst) {
delete r1;
}
-TEST(InstructionsTest, CallInst) {
- LLVMContext &C(getGlobalContext());
- std::unique_ptr<Module> M(new Module("MyModule", C));
-
- 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());
-
- Value *Args[] = {ConstantInt::get(Type::getInt8Ty(C), 20),
- ConstantInt::get(Type::getInt32Ty(C), 9999),
- ConstantInt::get(Type::getInt64Ty(C), 42)};
+// 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());
+ }
+
+ LLVMContext Ctx;
+ std::unique_ptr<Module> M;
+ std::vector<Type *> FArgTypes;
+ Function *F;
+};
+
+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());
More information about the llvm-commits
mailing list