summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/InstructionsTest.cpp
diff options
context:
space:
mode:
authorEli Bendersky <eliben@google.com>2014-03-26 20:41:15 +0000
committerEli Bendersky <eliben@google.com>2014-03-26 20:41:15 +0000
commit84aa5e555ff1b51ffd4ca3acc1c04505aa3f7b96 (patch)
treefa10ad150f8e24e40573b09c6067b07ac671da3f /llvm/unittests/IR/InstructionsTest.cpp
parent664afe94a642c35eeb459cc003c1b3f3098615d9 (diff)
downloadbcm5719-llvm-84aa5e555ff1b51ffd4ca3acc1c04505aa3f7b96.tar.gz
bcm5719-llvm-84aa5e555ff1b51ffd4ca3acc1c04505aa3f7b96.zip
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. llvm-svn: 204851
Diffstat (limited to 'llvm/unittests/IR/InstructionsTest.cpp')
-rw-r--r--llvm/unittests/IR/InstructionsTest.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp
index 962c07eea14..94065289e2e 100644
--- a/llvm/unittests/IR/InstructionsTest.cpp
+++ b/llvm/unittests/IR/InstructionsTest.cpp
@@ -14,11 +14,14 @@
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "gtest/gtest.h"
+#include <memory>
namespace llvm {
namespace {
@@ -47,6 +50,29 @@ 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)};
+ 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(Call->getArgOperand(Idx)->getType(), Arg->getType());
+ Idx++;
+ }
+}
+
TEST(InstructionsTest, BranchInst) {
LLVMContext &C(getGlobalContext());
OpenPOWER on IntegriCloud