diff options
author | dim <dim@FreeBSD.org> | 2012-04-14 13:54:10 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-04-14 13:54:10 +0000 |
commit | 1fc08f5e9ef733ef1ce6f363fecedc2260e78974 (patch) | |
tree | 19c69a04768629f2d440944b71cbe90adae0b615 /unittests/Bitcode/BitReaderTest.cpp | |
parent | 07637c87f826cdf411f0673595e9bc92ebd793f2 (diff) | |
download | FreeBSD-src-1fc08f5e9ef733ef1ce6f363fecedc2260e78974.zip FreeBSD-src-1fc08f5e9ef733ef1ce6f363fecedc2260e78974.tar.gz |
Vendor import of llvm trunk r154661:
http://llvm.org/svn/llvm-project/llvm/trunk@r154661
Diffstat (limited to 'unittests/Bitcode/BitReaderTest.cpp')
-rw-r--r-- | unittests/Bitcode/BitReaderTest.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/unittests/Bitcode/BitReaderTest.cpp b/unittests/Bitcode/BitReaderTest.cpp new file mode 100644 index 0000000..68cfe28 --- /dev/null +++ b/unittests/Bitcode/BitReaderTest.cpp @@ -0,0 +1,65 @@ +//===- llvm/unittest/Bitcode/BitReaderTest.cpp - Tests for BitReader ------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/SmallString.h" +#include "llvm/Analysis/Verifier.h" +#include "llvm/Bitcode/BitstreamWriter.h" +#include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/Constants.h" +#include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" +#include "llvm/Module.h" +#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; +} + +static void writeModuleToBuffer(SmallVectorImpl<char> &Buffer) { + Module *Mod = makeLLVMModule(); + raw_svector_ostream OS(Buffer); + WriteBitcodeToFile(Mod, OS); +} + +TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677 + SmallString<1024> Mem; + writeModuleToBuffer(Mem); + MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Mem.str(), "test", false); + std::string errMsg; + Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg); + PassManager passes; + passes.add(createVerifierPass()); + passes.run(*m); +} + +} +} |