2009-09-27 21:39:46 +00:00
|
|
|
//===- Cloning.cpp - Unit tests for the Cloner ----------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "llvm/Argument.h"
|
|
|
|
#include "llvm/Instructions.h"
|
2009-10-27 17:08:31 +00:00
|
|
|
#include "llvm/LLVMContext.h"
|
2009-09-27 21:39:46 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
TEST(CloneInstruction, OverflowBits) {
|
|
|
|
LLVMContext context;
|
|
|
|
Value *V = new Argument(Type::getInt32Ty(context));
|
|
|
|
|
|
|
|
BinaryOperator *Add = BinaryOperator::Create(Instruction::Add, V, V);
|
|
|
|
BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V);
|
|
|
|
BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V);
|
|
|
|
|
2009-10-27 22:16:29 +00:00
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
|
2009-09-27 21:39:46 +00:00
|
|
|
|
|
|
|
Add->setHasNoUnsignedWrap();
|
|
|
|
Sub->setHasNoUnsignedWrap();
|
|
|
|
Mul->setHasNoUnsignedWrap();
|
|
|
|
|
2009-10-27 22:16:29 +00:00
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
|
2009-09-27 21:39:46 +00:00
|
|
|
|
|
|
|
Add->setHasNoSignedWrap();
|
|
|
|
Sub->setHasNoSignedWrap();
|
|
|
|
Mul->setHasNoSignedWrap();
|
|
|
|
|
2009-10-27 22:16:29 +00:00
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
|
2009-09-27 21:39:46 +00:00
|
|
|
|
|
|
|
Add->setHasNoUnsignedWrap(false);
|
|
|
|
Sub->setHasNoUnsignedWrap(false);
|
|
|
|
Mul->setHasNoUnsignedWrap(false);
|
|
|
|
|
2009-10-27 22:16:29 +00:00
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
|
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
|
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
|
2009-09-27 21:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CloneInstruction, Inbounds) {
|
|
|
|
LLVMContext context;
|
2009-10-06 15:40:36 +00:00
|
|
|
Value *V = new Argument(Type::getInt32PtrTy(context));
|
2009-09-27 21:39:46 +00:00
|
|
|
Constant *Z = Constant::getNullValue(Type::getInt32Ty(context));
|
|
|
|
std::vector<Value *> ops;
|
|
|
|
ops.push_back(Z);
|
|
|
|
GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end());
|
2009-10-27 22:16:29 +00:00
|
|
|
EXPECT_FALSE(cast<GetElementPtrInst>(GEP->clone())->isInBounds());
|
2009-09-27 21:39:46 +00:00
|
|
|
|
|
|
|
GEP->setIsInBounds();
|
2009-10-27 22:16:29 +00:00
|
|
|
EXPECT_TRUE(cast<GetElementPtrInst>(GEP->clone())->isInBounds());
|
2009-09-27 21:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CloneInstruction, Exact) {
|
|
|
|
LLVMContext context;
|
|
|
|
Value *V = new Argument(Type::getInt32Ty(context));
|
|
|
|
|
|
|
|
BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V);
|
2009-10-27 22:16:29 +00:00
|
|
|
EXPECT_FALSE(cast<BinaryOperator>(SDiv->clone())->isExact());
|
2009-09-27 21:39:46 +00:00
|
|
|
|
|
|
|
SDiv->setIsExact(true);
|
2009-10-27 22:16:29 +00:00
|
|
|
EXPECT_TRUE(cast<BinaryOperator>(SDiv->clone())->isExact());
|
2009-09-27 21:39:46 +00:00
|
|
|
}
|