1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

Fix unit tests.

llvm-svn: 75262
This commit is contained in:
Owen Anderson 2009-07-10 18:58:29 +00:00
parent 2bdd9c7807
commit 565efa7c72
3 changed files with 94 additions and 92 deletions

View File

@ -16,6 +16,7 @@
#define LLVM_SUPPORT_TYPEBUILDER_H
#include "llvm/DerivedTypes.h"
#include "llvm/LLVMContext.h"
#include <limits.h>
namespace llvm {
@ -234,7 +235,7 @@ public:
template<bool cross> class TypeBuilder<void, cross> {
public:
static const Type *get(LLVMContxt&) {
static const Type *get(LLVMContext&) {
return Type::VoidTy;
}
};

View File

@ -65,7 +65,7 @@ struct RecordingJITEventListener : public JITEventListener {
class JITEventListenerTest : public testing::Test {
protected:
JITEventListenerTest()
: M(new Module("module", *new LLVMContext())),
: M(new Module("module", getGlobalContext())),
EE(ExecutionEngine::createJIT(new ExistingModuleProvider(M))) {
}
@ -75,7 +75,7 @@ class JITEventListenerTest : public testing::Test {
Function *buildFunction(Module *M) {
Function *Result = Function::Create(
TypeBuilder<int32_t(int32_t), false>::get(),
TypeBuilder<int32_t(int32_t), false>::get(getGlobalContext()),
GlobalValue::ExternalLinkage, "id", M);
Value *Arg = Result->arg_begin();
BasicBlock *BB = BasicBlock::Create("entry", Result);

View File

@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/TypeBuilder.h"
#include "llvm/LLVMContext.h"
#include "gtest/gtest.h"
@ -16,134 +17,134 @@ using namespace llvm;
namespace {
TEST(TypeBuilderTest, Void) {
EXPECT_EQ(Type::VoidTy, (TypeBuilder<void, true>::get()));
EXPECT_EQ(Type::VoidTy, (TypeBuilder<void, false>::get()));
EXPECT_EQ(Type::VoidTy, (TypeBuilder<void, true>::get(getGlobalContext())));
EXPECT_EQ(Type::VoidTy, (TypeBuilder<void, false>::get(getGlobalContext())));
// Special case for C compatibility:
EXPECT_EQ(PointerType::getUnqual(Type::Int8Ty),
(TypeBuilder<void*, false>::get()));
(TypeBuilder<void*, false>::get(getGlobalContext())));
}
TEST(TypeBuilderTest, HostIntegers) {
EXPECT_EQ(Type::Int8Ty, (TypeBuilder<int8_t, false>::get()));
EXPECT_EQ(Type::Int8Ty, (TypeBuilder<uint8_t, false>::get()));
EXPECT_EQ(Type::Int16Ty, (TypeBuilder<int16_t, false>::get()));
EXPECT_EQ(Type::Int16Ty, (TypeBuilder<uint16_t, false>::get()));
EXPECT_EQ(Type::Int32Ty, (TypeBuilder<int32_t, false>::get()));
EXPECT_EQ(Type::Int32Ty, (TypeBuilder<uint32_t, false>::get()));
EXPECT_EQ(Type::Int64Ty, (TypeBuilder<int64_t, false>::get()));
EXPECT_EQ(Type::Int64Ty, (TypeBuilder<uint64_t, false>::get()));
EXPECT_EQ(Type::Int8Ty, (TypeBuilder<int8_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty, (TypeBuilder<uint8_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int16Ty, (TypeBuilder<int16_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int16Ty, (TypeBuilder<uint16_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int32Ty, (TypeBuilder<int32_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int32Ty, (TypeBuilder<uint32_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int64Ty, (TypeBuilder<int64_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int64Ty, (TypeBuilder<uint64_t, false>::get(getGlobalContext())));
EXPECT_EQ(IntegerType::get(sizeof(size_t) * CHAR_BIT),
(TypeBuilder<size_t, false>::get()));
(TypeBuilder<size_t, false>::get(getGlobalContext())));
EXPECT_EQ(IntegerType::get(sizeof(ptrdiff_t) * CHAR_BIT),
(TypeBuilder<ptrdiff_t, false>::get()));
(TypeBuilder<ptrdiff_t, false>::get(getGlobalContext())));
}
TEST(TypeBuilderTest, CrossCompilableIntegers) {
EXPECT_EQ(IntegerType::get(1), (TypeBuilder<types::i<1>, true>::get()));
EXPECT_EQ(IntegerType::get(1), (TypeBuilder<types::i<1>, false>::get()));
EXPECT_EQ(IntegerType::get(72), (TypeBuilder<types::i<72>, true>::get()));
EXPECT_EQ(IntegerType::get(72), (TypeBuilder<types::i<72>, false>::get()));
EXPECT_EQ(IntegerType::get(1), (TypeBuilder<types::i<1>, true>::get(getGlobalContext())));
EXPECT_EQ(IntegerType::get(1), (TypeBuilder<types::i<1>, false>::get(getGlobalContext())));
EXPECT_EQ(IntegerType::get(72), (TypeBuilder<types::i<72>, true>::get(getGlobalContext())));
EXPECT_EQ(IntegerType::get(72), (TypeBuilder<types::i<72>, false>::get(getGlobalContext())));
}
TEST(TypeBuilderTest, Float) {
EXPECT_EQ(Type::FloatTy, (TypeBuilder<float, false>::get()));
EXPECT_EQ(Type::DoubleTy, (TypeBuilder<double, false>::get()));
EXPECT_EQ(Type::FloatTy, (TypeBuilder<float, false>::get(getGlobalContext())));
EXPECT_EQ(Type::DoubleTy, (TypeBuilder<double, false>::get(getGlobalContext())));
// long double isn't supported yet.
EXPECT_EQ(Type::FloatTy, (TypeBuilder<types::ieee_float, true>::get()));
EXPECT_EQ(Type::FloatTy, (TypeBuilder<types::ieee_float, false>::get()));
EXPECT_EQ(Type::DoubleTy, (TypeBuilder<types::ieee_double, true>::get()));
EXPECT_EQ(Type::DoubleTy, (TypeBuilder<types::ieee_double, false>::get()));
EXPECT_EQ(Type::X86_FP80Ty, (TypeBuilder<types::x86_fp80, true>::get()));
EXPECT_EQ(Type::X86_FP80Ty, (TypeBuilder<types::x86_fp80, false>::get()));
EXPECT_EQ(Type::FP128Ty, (TypeBuilder<types::fp128, true>::get()));
EXPECT_EQ(Type::FP128Ty, (TypeBuilder<types::fp128, false>::get()));
EXPECT_EQ(Type::PPC_FP128Ty, (TypeBuilder<types::ppc_fp128, true>::get()));
EXPECT_EQ(Type::PPC_FP128Ty, (TypeBuilder<types::ppc_fp128, false>::get()));
EXPECT_EQ(Type::FloatTy, (TypeBuilder<types::ieee_float, true>::get(getGlobalContext())));
EXPECT_EQ(Type::FloatTy, (TypeBuilder<types::ieee_float, false>::get(getGlobalContext())));
EXPECT_EQ(Type::DoubleTy, (TypeBuilder<types::ieee_double, true>::get(getGlobalContext())));
EXPECT_EQ(Type::DoubleTy, (TypeBuilder<types::ieee_double, false>::get(getGlobalContext())));
EXPECT_EQ(Type::X86_FP80Ty, (TypeBuilder<types::x86_fp80, true>::get(getGlobalContext())));
EXPECT_EQ(Type::X86_FP80Ty, (TypeBuilder<types::x86_fp80, false>::get(getGlobalContext())));
EXPECT_EQ(Type::FP128Ty, (TypeBuilder<types::fp128, true>::get(getGlobalContext())));
EXPECT_EQ(Type::FP128Ty, (TypeBuilder<types::fp128, false>::get(getGlobalContext())));
EXPECT_EQ(Type::PPC_FP128Ty, (TypeBuilder<types::ppc_fp128, true>::get(getGlobalContext())));
EXPECT_EQ(Type::PPC_FP128Ty, (TypeBuilder<types::ppc_fp128, false>::get(getGlobalContext())));
}
TEST(TypeBuilderTest, Derived) {
EXPECT_EQ(PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)),
(TypeBuilder<int8_t**, false>::get()));
(TypeBuilder<int8_t**, false>::get(getGlobalContext())));
EXPECT_EQ(ArrayType::get(Type::Int8Ty, 7),
(TypeBuilder<int8_t[7], false>::get()));
(TypeBuilder<int8_t[7], false>::get(getGlobalContext())));
EXPECT_EQ(ArrayType::get(Type::Int8Ty, 0),
(TypeBuilder<int8_t[], false>::get()));
(TypeBuilder<int8_t[], false>::get(getGlobalContext())));
EXPECT_EQ(PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)),
(TypeBuilder<types::i<8>**, false>::get()));
(TypeBuilder<types::i<8>**, false>::get(getGlobalContext())));
EXPECT_EQ(ArrayType::get(Type::Int8Ty, 7),
(TypeBuilder<types::i<8>[7], false>::get()));
(TypeBuilder<types::i<8>[7], false>::get(getGlobalContext())));
EXPECT_EQ(ArrayType::get(Type::Int8Ty, 0),
(TypeBuilder<types::i<8>[], false>::get()));
(TypeBuilder<types::i<8>[], false>::get(getGlobalContext())));
EXPECT_EQ(PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)),
(TypeBuilder<types::i<8>**, true>::get()));
(TypeBuilder<types::i<8>**, true>::get(getGlobalContext())));
EXPECT_EQ(ArrayType::get(Type::Int8Ty, 7),
(TypeBuilder<types::i<8>[7], true>::get()));
(TypeBuilder<types::i<8>[7], true>::get(getGlobalContext())));
EXPECT_EQ(ArrayType::get(Type::Int8Ty, 0),
(TypeBuilder<types::i<8>[], true>::get()));
(TypeBuilder<types::i<8>[], true>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty,
(TypeBuilder<const int8_t, false>::get()));
(TypeBuilder<const int8_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty,
(TypeBuilder<volatile int8_t, false>::get()));
(TypeBuilder<volatile int8_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty,
(TypeBuilder<const volatile int8_t, false>::get()));
(TypeBuilder<const volatile int8_t, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty,
(TypeBuilder<const types::i<8>, false>::get()));
(TypeBuilder<const types::i<8>, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty,
(TypeBuilder<volatile types::i<8>, false>::get()));
(TypeBuilder<volatile types::i<8>, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty,
(TypeBuilder<const volatile types::i<8>, false>::get()));
(TypeBuilder<const volatile types::i<8>, false>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty,
(TypeBuilder<const types::i<8>, true>::get()));
(TypeBuilder<const types::i<8>, true>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty,
(TypeBuilder<volatile types::i<8>, true>::get()));
(TypeBuilder<volatile types::i<8>, true>::get(getGlobalContext())));
EXPECT_EQ(Type::Int8Ty,
(TypeBuilder<const volatile types::i<8>, true>::get()));
(TypeBuilder<const volatile types::i<8>, true>::get(getGlobalContext())));
EXPECT_EQ(PointerType::getUnqual(Type::Int8Ty),
(TypeBuilder<const volatile int8_t*const volatile, false>::get()));
(TypeBuilder<const volatile int8_t*const volatile, false>::get(getGlobalContext())));
}
TEST(TypeBuilderTest, Functions) {
std::vector<const Type*> params;
EXPECT_EQ(FunctionType::get(Type::VoidTy, params, false),
(TypeBuilder<void(), true>::get()));
(TypeBuilder<void(), true>::get(getGlobalContext())));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true),
(TypeBuilder<int8_t(...), false>::get()));
params.push_back(TypeBuilder<int32_t*, false>::get());
(TypeBuilder<int8_t(...), false>::get(getGlobalContext())));
params.push_back(TypeBuilder<int32_t*, false>::get(getGlobalContext()));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false),
(TypeBuilder<int8_t(const int32_t*), false>::get()));
(TypeBuilder<int8_t(const int32_t*), false>::get(getGlobalContext())));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true),
(TypeBuilder<int8_t(const int32_t*, ...), false>::get()));
params.push_back(TypeBuilder<char*, false>::get());
(TypeBuilder<int8_t(const int32_t*, ...), false>::get(getGlobalContext())));
params.push_back(TypeBuilder<char*, false>::get(getGlobalContext()));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false),
(TypeBuilder<int8_t(int32_t*, void*), false>::get()));
(TypeBuilder<int8_t(int32_t*, void*), false>::get(getGlobalContext())));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true),
(TypeBuilder<int8_t(int32_t*, char*, ...), false>::get()));
params.push_back(TypeBuilder<char, false>::get());
(TypeBuilder<int8_t(int32_t*, char*, ...), false>::get(getGlobalContext())));
params.push_back(TypeBuilder<char, false>::get(getGlobalContext()));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false),
(TypeBuilder<int8_t(int32_t*, void*, char), false>::get()));
(TypeBuilder<int8_t(int32_t*, void*, char), false>::get(getGlobalContext())));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true),
(TypeBuilder<int8_t(int32_t*, char*, char, ...), false>::get()));
params.push_back(TypeBuilder<char, false>::get());
(TypeBuilder<int8_t(int32_t*, char*, char, ...), false>::get(getGlobalContext())));
params.push_back(TypeBuilder<char, false>::get(getGlobalContext()));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false),
(TypeBuilder<int8_t(int32_t*, void*, char, char), false>::get()));
(TypeBuilder<int8_t(int32_t*, void*, char, char), false>::get(getGlobalContext())));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true),
(TypeBuilder<int8_t(int32_t*, char*, char, char, ...),
false>::get()));
params.push_back(TypeBuilder<char, false>::get());
false>::get(getGlobalContext())));
params.push_back(TypeBuilder<char, false>::get(getGlobalContext()));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false),
(TypeBuilder<int8_t(int32_t*, void*, char, char, char),
false>::get()));
false>::get(getGlobalContext())));
EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true),
(TypeBuilder<int8_t(int32_t*, char*, char, char, char, ...),
false>::get()));
false>::get(getGlobalContext())));
}
class MyType {
@ -163,14 +164,14 @@ class MyPortableType {
namespace llvm {
template<bool cross> class TypeBuilder<MyType, cross> {
public:
static const StructType *get() {
static const StructType *get(LLVMContext &Context) {
// Using the static result variable ensures that the type is
// only looked up once.
static const StructType *const result = StructType::get(
TypeBuilder<int, cross>::get(),
TypeBuilder<int*, cross>::get(),
TypeBuilder<void*[], cross>::get(),
NULL);
std::vector<const Type*> st;
st.push_back(TypeBuilder<int, cross>::get(Context));
st.push_back(TypeBuilder<int*, cross>::get(Context));
st.push_back(TypeBuilder<void*[], cross>::get(Context));
static const StructType *const result = Context.getStructType(st);
return result;
}
@ -186,14 +187,14 @@ public:
template<bool cross> class TypeBuilder<MyPortableType, cross> {
public:
static const StructType *get() {
static const StructType *get(LLVMContext &Context) {
// Using the static result variable ensures that the type is
// only looked up once.
static const StructType *const result = StructType::get(
TypeBuilder<types::i<32>, cross>::get(),
TypeBuilder<types::i<32>*, cross>::get(),
TypeBuilder<types::i<8>*[], cross>::get(),
NULL);
std::vector<const Type*> st;
st.push_back(TypeBuilder<types::i<32>, cross>::get(Context));
st.push_back(TypeBuilder<types::i<32>*, cross>::get(Context));
st.push_back(TypeBuilder<types::i<8>*[], cross>::get(Context));
static const StructType *const result = Context.getStructType(st);
return result;
}
@ -211,23 +212,23 @@ namespace {
TEST(TypeBuilderTest, Extensions) {
EXPECT_EQ(PointerType::getUnqual(StructType::get(
TypeBuilder<int, false>::get(),
TypeBuilder<int*, false>::get(),
TypeBuilder<void*[], false>::get(),
TypeBuilder<int, false>::get(getGlobalContext()),
TypeBuilder<int*, false>::get(getGlobalContext()),
TypeBuilder<void*[], false>::get(getGlobalContext()),
NULL)),
(TypeBuilder<MyType*, false>::get()));
(TypeBuilder<MyType*, false>::get(getGlobalContext())));
EXPECT_EQ(PointerType::getUnqual(StructType::get(
TypeBuilder<types::i<32>, false>::get(),
TypeBuilder<types::i<32>*, false>::get(),
TypeBuilder<types::i<8>*[], false>::get(),
TypeBuilder<types::i<32>, false>::get(getGlobalContext()),
TypeBuilder<types::i<32>*, false>::get(getGlobalContext()),
TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()),
NULL)),
(TypeBuilder<MyPortableType*, false>::get()));
(TypeBuilder<MyPortableType*, false>::get(getGlobalContext())));
EXPECT_EQ(PointerType::getUnqual(StructType::get(
TypeBuilder<types::i<32>, false>::get(),
TypeBuilder<types::i<32>*, false>::get(),
TypeBuilder<types::i<8>*[], false>::get(),
TypeBuilder<types::i<32>, false>::get(getGlobalContext()),
TypeBuilder<types::i<32>*, false>::get(getGlobalContext()),
TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()),
NULL)),
(TypeBuilder<MyPortableType*, true>::get()));
(TypeBuilder<MyPortableType*, true>::get(getGlobalContext())));
}
} // anonymous namespace