From 08bbd35a80bf7765fe0d3043f9eb5a2f2786b649 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 26 Jun 2017 20:32:52 +0000 Subject: Vendor import of llvm trunk r306325: https://llvm.org/svn/llvm-project/llvm/trunk@306325 --- .../DebugInfo/CodeView/RandomAccessVisitorTest.cpp | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp') diff --git a/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp b/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp index 4fa172a37ef2d..92134513b75b9 100644 --- a/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp +++ b/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp @@ -351,3 +351,55 @@ TEST_F(RandomAccessVisitorTest, InnerChunk) { for (auto &I : enumerate(IndicesToVisit)) EXPECT_TRUE(ValidateVisitedRecord(I.index(), I.value())); } + +TEST_F(RandomAccessVisitorTest, CrossChunkName) { + TypeTableBuilder Builder(GlobalState->Allocator); + + // TypeIndex 0 + ClassRecord Class(TypeRecordKind::Class); + Class.Name = "FooClass"; + Class.Options = ClassOptions::None; + Class.MemberCount = 0; + Class.Size = 4U; + Class.DerivationList = TypeIndex::fromArrayIndex(0); + Class.FieldList = TypeIndex::fromArrayIndex(0); + Class.VTableShape = TypeIndex::fromArrayIndex(0); + TypeIndex IndexZero = Builder.writeKnownType(Class); + + // TypeIndex 1 refers to type index 0. + ModifierRecord Modifier(TypeRecordKind::Modifier); + Modifier.ModifiedType = TypeIndex::fromArrayIndex(0); + Modifier.Modifiers = ModifierOptions::Const; + TypeIndex IndexOne = Builder.writeKnownType(Modifier); + + // set up a type stream that refers to the above two serialized records. + std::vector TypeArray; + TypeArray.push_back( + CVType(static_cast(Class.Kind), Builder.records()[0])); + TypeArray.push_back( + CVType(static_cast(Modifier.Kind), Builder.records()[1])); + BinaryItemStream ItemStream(llvm::support::little); + ItemStream.setItems(TypeArray); + VarStreamArray TypeStream(ItemStream); + + // Figure out the byte offset of the second item. + auto ItemOneIter = TypeStream.begin(); + ++ItemOneIter; + + // Set up a partial offsets buffer that contains the first and second items + // in separate chunks. + std::vector TIO; + TIO.push_back({IndexZero, ulittle32_t(0u)}); + TIO.push_back({IndexOne, ulittle32_t(ItemOneIter.offset())}); + ArrayRef Buffer(reinterpret_cast(TIO.data()), + TIO.size() * sizeof(TypeIndexOffset)); + + BinaryStreamReader Reader(Buffer, llvm::support::little); + FixedStreamArray PartialOffsets; + ASSERT_THAT_ERROR(Reader.readArray(PartialOffsets, 2), Succeeded()); + + LazyRandomTypeCollection Types(TypeStream, 2, PartialOffsets); + + StringRef Name = Types.getTypeName(IndexOne); + EXPECT_EQ("const FooClass", Name); +} \ No newline at end of file -- cgit v1.2.3