From: Chandler Carruth Date: Mon, 2 Jan 2012 09:19:48 +0000 (+0000) Subject: Undo the hack in r147427 and move this unittest to a better home. This X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=972cc0d54ac9ddbaa4d22a4f36db5269b3b4bbde;p=oota-llvm.git Undo the hack in r147427 and move this unittest to a better home. This is testing the bitcode reader's functionality, not VMCore's. Add the what is a hope sufficient build system mojo to build and run a new unittest. Also clean up some of the test's naming. The goal for the file should be to unittest the Bitcode Reader, and this is just one particular test among potentially many in the future. Also, reverse my position and relegate the PR# to a comment, but stash the comment on the same line as the test name so it doesn't get lost. This makes the code more self-documenting hopefully w/o losing track of the PR number. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147431 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/Bitcode/BitReaderTest.cpp b/unittests/Bitcode/BitReaderTest.cpp new file mode 100644 index 00000000000..91e6c151558 --- /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/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(std::vector &Buffer) { + Module *Mod = makeLLVMModule(); + BitstreamWriter Stream(Buffer); + WriteBitcodeToStream(Mod, Stream); +} + +TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677 + std::vector Mem; + writeModuleToBuffer(Mem); + StringRef Data((const char*)&Mem[0], Mem.size()); + MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Data, "test", false); + std::string errMsg; + Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg); + PassManager passes; + passes.add(createVerifierPass()); + passes.run(*m); +} + +} +} diff --git a/unittests/Bitcode/Makefile b/unittests/Bitcode/Makefile new file mode 100644 index 00000000000..aa437e7e2cc --- /dev/null +++ b/unittests/Bitcode/Makefile @@ -0,0 +1,15 @@ +##===- unittests/Bitcode/Makefile --------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../.. +TESTNAME = Bitcode +LINK_COMPONENTS := core support bitreader bitwriter + +include $(LEVEL)/Makefile.config +include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 3cd7f2f051d..6724f2df83f 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -112,7 +112,6 @@ set(VMCoreSources VMCore/PassManagerTest.cpp VMCore/ValueMapTest.cpp VMCore/VerifierTest.cpp - VMCore/pr11677.cpp ) # MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug. @@ -123,6 +122,10 @@ endif() add_llvm_unittest(VMCore ${VMCoreSources}) +add_llvm_unittest(Bitcode + Bitcode/BitReaderTest.cpp + ) + set(LLVM_LINK_COMPONENTS Support Core diff --git a/unittests/Makefile b/unittests/Makefile index 0401cd1c673..27afccf02e3 100644 --- a/unittests/Makefile +++ b/unittests/Makefile @@ -9,7 +9,7 @@ LEVEL = .. -PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore Analysis +PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore Analysis Bitcode include $(LEVEL)/Makefile.common diff --git a/unittests/VMCore/Makefile b/unittests/VMCore/Makefile index c6babe742cd..1b2b69c6d60 100644 --- a/unittests/VMCore/Makefile +++ b/unittests/VMCore/Makefile @@ -9,7 +9,7 @@ LEVEL = ../.. TESTNAME = VMCore -LINK_COMPONENTS := core support bitreader bitwriter target ipa +LINK_COMPONENTS := core support target ipa include $(LEVEL)/Makefile.config include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/unittests/VMCore/pr11677.cpp b/unittests/VMCore/pr11677.cpp deleted file mode 100644 index 362eec77630..00000000000 --- a/unittests/VMCore/pr11677.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//===- llvm/unittest/VMCore/pr11677.cpp - Test for blockaddr --------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#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(std::vector &Buffer) { - Module *Mod = makeLLVMModule(); - BitstreamWriter Stream(Buffer); - WriteBitcodeToStream(Mod, Stream); -} - -TEST(PR11677, BlockAddr) { - std::vector Mem; - writeModuleToBuffer(Mem); - StringRef Data((const char*)&Mem[0], Mem.size()); - MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Data, "test", false); - std::string errMsg; - Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg); - PassManager passes; - passes.add(createVerifierPass()); - passes.run(*m); -} -} -}