1 //===- llvm/unittest/Bitcode/BitReaderTest.cpp - Tests for BitReader ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/Bitcode/BitstreamWriter.h"
12 #include "llvm/Bitcode/ReaderWriter.h"
13 #include "llvm/AsmParser/Parser.h"
14 #include "llvm/IR/Constants.h"
15 #include "llvm/IR/Instructions.h"
16 #include "llvm/IR/LLVMContext.h"
17 #include "llvm/IR/Module.h"
18 #include "llvm/IR/Verifier.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/MemoryBuffer.h"
21 #include "llvm/Support/SourceMgr.h"
22 #include "gtest/gtest.h"
28 std::unique_ptr<Module> parseAssembly(const char *Assembly) {
29 auto M = make_unique<Module>("Module", getGlobalContext());
33 ParseAssemblyString(Assembly, M.get(), Error, M->getContext()) == M.get();
36 raw_string_ostream OS(ErrMsg);
39 // A failure here means that the test itself is buggy.
41 report_fatal_error(OS.str().c_str());
46 static void writeModuleToBuffer(std::unique_ptr<Module> Mod,
47 SmallVectorImpl<char> &Buffer) {
48 raw_svector_ostream OS(Buffer);
49 WriteBitcodeToFile(Mod.get(), OS);
52 static std::unique_ptr<Module> getLazyModuleFromAssembly(LLVMContext &Context,
53 SmallString<1024> &Mem,
54 const char *Assembly) {
55 writeModuleToBuffer(parseAssembly(Assembly), Mem);
56 MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Mem.str(), "test", false);
57 ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
58 return std::unique_ptr<Module>(ModuleOrErr.get());
61 TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677
62 SmallString<1024> Mem;
65 std::unique_ptr<Module> M = getLazyModuleFromAssembly(
66 Context, Mem, "@table = constant i8* blockaddress(@func, %bb)\n"
67 "define void @func() {\n"
72 EXPECT_FALSE(verifyModule(*M, &dbgs()));