// 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)} {
+ 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;
- std::vector<Type *> FArgTypes;
+ SmallVector<Type *, 3> FArgTypes;
Function *F;
};
LLVMContext &C(getGlobalContext());
// Type Definitions
- PointerType *Ptri8Ty = PointerType::get(IntegerType::get(C, 8), 0);
- PointerType *Ptri32Ty = PointerType::get(IntegerType::get(C, 32), 0);
+ Type *I8Ty = IntegerType::get(C, 8);
+ Type *I32Ty = IntegerType::get(C, 32);
+ PointerType *Ptri8Ty = PointerType::get(I8Ty, 0);
+ PointerType *Ptri32Ty = PointerType::get(I32Ty, 0);
VectorType *V2xi8PTy = VectorType::get(Ptri8Ty, 2);
VectorType *V2xi32PTy = VectorType::get(Ptri32Ty, 2);
ICmpInst *ICmp2 = new ICmpInst(*BB0, ICmpInst::ICMP_SGE, PtrVecA, PtrVecB);
EXPECT_NE(ICmp0, ICmp2); // suppress warning.
- GetElementPtrInst *Gep0 = GetElementPtrInst::Create(PtrVecA, C2xi32a);
- GetElementPtrInst *Gep1 = GetElementPtrInst::Create(PtrVecA, C2xi32b);
- GetElementPtrInst *Gep2 = GetElementPtrInst::Create(PtrVecB, C2xi32a);
- GetElementPtrInst *Gep3 = GetElementPtrInst::Create(PtrVecB, C2xi32b);
+ GetElementPtrInst *Gep0 = GetElementPtrInst::Create(I32Ty, PtrVecA, C2xi32a);
+ GetElementPtrInst *Gep1 = GetElementPtrInst::Create(I32Ty, PtrVecA, C2xi32b);
+ GetElementPtrInst *Gep2 = GetElementPtrInst::Create(I32Ty, PtrVecB, C2xi32a);
+ GetElementPtrInst *Gep3 = GetElementPtrInst::Create(I32Ty, PtrVecB, C2xi32b);
CastInst *BTC0 = new BitCastInst(Gep0, V2xi8PTy);
CastInst *BTC1 = new BitCastInst(Gep1, V2xi8PTy);
"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);
- GetPointerBaseWithConstantOffset(Gep1, Offset, &TD);
- GetPointerBaseWithConstantOffset(Gep2, Offset, &TD);
- GetPointerBaseWithConstantOffset(Gep3, Offset, &TD);
+ GetPointerBaseWithConstantOffset(Gep0, Offset, TD);
+ GetPointerBaseWithConstantOffset(Gep1, Offset, TD);
+ GetPointerBaseWithConstantOffset(Gep2, Offset, TD);
+ GetPointerBaseWithConstantOffset(Gep3, Offset, TD);
// Gep of Geps
- GetElementPtrInst *GepII0 = GetElementPtrInst::Create(Gep0, C2xi32b);
- GetElementPtrInst *GepII1 = GetElementPtrInst::Create(Gep1, C2xi32a);
- GetElementPtrInst *GepII2 = GetElementPtrInst::Create(Gep2, C2xi32b);
- GetElementPtrInst *GepII3 = GetElementPtrInst::Create(Gep3, C2xi32a);
+ GetElementPtrInst *GepII0 = GetElementPtrInst::Create(I32Ty, Gep0, C2xi32b);
+ GetElementPtrInst *GepII1 = GetElementPtrInst::Create(I32Ty, Gep1, C2xi32a);
+ GetElementPtrInst *GepII2 = GetElementPtrInst::Create(I32Ty, Gep2, C2xi32b);
+ GetElementPtrInst *GepII3 = GetElementPtrInst::Create(I32Ty, Gep3, C2xi32a);
EXPECT_EQ(GepII0->getNumIndices(), 1u);
EXPECT_EQ(GepII1->getNumIndices(), 1u);
EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::PtrToInt,
CastInst::IntToPtr,
Int64PtrTy, Int64Ty, Int64PtrTy,
- Int32Ty, 0, Int32Ty),
+ Int32Ty, nullptr, Int32Ty),
CastInst::BitCast);
// Source and destination have unknown sizes, but the same address space and
EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::PtrToInt,
CastInst::IntToPtr,
Int64PtrTy, Int64Ty, Int64PtrTy,
- 0, 0, 0),
+ nullptr, nullptr, nullptr),
CastInst::BitCast);
// Source and destination have unknown sizes, but the same address space and
EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::PtrToInt,
CastInst::IntToPtr,
Int64PtrTy, Int32Ty, Int64PtrTy,
- 0, 0, 0),
+ nullptr, nullptr, nullptr),
0U);
// Middle pointer big enough -> bitcast.
EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
CastInst::PtrToInt,
Int64Ty, Int64PtrTy, Int64Ty,
- 0, Int64Ty, 0),
+ nullptr, Int64Ty, nullptr),
CastInst::BitCast);
// Middle pointer too small -> fail.
EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
CastInst::PtrToInt,
Int64Ty, Int64PtrTy, Int64Ty,
- 0, Int32Ty, 0),
+ nullptr, Int32Ty, nullptr),
0U);
// Test that we don't eliminate bitcasts between different address spaces,
EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
CastInst::AddrSpaceCast,
Int16Ty, Int64PtrTyAS1, Int64PtrTyAS2,
- 0, Int16SizePtr, Int64SizePtr),
+ nullptr, Int16SizePtr, Int64SizePtr),
0U);
// Cannot simplify addrspacecast, ptrtoint
EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::AddrSpaceCast,
CastInst::PtrToInt,
Int64PtrTyAS1, Int64PtrTyAS2, Int16Ty,
- Int64SizePtr, Int16SizePtr, 0),
+ Int64SizePtr, Int16SizePtr, nullptr),
0U);
// Pass since the bitcast address spaces are the same
EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
CastInst::BitCast,
Int16Ty, Int64PtrTyAS1, Int64PtrTyAS1,
- 0, 0, 0),
+ nullptr, nullptr, nullptr),
CastInst::IntToPtr);
}
+TEST(InstructionsTest, CloneCall) {
+ LLVMContext &C(getGlobalContext());
+ Type *Int32Ty = Type::getInt32Ty(C);
+ Type *ArgTys[] = {Int32Ty, Int32Ty, Int32Ty};
+ Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false);
+ Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
+ Value *Args[] = {
+ ConstantInt::get(Int32Ty, 1),
+ ConstantInt::get(Int32Ty, 2),
+ ConstantInt::get(Int32Ty, 3)
+ };
+ std::unique_ptr<CallInst> Call(CallInst::Create(Callee, Args, "result"));
+
+ // Test cloning the tail call kind.
+ CallInst::TailCallKind Kinds[] = {CallInst::TCK_None, CallInst::TCK_Tail,
+ CallInst::TCK_MustTail};
+ for (CallInst::TailCallKind TCK : Kinds) {
+ Call->setTailCallKind(TCK);
+ std::unique_ptr<CallInst> Clone(cast<CallInst>(Call->clone()));
+ EXPECT_EQ(Call->getTailCallKind(), Clone->getTailCallKind());
+ }
+ Call->setTailCallKind(CallInst::TCK_None);
+
+ // Test cloning an attribute.
+ {
+ AttrBuilder AB;
+ AB.addAttribute(Attribute::ReadOnly);
+ Call->setAttributes(AttributeSet::get(C, AttributeSet::FunctionIndex, AB));
+ std::unique_ptr<CallInst> Clone(cast<CallInst>(Call->clone()));
+ EXPECT_TRUE(Clone->onlyReadsMemory());
+ }
+}
+
} // end anonymous namespace
} // end namespace llvm