[llvm] f4fca0f - [Bitcode] Replace assertion with check

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 7 03:40:41 PST 2022


Author: Nikita Popov
Date: 2022-02-07T12:39:35+01:00
New Revision: f4fca0fbb052e55935b483c8955c440b59511ce8

URL: https://github.com/llvm/llvm-project/commit/f4fca0fbb052e55935b483c8955c440b59511ce8
DIFF: https://github.com/llvm/llvm-project/commit/f4fca0fbb052e55935b483c8955c440b59511ce8.diff

LOG: [Bitcode] Replace assertion with check

Added: 
    llvm/test/Bitcode/Inputs/invalid-value-symbol-table-2.bc

Modified: 
    llvm/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/test/Bitcode/invalid.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 33f0f87108d9..66f2dccbf695 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -2056,8 +2056,9 @@ static Expected<uint64_t> jumpToValueSymbolTable(uint64_t Offset,
   Expected<BitstreamEntry> MaybeEntry = Stream.advance();
   if (!MaybeEntry)
     return MaybeEntry.takeError();
-  assert(MaybeEntry.get().Kind == BitstreamEntry::SubBlock);
-  assert(MaybeEntry.get().ID == bitc::VALUE_SYMTAB_BLOCK_ID);
+  if (MaybeEntry.get().Kind != BitstreamEntry::SubBlock ||
+      MaybeEntry.get().ID != bitc::VALUE_SYMTAB_BLOCK_ID)
+    return error("Expected value symbol table subblock");
   return CurrentBit;
 }
 

diff  --git a/llvm/test/Bitcode/Inputs/invalid-value-symbol-table-2.bc b/llvm/test/Bitcode/Inputs/invalid-value-symbol-table-2.bc
new file mode 100644
index 000000000000..a6e4250730f9
Binary files /dev/null and b/llvm/test/Bitcode/Inputs/invalid-value-symbol-table-2.bc 
diff er

diff  --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test
index 32f93ab160e9..fd0fae93171e 100644
--- a/llvm/test/Bitcode/invalid.test
+++ b/llvm/test/Bitcode/invalid.test
@@ -271,3 +271,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-value-symbol-table.bc 2>&1 |
 RUN:   FileCheck --check-prefix=INVALID-VALUE-SYMBOL-TABLE %s
 
 INVALID-VALUE-SYMBOL-TABLE: Invalid value reference in symbol table
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-value-symbol-table-2.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=INVALID-VALUE-SYMBOL-TABLE-2 %s
+
+INVALID-VALUE-SYMBOL-TABLE-2: Expected value symbol table subblock


        


More information about the llvm-commits mailing list