From 145449b1e420787bb99721a429341fa6be3adfb6 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 3 Jul 2022 16:10:23 +0200 Subject: Vendor import of llvm-project main llvmorg-15-init-15358-g53dc0f107877. --- llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp | 33 +++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp') diff --git a/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp b/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp index 1af59ff679dd..a66f9af98835 100644 --- a/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp +++ b/llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp @@ -8,7 +8,9 @@ #include "llvm/DebugInfo/CodeView/CodeViewRecordIO.h" #include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/GUID.h" #include "llvm/DebugInfo/CodeView/RecordSerialization.h" +#include "llvm/DebugInfo/CodeView/TypeIndex.h" #include "llvm/Support/BinaryStreamReader.h" #include "llvm/Support/BinaryStreamWriter.h" @@ -68,10 +70,10 @@ uint32_t CodeViewRecordIO::maxFieldLength() const { Optional Min = Limits.front().bytesRemaining(Offset); for (auto X : makeArrayRef(Limits).drop_front()) { Optional ThisMin = X.bytesRemaining(Offset); - if (ThisMin.hasValue()) - Min = (Min.hasValue()) ? std::min(*Min, *ThisMin) : *ThisMin; + if (ThisMin) + Min = Min ? std::min(*Min, *ThisMin) : *ThisMin; } - assert(Min.hasValue() && "Every field must have a maximum length!"); + assert(Min && "Every field must have a maximum length!"); return *Min; } @@ -279,17 +281,24 @@ void CodeViewRecordIO::emitEncodedSignedInteger(const int64_t &Value, // FIXME: There are no test cases covering this function. // This may be because we always consider enumerators to be unsigned. // See FIXME at CodeViewDebug.cpp : CodeViewDebug::lowerTypeEnum. - if (Value >= std::numeric_limits::min()) { + if (Value < LF_NUMERIC && Value >= 0) { + emitComment(Comment); + Streamer->emitIntValue(Value, 2); + incrStreamedLen(2); + } else if (Value >= std::numeric_limits::min() && + Value <= std::numeric_limits::max()) { Streamer->emitIntValue(LF_CHAR, 2); emitComment(Comment); Streamer->emitIntValue(Value, 1); incrStreamedLen(3); - } else if (Value >= std::numeric_limits::min()) { + } else if (Value >= std::numeric_limits::min() && + Value <= std::numeric_limits::max()) { Streamer->emitIntValue(LF_SHORT, 2); emitComment(Comment); Streamer->emitIntValue(Value, 2); incrStreamedLen(4); - } else if (Value >= std::numeric_limits::min()) { + } else if (Value >= std::numeric_limits::min() && + Value <= std::numeric_limits::max()) { Streamer->emitIntValue(LF_LONG, 2); emitComment(Comment); Streamer->emitIntValue(Value, 4); @@ -328,17 +337,23 @@ void CodeViewRecordIO::emitEncodedUnsignedInteger(const uint64_t &Value, } Error CodeViewRecordIO::writeEncodedSignedInteger(const int64_t &Value) { - if (Value >= std::numeric_limits::min()) { + if (Value < LF_NUMERIC && Value >= 0) { + if (auto EC = Writer->writeInteger(Value)) + return EC; + } else if (Value >= std::numeric_limits::min() && + Value <= std::numeric_limits::max()) { if (auto EC = Writer->writeInteger(LF_CHAR)) return EC; if (auto EC = Writer->writeInteger(Value)) return EC; - } else if (Value >= std::numeric_limits::min()) { + } else if (Value >= std::numeric_limits::min() && + Value <= std::numeric_limits::max()) { if (auto EC = Writer->writeInteger(LF_SHORT)) return EC; if (auto EC = Writer->writeInteger(Value)) return EC; - } else if (Value >= std::numeric_limits::min()) { + } else if (Value >= std::numeric_limits::min() && + Value <= std::numeric_limits::max()) { if (auto EC = Writer->writeInteger(LF_LONG)) return EC; if (auto EC = Writer->writeInteger(Value)) -- cgit v1.2.3