[llvm] 4a794d8 - [Bitstream] Improve error propagation from ReadVBR
Jan Korous via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 15 17:12:54 PST 2022
Author: Jan Korous
Date: 2022-02-15T17:12:38-08:00
New Revision: 4a794d848ce81f41c6e23a4d3d3f70c2d7d1baa4
URL: https://github.com/llvm/llvm-project/commit/4a794d848ce81f41c6e23a4d3d3f70c2d7d1baa4
DIFF: https://github.com/llvm/llvm-project/commit/4a794d848ce81f41c6e23a4d3d3f70c2d7d1baa4.diff
LOG: [Bitstream] Improve error propagation from ReadVBR
Differential Revision: https://reviews.llvm.org/D119307
Added:
Modified:
llvm/lib/Bitstream/Reader/BitstreamReader.cpp
llvm/test/Bitcode/invalid.test
Removed:
################################################################################
diff --git a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
index b2da7e721e256..ac674e88c61cc 100644
--- a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
+++ b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
@@ -220,7 +220,9 @@ Expected<unsigned> BitstreamCursor::readRecord(unsigned AbbrevID,
uint32_t Code = MaybeCode.get();
Expected<uint32_t> MaybeNumElts = ReadVBR(6);
if (!MaybeNumElts)
- return MaybeNumElts.takeError();
+ return error(("Failed to read size: " +
+ toString(std::move(MaybeNumElts.takeError())))
+ .c_str());
uint32_t NumElts = MaybeNumElts.get();
if (!isSizePlausible(NumElts))
return error("Size is not plausible");
@@ -275,7 +277,9 @@ Expected<unsigned> BitstreamCursor::readRecord(unsigned AbbrevID,
// Array case. Read the number of elements as a vbr6.
Expected<uint32_t> MaybeNumElts = ReadVBR(6);
if (!MaybeNumElts)
- return MaybeNumElts.takeError();
+ return error(("Failed to read size: " +
+ toString(std::move(MaybeNumElts.takeError())))
+ .c_str());
uint32_t NumElts = MaybeNumElts.get();
if (!isSizePlausible(NumElts))
return error("Size is not plausible");
diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test
index 26371504bab7e..ab24a1b2152c7 100644
--- a/llvm/test/Bitcode/invalid.test
+++ b/llvm/test/Bitcode/invalid.test
@@ -275,7 +275,7 @@ INVALID-VALUE-SYMBOL-TABLE: Invalid value reference in symbol table
RUN: not llvm-dis -disable-output %p/Inputs/unterminated-vbr.bc 2>&1 | \
RUN: FileCheck --check-prefix=UNTERMINATED-VBR %s
-UNTERMINATED-VBR: Unterminated VBR
+UNTERMINATED-VBR: Failed to read size: Unterminated VBR
RUN: not llvm-dis -disable-output %p/Inputs/comdat-name-too-large.bc 2>&1 | \
RUN: FileCheck --check-prefix=COMDAT-NAME-TOO-LARGE %s
More information about the llvm-commits
mailing list