2012-01-02 09:19:48 +00:00
|
|
|
//===- llvm/unittest/Bitcode/BitReaderTest.cpp - Tests for BitReader ------===//
|
2012-01-02 07:49:53 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-02-29 20:30:56 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2012-01-02 07:49:53 +00:00
|
|
|
#include "llvm/Analysis/Verifier.h"
|
|
|
|
#include "llvm/Bitcode/BitstreamWriter.h"
|
|
|
|
#include "llvm/Bitcode/ReaderWriter.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2012-01-02 07:49:53 +00:00
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
static Module *makeLLVMModule() {
|
|
|
|
Module* Mod = new Module("test-mem", getGlobalContext());
|
|
|
|
|
|
|
|
FunctionType* FuncTy =
|
|
|
|
FunctionType::get(Type::getVoidTy(Mod->getContext()), false);
|
|
|
|
Function* Func = Function::Create(FuncTy,GlobalValue::ExternalLinkage,
|
|
|
|
"func", Mod);
|
|
|
|
|
|
|
|
BasicBlock* Entry = BasicBlock::Create(Mod->getContext(), "entry", Func);
|
|
|
|
new UnreachableInst(Mod->getContext(), Entry);
|
|
|
|
|
|
|
|
BasicBlock* BB = BasicBlock::Create(Mod->getContext(), "bb", Func);
|
|
|
|
new UnreachableInst(Mod->getContext(), BB);
|
|
|
|
|
|
|
|
PointerType* Int8Ptr = Type::getInt8PtrTy(Mod->getContext());
|
|
|
|
new GlobalVariable(*Mod, Int8Ptr, /*isConstant=*/true,
|
|
|
|
GlobalValue::ExternalLinkage,
|
|
|
|
BlockAddress::get(BB), "table");
|
|
|
|
|
|
|
|
return Mod;
|
|
|
|
}
|
|
|
|
|
2012-02-29 20:30:56 +00:00
|
|
|
static void writeModuleToBuffer(SmallVectorImpl<char> &Buffer) {
|
2013-01-23 08:33:13 +00:00
|
|
|
OwningPtr<Module> Mod(makeLLVMModule());
|
2012-02-29 20:30:56 +00:00
|
|
|
raw_svector_ostream OS(Buffer);
|
2013-01-23 08:33:13 +00:00
|
|
|
WriteBitcodeToFile(Mod.get(), OS);
|
2012-01-02 07:49:53 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 09:19:48 +00:00
|
|
|
TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677
|
2012-02-29 20:30:56 +00:00
|
|
|
SmallString<1024> Mem;
|
2012-01-02 07:49:53 +00:00
|
|
|
writeModuleToBuffer(Mem);
|
2012-02-29 20:30:56 +00:00
|
|
|
MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
|
2012-01-02 07:49:53 +00:00
|
|
|
std::string errMsg;
|
2013-01-23 08:33:13 +00:00
|
|
|
OwningPtr<Module> m(getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg));
|
2012-01-02 07:49:53 +00:00
|
|
|
PassManager passes;
|
|
|
|
passes.add(createVerifierPass());
|
|
|
|
passes.run(*m);
|
|
|
|
}
|
2012-01-02 09:19:48 +00:00
|
|
|
|
2012-01-02 07:49:53 +00:00
|
|
|
}
|
|
|
|
}
|