llvm.org GIT mirror llvm / 972cc0d
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 Chandler Carruth 7 years ago
6 changed file(s) with 86 addition(s) and 67 deletion(s). Raw diff Collapse all Expand all
0 //===- llvm/unittest/Bitcode/BitReaderTest.cpp - Tests for BitReader ------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Analysis/Verifier.h"
10 #include "llvm/Bitcode/BitstreamWriter.h"
11 #include "llvm/Bitcode/ReaderWriter.h"
12 #include "llvm/Constants.h"
13 #include "llvm/Instructions.h"
14 #include "llvm/LLVMContext.h"
15 #include "llvm/Module.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/Support/MemoryBuffer.h"
18 #include "gtest/gtest.h"
19
20 namespace llvm {
21 namespace {
22
23 static Module *makeLLVMModule() {
24 Module* Mod = new Module("test-mem", getGlobalContext());
25
26 FunctionType* FuncTy =
27 FunctionType::get(Type::getVoidTy(Mod->getContext()), false);
28 Function* Func = Function::Create(FuncTy,GlobalValue::ExternalLinkage,
29 "func", Mod);
30
31 BasicBlock* Entry = BasicBlock::Create(Mod->getContext(), "entry", Func);
32 new UnreachableInst(Mod->getContext(), Entry);
33
34 BasicBlock* BB = BasicBlock::Create(Mod->getContext(), "bb", Func);
35 new UnreachableInst(Mod->getContext(), BB);
36
37 PointerType* Int8Ptr = Type::getInt8PtrTy(Mod->getContext());
38 new GlobalVariable(*Mod, Int8Ptr, /*isConstant=*/true,
39 GlobalValue::ExternalLinkage,
40 BlockAddress::get(BB), "table");
41
42 return Mod;
43 }
44
45 static void writeModuleToBuffer(std::vector &Buffer) {
46 Module *Mod = makeLLVMModule();
47 BitstreamWriter Stream(Buffer);
48 WriteBitcodeToStream(Mod, Stream);
49 }
50
51 TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677
52 std::vector Mem;
53 writeModuleToBuffer(Mem);
54 StringRef Data((const char*)&Mem[0], Mem.size());
55 MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Data, "test", false);
56 std::string errMsg;
57 Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg);
58 PassManager passes;
59 passes.add(createVerifierPass());
60 passes.run(*m);
61 }
62
63 }
64 }
0 ##===- unittests/Bitcode/Makefile --------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../..
10 TESTNAME = Bitcode
11 LINK_COMPONENTS := core support bitreader bitwriter
12
13 include $(LEVEL)/Makefile.config
14 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
111111 VMCore/PassManagerTest.cpp
112112 VMCore/ValueMapTest.cpp
113113 VMCore/VerifierTest.cpp
114 VMCore/pr11677.cpp
115114 )
116115
117116 # MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug.
121120 endif()
122121
123122 add_llvm_unittest(VMCore ${VMCoreSources})
123
124 add_llvm_unittest(Bitcode
125 Bitcode/BitReaderTest.cpp
126 )
124127
125128 set(LLVM_LINK_COMPONENTS
126129 Support
88
99 LEVEL = ..
1010
11 PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore Analysis
11 PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore Analysis Bitcode
1212
1313 include $(LEVEL)/Makefile.common
1414
88
99 LEVEL = ../..
1010 TESTNAME = VMCore
11 LINK_COMPONENTS := core support bitreader bitwriter target ipa
11 LINK_COMPONENTS := core support target ipa
1212
1313 include $(LEVEL)/Makefile.config
1414 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
+0
-64
unittests/VMCore/pr11677.cpp less more
None //===- llvm/unittest/VMCore/pr11677.cpp - Test for blockaddr --------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Analysis/Verifier.h"
10 #include "llvm/Bitcode/BitstreamWriter.h"
11 #include "llvm/Bitcode/ReaderWriter.h"
12 #include "llvm/Constants.h"
13 #include "llvm/Instructions.h"
14 #include "llvm/LLVMContext.h"
15 #include "llvm/Module.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/Support/MemoryBuffer.h"
18 #include "gtest/gtest.h"
19
20 namespace llvm {
21 namespace {
22
23 static Module *makeLLVMModule() {
24 Module* Mod = new Module("test-mem", getGlobalContext());
25
26 FunctionType* FuncTy =
27 FunctionType::get(Type::getVoidTy(Mod->getContext()), false);
28 Function* Func = Function::Create(FuncTy,GlobalValue::ExternalLinkage,
29 "func", Mod);
30
31 BasicBlock* Entry = BasicBlock::Create(Mod->getContext(), "entry", Func);
32 new UnreachableInst(Mod->getContext(), Entry);
33
34 BasicBlock* BB = BasicBlock::Create(Mod->getContext(), "bb", Func);
35 new UnreachableInst(Mod->getContext(), BB);
36
37 PointerType* Int8Ptr = Type::getInt8PtrTy(Mod->getContext());
38 new GlobalVariable(*Mod, Int8Ptr, /*isConstant=*/true,
39 GlobalValue::ExternalLinkage,
40 BlockAddress::get(BB), "table");
41
42 return Mod;
43 }
44
45 static void writeModuleToBuffer(std::vector &Buffer) {
46 Module *Mod = makeLLVMModule();
47 BitstreamWriter Stream(Buffer);
48 WriteBitcodeToStream(Mod, Stream);
49 }
50
51 TEST(PR11677, BlockAddr) {
52 std::vector Mem;
53 writeModuleToBuffer(Mem);
54 StringRef Data((const char*)&Mem[0], Mem.size());
55 MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Data, "test", false);
56 std::string errMsg;
57 Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg);
58 PassManager passes;
59 passes.add(createVerifierPass());
60 passes.run(*m);
61 }
62 }
63 }