aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/IR/InstructionsTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/IR/InstructionsTest.cpp')
-rw-r--r--unittests/IR/InstructionsTest.cpp79
1 files changed, 75 insertions, 4 deletions
diff --git a/unittests/IR/InstructionsTest.cpp b/unittests/IR/InstructionsTest.cpp
index 65f85ba..e76afa8 100644
--- a/unittests/IR/InstructionsTest.cpp
+++ b/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,58 @@ TEST(InstructionsTest, ReturnInst) {
delete r1;
}
+// 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.push_back(Type::getInt8Ty(Ctx));
+ FArgTypes.push_back(Type::getInt32Ty(Ctx));
+ FArgTypes.push_back(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;
+ SmallVector<Type *, 3> 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(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());
@@ -65,9 +120,9 @@ TEST(InstructionsTest, BranchInst) {
EXPECT_EQ(1U, b0->getNumOperands());
EXPECT_NE(b0->op_begin(), b0->op_end());
- EXPECT_EQ(b0->op_end(), llvm::next(b0->op_begin()));
+ EXPECT_EQ(b0->op_end(), std::next(b0->op_begin()));
- EXPECT_EQ(b0->op_end(), llvm::next(b0->op_begin()));
+ EXPECT_EQ(b0->op_end(), std::next(b0->op_begin()));
IntegerType* Int1 = IntegerType::get(C, 1);
Constant* One = ConstantInt::get(Int1, 1, true);
@@ -145,6 +200,7 @@ TEST(InstructionsTest, CastInst) {
Type *V2Int64PtrTy = VectorType::get(Int64PtrTy, 2);
Type *V2Int32PtrTy = VectorType::get(Int32PtrTy, 2);
+ Type *V4Int32PtrTy = VectorType::get(Int32PtrTy, 4);
const Constant* c8 = Constant::getNullValue(V8x8Ty);
const Constant* c64 = Constant::getNullValue(V8x64Ty);
@@ -205,6 +261,21 @@ TEST(InstructionsTest, CastInst) {
EXPECT_FALSE(CastInst::isBitCastable(V2Int64Ty, V2Int32Ty));
+ EXPECT_FALSE(CastInst::castIsValid(Instruction::BitCast,
+ Constant::getNullValue(V4Int32PtrTy),
+ V2Int32PtrTy));
+ EXPECT_FALSE(CastInst::castIsValid(Instruction::BitCast,
+ Constant::getNullValue(V2Int32PtrTy),
+ V4Int32PtrTy));
+
+ EXPECT_FALSE(CastInst::castIsValid(Instruction::AddrSpaceCast,
+ Constant::getNullValue(V4Int32PtrAS1Ty),
+ V2Int32PtrTy));
+ EXPECT_FALSE(CastInst::castIsValid(Instruction::AddrSpaceCast,
+ Constant::getNullValue(V2Int32PtrTy),
+ V4Int32PtrAS1Ty));
+
+
// Check that assertion is not hit when creating a cast with a vector of
// pointers
// First form
@@ -269,7 +340,7 @@ TEST(InstructionsTest, VectorGep) {
int64_t Offset;
DataLayout TD("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3"
- "2:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80"
+ "2:32:32-f64:64:64-v64:64:64-v128:128:128-a:0:64-s:64:64-f80"
":128:128-n8:16:32:64-S128");
// Make sure we don't crash
GetPointerBaseWithConstantOffset(Gep0, Offset, &TD);
@@ -381,7 +452,7 @@ TEST(InstructionsTest, isEliminableCastPair) {
// or if we don't have available pointer size information.
DataLayout DL("e-p:32:32:32-p1:16:16:16-p2:64:64:64-i1:8:8-i8:8:8-i16:16:16"
"-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64"
- "-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128");
+ "-v128:128:128-a:0:64-s:64:64-f80:128:128-n8:16:32:64-S128");
Type* Int64PtrTyAS1 = Type::getInt64PtrTy(C, 1);
Type* Int64PtrTyAS2 = Type::getInt64PtrTy(C, 2);