From 7ab83427af0f77b59941ceba41d509d7d097b065 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 10 Jun 2017 13:44:06 +0000 Subject: Vendor import of llvm trunk r305145: https://llvm.org/svn/llvm-project/llvm/trunk@305145 --- lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp | 28 ++++++++++-------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp') diff --git a/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp b/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp index cfd1c5d3ab0c..e9124e68fe82 100644 --- a/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp +++ b/lib/DebugInfo/CodeView/DebugSubsectionRecord.cpp @@ -34,14 +34,6 @@ Error DebugSubsectionRecord::initialize(BinaryStreamRef Stream, DebugSubsectionKind Kind = static_cast(uint32_t(Header->Kind)); - switch (Kind) { - case DebugSubsectionKind::FileChecksums: - case DebugSubsectionKind::Lines: - case DebugSubsectionKind::InlineeLines: - break; - default: - llvm_unreachable("Unexpected debug fragment kind!"); - } if (auto EC = Reader.readStreamRef(Info.Data, Header->Length)) return EC; Info.Container = Container; @@ -50,9 +42,7 @@ Error DebugSubsectionRecord::initialize(BinaryStreamRef Stream, } uint32_t DebugSubsectionRecord::getRecordLength() const { - uint32_t Result = sizeof(DebugSubsectionHeader) + Data.getLength(); - assert(Result % alignOf(Container) == 0); - return Result; + return sizeof(DebugSubsectionHeader) + Data.getLength(); } DebugSubsectionKind DebugSubsectionRecord::kind() const { return Kind; } @@ -64,25 +54,29 @@ DebugSubsectionRecordBuilder::DebugSubsectionRecordBuilder( : Subsection(std::move(Subsection)), Container(Container) {} uint32_t DebugSubsectionRecordBuilder::calculateSerializedLength() { - uint32_t Size = - sizeof(DebugSubsectionHeader) + - alignTo(Subsection->calculateSerializedSize(), alignOf(Container)); + // The length of the entire subsection is always padded to 4 bytes, regardless + // of the container kind. + uint32_t Size = sizeof(DebugSubsectionHeader) + + alignTo(Subsection->calculateSerializedSize(), 4); return Size; } -Error DebugSubsectionRecordBuilder::commit(BinaryStreamWriter &Writer) { +Error DebugSubsectionRecordBuilder::commit(BinaryStreamWriter &Writer) const { assert(Writer.getOffset() % alignOf(Container) == 0 && "Debug Subsection not properly aligned"); DebugSubsectionHeader Header; Header.Kind = uint32_t(Subsection->kind()); - Header.Length = calculateSerializedLength() - sizeof(DebugSubsectionHeader); + // The value written into the Header's Length field is only padded to the + // container's alignment + Header.Length = + alignTo(Subsection->calculateSerializedSize(), alignOf(Container)); if (auto EC = Writer.writeObject(Header)) return EC; if (auto EC = Subsection->commit(Writer)) return EC; - if (auto EC = Writer.padToAlignment(alignOf(Container))) + if (auto EC = Writer.padToAlignment(4)) return EC; return Error::success(); -- cgit v1.3