You've already forked linux-packaging-mono
Imported Upstream version 5.18.0.207
Former-commit-id: 3b152f462918d427ce18620a2cbe4f8b79650449
This commit is contained in:
parent
8e12397d70
commit
eb85e2fc17
194
external/llvm/unittests/Bitcode/BitReaderTest.cpp
vendored
194
external/llvm/unittests/Bitcode/BitReaderTest.cpp
vendored
@ -1,194 +0,0 @@
|
||||
//===- 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/STLExtras.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/AsmParser/Parser.h"
|
||||
#include "llvm/Bitcode/BitcodeReader.h"
|
||||
#include "llvm/Bitcode/BitcodeWriter.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/Verifier.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
std::unique_ptr<Module> parseAssembly(LLVMContext &Context,
|
||||
const char *Assembly) {
|
||||
SMDiagnostic Error;
|
||||
std::unique_ptr<Module> M = parseAssemblyString(Assembly, Error, Context);
|
||||
|
||||
std::string ErrMsg;
|
||||
raw_string_ostream OS(ErrMsg);
|
||||
Error.print("", OS);
|
||||
|
||||
// A failure here means that the test itself is buggy.
|
||||
if (!M)
|
||||
report_fatal_error(OS.str().c_str());
|
||||
|
||||
return M;
|
||||
}
|
||||
|
||||
static void writeModuleToBuffer(std::unique_ptr<Module> Mod,
|
||||
SmallVectorImpl<char> &Buffer) {
|
||||
raw_svector_ostream OS(Buffer);
|
||||
WriteBitcodeToFile(Mod.get(), OS);
|
||||
}
|
||||
|
||||
static std::unique_ptr<Module> getLazyModuleFromAssembly(LLVMContext &Context,
|
||||
SmallString<1024> &Mem,
|
||||
const char *Assembly) {
|
||||
writeModuleToBuffer(parseAssembly(Context, Assembly), Mem);
|
||||
Expected<std::unique_ptr<Module>> ModuleOrErr =
|
||||
getLazyBitcodeModule(MemoryBufferRef(Mem.str(), "test"), Context);
|
||||
if (!ModuleOrErr)
|
||||
report_fatal_error("Could not parse bitcode module");
|
||||
return std::move(ModuleOrErr.get());
|
||||
}
|
||||
|
||||
// Tests that lazy evaluation can parse functions out of order.
|
||||
TEST(BitReaderTest, MaterializeFunctionsOutOfOrder) {
|
||||
SmallString<1024> Mem;
|
||||
LLVMContext Context;
|
||||
std::unique_ptr<Module> M = getLazyModuleFromAssembly(
|
||||
Context, Mem, "define void @f() {\n"
|
||||
" unreachable\n"
|
||||
"}\n"
|
||||
"define void @g() {\n"
|
||||
" unreachable\n"
|
||||
"}\n"
|
||||
"define void @h() {\n"
|
||||
" unreachable\n"
|
||||
"}\n"
|
||||
"define void @j() {\n"
|
||||
" unreachable\n"
|
||||
"}\n");
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
|
||||
Function *F = M->getFunction("f");
|
||||
Function *G = M->getFunction("g");
|
||||
Function *H = M->getFunction("h");
|
||||
Function *J = M->getFunction("j");
|
||||
|
||||
// Initially all functions are not materialized (no basic blocks).
|
||||
EXPECT_TRUE(F->empty());
|
||||
EXPECT_TRUE(G->empty());
|
||||
EXPECT_TRUE(H->empty());
|
||||
EXPECT_TRUE(J->empty());
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
|
||||
// Materialize h.
|
||||
ASSERT_FALSE(H->materialize());
|
||||
EXPECT_TRUE(F->empty());
|
||||
EXPECT_TRUE(G->empty());
|
||||
EXPECT_FALSE(H->empty());
|
||||
EXPECT_TRUE(J->empty());
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
|
||||
// Materialize g.
|
||||
ASSERT_FALSE(G->materialize());
|
||||
EXPECT_TRUE(F->empty());
|
||||
EXPECT_FALSE(G->empty());
|
||||
EXPECT_FALSE(H->empty());
|
||||
EXPECT_TRUE(J->empty());
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
|
||||
// Materialize j.
|
||||
ASSERT_FALSE(J->materialize());
|
||||
EXPECT_TRUE(F->empty());
|
||||
EXPECT_FALSE(G->empty());
|
||||
EXPECT_FALSE(H->empty());
|
||||
EXPECT_FALSE(J->empty());
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
|
||||
// Materialize f.
|
||||
ASSERT_FALSE(F->materialize());
|
||||
EXPECT_FALSE(F->empty());
|
||||
EXPECT_FALSE(G->empty());
|
||||
EXPECT_FALSE(H->empty());
|
||||
EXPECT_FALSE(J->empty());
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
}
|
||||
|
||||
TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677
|
||||
SmallString<1024> Mem;
|
||||
|
||||
LLVMContext Context;
|
||||
std::unique_ptr<Module> M = getLazyModuleFromAssembly(
|
||||
Context, Mem, "@table = constant i8* blockaddress(@func, %bb)\n"
|
||||
"define void @func() {\n"
|
||||
" unreachable\n"
|
||||
"bb:\n"
|
||||
" unreachable\n"
|
||||
"}\n");
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
EXPECT_FALSE(M->getFunction("func")->empty());
|
||||
}
|
||||
|
||||
TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionBefore) {
|
||||
SmallString<1024> Mem;
|
||||
|
||||
LLVMContext Context;
|
||||
std::unique_ptr<Module> M = getLazyModuleFromAssembly(
|
||||
Context, Mem, "define i8* @before() {\n"
|
||||
" ret i8* blockaddress(@func, %bb)\n"
|
||||
"}\n"
|
||||
"define void @other() {\n"
|
||||
" unreachable\n"
|
||||
"}\n"
|
||||
"define void @func() {\n"
|
||||
" unreachable\n"
|
||||
"bb:\n"
|
||||
" unreachable\n"
|
||||
"}\n");
|
||||
EXPECT_TRUE(M->getFunction("before")->empty());
|
||||
EXPECT_TRUE(M->getFunction("func")->empty());
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
|
||||
// Materialize @before, pulling in @func.
|
||||
EXPECT_FALSE(M->getFunction("before")->materialize());
|
||||
EXPECT_FALSE(M->getFunction("func")->empty());
|
||||
EXPECT_TRUE(M->getFunction("other")->empty());
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
}
|
||||
|
||||
TEST(BitReaderTest, MaterializeFunctionsForBlockAddrInFunctionAfter) {
|
||||
SmallString<1024> Mem;
|
||||
|
||||
LLVMContext Context;
|
||||
std::unique_ptr<Module> M = getLazyModuleFromAssembly(
|
||||
Context, Mem, "define void @func() {\n"
|
||||
" unreachable\n"
|
||||
"bb:\n"
|
||||
" unreachable\n"
|
||||
"}\n"
|
||||
"define void @other() {\n"
|
||||
" unreachable\n"
|
||||
"}\n"
|
||||
"define i8* @after() {\n"
|
||||
" ret i8* blockaddress(@func, %bb)\n"
|
||||
"}\n");
|
||||
EXPECT_TRUE(M->getFunction("after")->empty());
|
||||
EXPECT_TRUE(M->getFunction("func")->empty());
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
|
||||
// Materialize @after, pulling in @func.
|
||||
EXPECT_FALSE(M->getFunction("after")->materialize());
|
||||
EXPECT_FALSE(M->getFunction("func")->empty());
|
||||
EXPECT_TRUE(M->getFunction("other")->empty());
|
||||
EXPECT_FALSE(verifyModule(*M, &dbgs()));
|
||||
}
|
||||
|
||||
} // end namespace
|
@ -1,151 +0,0 @@
|
||||
//===- BitstreamReaderTest.cpp - Tests for BitstreamReader ----------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Bitcode/BitstreamReader.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/Bitcode/BitstreamWriter.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(BitstreamReaderTest, AtEndOfStream) {
|
||||
uint8_t Bytes[4] = {
|
||||
0x00, 0x01, 0x02, 0x03
|
||||
};
|
||||
BitstreamCursor Cursor(Bytes);
|
||||
|
||||
EXPECT_FALSE(Cursor.AtEndOfStream());
|
||||
(void)Cursor.Read(8);
|
||||
EXPECT_FALSE(Cursor.AtEndOfStream());
|
||||
(void)Cursor.Read(24);
|
||||
EXPECT_TRUE(Cursor.AtEndOfStream());
|
||||
|
||||
Cursor.JumpToBit(0);
|
||||
EXPECT_FALSE(Cursor.AtEndOfStream());
|
||||
|
||||
Cursor.JumpToBit(32);
|
||||
EXPECT_TRUE(Cursor.AtEndOfStream());
|
||||
}
|
||||
|
||||
TEST(BitstreamReaderTest, AtEndOfStreamJump) {
|
||||
uint8_t Bytes[4] = {
|
||||
0x00, 0x01, 0x02, 0x03
|
||||
};
|
||||
BitstreamCursor Cursor(Bytes);
|
||||
|
||||
Cursor.JumpToBit(32);
|
||||
EXPECT_TRUE(Cursor.AtEndOfStream());
|
||||
}
|
||||
|
||||
TEST(BitstreamReaderTest, AtEndOfStreamEmpty) {
|
||||
BitstreamCursor Cursor(ArrayRef<uint8_t>{});
|
||||
|
||||
EXPECT_TRUE(Cursor.AtEndOfStream());
|
||||
}
|
||||
|
||||
TEST(BitstreamReaderTest, getCurrentByteNo) {
|
||||
uint8_t Bytes[] = {0x00, 0x01, 0x02, 0x03};
|
||||
SimpleBitstreamCursor Cursor(Bytes);
|
||||
|
||||
for (unsigned I = 0, E = 32; I != E; ++I) {
|
||||
EXPECT_EQ(I / 8, Cursor.getCurrentByteNo());
|
||||
(void)Cursor.Read(1);
|
||||
}
|
||||
EXPECT_EQ(4u, Cursor.getCurrentByteNo());
|
||||
}
|
||||
|
||||
TEST(BitstreamReaderTest, getPointerToByte) {
|
||||
uint8_t Bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
|
||||
SimpleBitstreamCursor Cursor(Bytes);
|
||||
|
||||
for (unsigned I = 0, E = 8; I != E; ++I) {
|
||||
EXPECT_EQ(Bytes + I, Cursor.getPointerToByte(I, 1));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BitstreamReaderTest, getPointerToBit) {
|
||||
uint8_t Bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
|
||||
SimpleBitstreamCursor Cursor(Bytes);
|
||||
|
||||
for (unsigned I = 0, E = 8; I != E; ++I) {
|
||||
EXPECT_EQ(Bytes + I, Cursor.getPointerToBit(I * 8, 1));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BitstreamReaderTest, readRecordWithBlobWhileStreaming) {
|
||||
SmallVector<uint8_t, 1> BlobData;
|
||||
for (unsigned I = 0, E = 1024; I != E; ++I)
|
||||
BlobData.push_back(I);
|
||||
|
||||
// Try a bunch of different sizes.
|
||||
const unsigned Magic = 0x12345678;
|
||||
const unsigned BlockID = bitc::FIRST_APPLICATION_BLOCKID;
|
||||
const unsigned RecordID = 1;
|
||||
for (unsigned I = 0, BlobSize = 0, E = BlobData.size(); BlobSize < E;
|
||||
BlobSize += ++I) {
|
||||
StringRef BlobIn((const char *)BlobData.begin(), BlobSize);
|
||||
|
||||
// Write the bitcode.
|
||||
SmallVector<char, 1> Buffer;
|
||||
unsigned AbbrevID;
|
||||
{
|
||||
BitstreamWriter Stream(Buffer);
|
||||
Stream.Emit(Magic, 32);
|
||||
Stream.EnterSubblock(BlockID, 3);
|
||||
|
||||
auto Abbrev = std::make_shared<BitCodeAbbrev>();
|
||||
Abbrev->Add(BitCodeAbbrevOp(RecordID));
|
||||
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
|
||||
AbbrevID = Stream.EmitAbbrev(std::move(Abbrev));
|
||||
unsigned Record[] = {RecordID};
|
||||
Stream.EmitRecordWithBlob(AbbrevID, makeArrayRef(Record), BlobIn);
|
||||
|
||||
Stream.ExitBlock();
|
||||
}
|
||||
|
||||
// Stream the buffer into the reader.
|
||||
BitstreamCursor Stream(
|
||||
ArrayRef<uint8_t>((const uint8_t *)Buffer.begin(), Buffer.size()));
|
||||
|
||||
// Header. Included in test so that we can run llvm-bcanalyzer to debug
|
||||
// when there are problems.
|
||||
ASSERT_EQ(Magic, Stream.Read(32));
|
||||
|
||||
// Block.
|
||||
BitstreamEntry Entry =
|
||||
Stream.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs);
|
||||
ASSERT_EQ(BitstreamEntry::SubBlock, Entry.Kind);
|
||||
ASSERT_EQ(BlockID, Entry.ID);
|
||||
ASSERT_FALSE(Stream.EnterSubBlock(BlockID));
|
||||
|
||||
// Abbreviation.
|
||||
Entry = Stream.advance();
|
||||
ASSERT_EQ(BitstreamEntry::Record, Entry.Kind);
|
||||
ASSERT_EQ(AbbrevID, Entry.ID);
|
||||
|
||||
// Record.
|
||||
StringRef BlobOut;
|
||||
SmallVector<uint64_t, 1> Record;
|
||||
ASSERT_EQ(RecordID, Stream.readRecord(Entry.ID, Record, &BlobOut));
|
||||
EXPECT_TRUE(Record.empty());
|
||||
EXPECT_EQ(BlobIn, BlobOut);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BitstreamReaderTest, shortRead) {
|
||||
uint8_t Bytes[] = {8, 7, 6, 5, 4, 3, 2, 1};
|
||||
for (unsigned I = 1; I != 8; ++I) {
|
||||
SimpleBitstreamCursor Cursor(ArrayRef<uint8_t>(Bytes, I));
|
||||
EXPECT_EQ(8ull, Cursor.Read(8));
|
||||
}
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
@ -1,59 +0,0 @@
|
||||
//===- BitstreamWriterTest.cpp - Tests for BitstreamWriter ----------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Bitcode/BitstreamWriter.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(BitstreamWriterTest, emitBlob) {
|
||||
SmallString<64> Buffer;
|
||||
BitstreamWriter W(Buffer);
|
||||
W.emitBlob("str", /* ShouldEmitSize */ false);
|
||||
EXPECT_EQ(StringRef("str\0", 4), Buffer);
|
||||
}
|
||||
|
||||
TEST(BitstreamWriterTest, emitBlobWithSize) {
|
||||
SmallString<64> Buffer;
|
||||
{
|
||||
BitstreamWriter W(Buffer);
|
||||
W.emitBlob("str");
|
||||
}
|
||||
SmallString<64> Expected;
|
||||
{
|
||||
BitstreamWriter W(Expected);
|
||||
W.EmitVBR(3, 6);
|
||||
W.FlushToWord();
|
||||
W.Emit('s', 8);
|
||||
W.Emit('t', 8);
|
||||
W.Emit('r', 8);
|
||||
W.Emit(0, 8);
|
||||
}
|
||||
EXPECT_EQ(StringRef(Expected), Buffer);
|
||||
}
|
||||
|
||||
TEST(BitstreamWriterTest, emitBlobEmpty) {
|
||||
SmallString<64> Buffer;
|
||||
BitstreamWriter W(Buffer);
|
||||
W.emitBlob("", /* ShouldEmitSize */ false);
|
||||
EXPECT_EQ(StringRef(""), Buffer);
|
||||
}
|
||||
|
||||
TEST(BitstreamWriterTest, emitBlob4ByteAligned) {
|
||||
SmallString<64> Buffer;
|
||||
BitstreamWriter W(Buffer);
|
||||
W.emitBlob("str0", /* ShouldEmitSize */ false);
|
||||
EXPECT_EQ(StringRef("str0"), Buffer);
|
||||
}
|
||||
|
||||
} // end namespace
|
13
external/llvm/unittests/Bitcode/CMakeLists.txt
vendored
13
external/llvm/unittests/Bitcode/CMakeLists.txt
vendored
@ -1,13 +0,0 @@
|
||||
set(LLVM_LINK_COMPONENTS
|
||||
AsmParser
|
||||
BitReader
|
||||
BitWriter
|
||||
Core
|
||||
Support
|
||||
)
|
||||
|
||||
add_llvm_unittest(BitcodeTests
|
||||
BitReaderTest.cpp
|
||||
BitstreamReaderTest.cpp
|
||||
BitstreamWriterTest.cpp
|
||||
)
|
Reference in New Issue
Block a user