llvm.org GIT mirror llvm / d8f4993
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 Eli Bendersky 6 years ago
1 changed file(s) with 42 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
4949 delete r1;
5050 }
5151
52 TEST(InstructionsTest, CallInst) {
53 LLVMContext &C(getGlobalContext());
54 std::unique_ptr M(new Module("MyModule", C));
55
56 Type *ArgTypes[] = {Type::getInt8Ty(C), Type::getInt32Ty(C),
57 Type::getInt64Ty(C)};
58 FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), ArgTypes, false);
59 Function *F = Function::Create(FTy, Function::ExternalLinkage, "", M.get());
60
61 Value *Args[] = {ConstantInt::get(Type::getInt8Ty(C), 20),
62 ConstantInt::get(Type::getInt32Ty(C), 9999),
63 ConstantInt::get(Type::getInt64Ty(C), 42)};
52 // Test fixture that provides a module and a single function within it. Useful
53 // for tests that need to refer to the function in some way.
54 class ModuleWithFunctionTest : public testing::Test {
55 protected:
56 ModuleWithFunctionTest()
57 : M(new Module("MyModule", Ctx)),
58 FArgTypes{Type::getInt8Ty(Ctx), Type::getInt32Ty(Ctx),
59 Type::getInt64Ty(Ctx)} {
60 FunctionType *FTy =
61 FunctionType::get(Type::getVoidTy(Ctx), FArgTypes, false);
62 F = Function::Create(FTy, Function::ExternalLinkage, "", M.get());
63 }
64
65 LLVMContext Ctx;
66 std::unique_ptr M;
67 std::vector FArgTypes;
68 Function *F;
69 };
70
71 TEST_F(ModuleWithFunctionTest, CallInst) {
72 Value *Args[] = {ConstantInt::get(Type::getInt8Ty(Ctx), 20),
73 ConstantInt::get(Type::getInt32Ty(Ctx), 9999),
74 ConstantInt::get(Type::getInt64Ty(Ctx), 42)};
6475 std::unique_ptr Call(CallInst::Create(F, Args));
6576
6677 // Make sure iteration over a call's arguments works as expected.
6778 unsigned Idx = 0;
6879 for (Value *Arg : Call->arg_operands()) {
69 EXPECT_EQ(ArgTypes[Idx], Arg->getType());
80 EXPECT_EQ(FArgTypes[Idx], Arg->getType());
7081 EXPECT_EQ(Call->getArgOperand(Idx)->getType(), Arg->getType());
82 Idx++;
83 }
84 }
85
86 TEST_F(ModuleWithFunctionTest, InvokeInst) {
87 BasicBlock *BB1 = BasicBlock::Create(Ctx, "", F);
88 BasicBlock *BB2 = BasicBlock::Create(Ctx, "", F);
89
90 Value *Args[] = {ConstantInt::get(Type::getInt8Ty(Ctx), 20),
91 ConstantInt::get(Type::getInt32Ty(Ctx), 9999),
92 ConstantInt::get(Type::getInt64Ty(Ctx), 42)};
93 std::unique_ptr Invoke(InvokeInst::Create(F, BB1, BB2, Args));
94
95 // Make sure iteration over invoke's arguments works as expected.
96 unsigned Idx = 0;
97 for (Value *Arg : Invoke->arg_operands()) {
98 EXPECT_EQ(FArgTypes[Idx], Arg->getType());
99 EXPECT_EQ(Invoke->getArgOperand(Idx)->getType(), Arg->getType());
71100 Idx++;
72101 }
73102 }