llvm.org GIT mirror llvm / 1003e8f
Fix problem with r204836 In CallInst, op_end() points at the callee, which we don't want to iterate over when just iterating over arguments. Now take this into account when returning a iterator_range from arg_operands. Similar reasoning for InvokeInst. Also adds a unit test to verify this actually works as expected. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204851 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Bendersky 6 years ago
2 changed file(s) with 32 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
12961296
12971297 /// arg_operands - iteration adapter for range-for loops.
12981298 iterator_range arg_operands() {
1299 return iterator_range(op_begin(), op_end());
1299 // The last operand in the op list is the callee - it's not one of the args
1300 // so we don't want to iterate over it.
1301 return iterator_range(op_begin(), op_end() - 1);
13001302 }
13011303
13021304 /// arg_operands - iteration adapter for range-for loops.
13031305 iterator_range arg_operands() const {
1304 return iterator_range(op_begin(), op_end());
1306 return iterator_range(op_begin(), op_end() - 1);
13051307 }
13061308
13071309 /// \brief Wrappers for getting the \c Use of a call argument.
29532955
29542956 /// arg_operands - iteration adapter for range-for loops.
29552957 iterator_range arg_operands() {
2956 return iterator_range(op_begin(), op_end());
2958 return iterator_range(op_begin(), op_end() - 3);
29572959 }
29582960
29592961 /// arg_operands - iteration adapter for range-for loops.
29602962 iterator_range arg_operands() const {
2961 return iterator_range(op_begin(), op_end());
2963 return iterator_range(op_begin(), op_end() - 3);
29622964 }
29632965
29642966 /// \brief Wrappers for getting the \c Use of a invoke argument.
1313 #include "llvm/IR/Constants.h"
1414 #include "llvm/IR/DataLayout.h"
1515 #include "llvm/IR/DerivedTypes.h"
16 #include "llvm/IR/Function.h"
1617 #include "llvm/IR/IRBuilder.h"
1718 #include "llvm/IR/LLVMContext.h"
1819 #include "llvm/IR/MDBuilder.h"
20 #include "llvm/IR/Module.h"
1921 #include "llvm/IR/Operator.h"
2022 #include "gtest/gtest.h"
23 #include
2124
2225 namespace llvm {
2326 namespace {
4447 // clean up
4548 delete r0;
4649 delete r1;
50 }
51
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)};
64 CallInst *Call = CallInst::Create(F, Args);
65
66 // Make sure iteration over a call's arguments works as expected.
67 unsigned Idx = 0;
68 for (Value *Arg : Call->arg_operands()) {
69 EXPECT_EQ(ArgTypes[Idx], Arg->getType());
70 EXPECT_EQ(Call->getArgOperand(Idx)->getType(), Arg->getType());
71 Idx++;
72 }
4773 }
4874
4975 TEST(InstructionsTest, BranchInst) {