[PATCH] Error out of ParseBitcodeInto(Module*) if we haven't read a Module

Filipe Cabecinhas filcab+llvm.phabricator at gmail.com
Tue Apr 14 07:10:24 PDT 2015


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D9014

Files:
  llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/trunk/test/Bitcode/Inputs/invalid-no-proper-module.bc
  llvm/trunk/test/Bitcode/invalid.test

Index: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
===================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3063,8 +3063,12 @@
   // We expect a number of well-defined blocks, though we don't necessarily
   // need to understand them all.
   while (1) {
-    if (Stream.AtEndOfStream())
-      return std::error_code();
+    if (Stream.AtEndOfStream()) {
+      if (TheModule)
+        return std::error_code();
+      // We didn't really read a proper Module.
+      return Error("Malformed IR file");
+    }
 
     BitstreamEntry Entry =
       Stream.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs);
Index: llvm/trunk/test/Bitcode/invalid.test
===================================================================
--- llvm/trunk/test/Bitcode/invalid.test
+++ llvm/trunk/test/Bitcode/invalid.test
@@ -50,3 +50,8 @@
 INSERT-ARRAY: INSERTVAL: Invalid array index
 INSERT-STRUCT: INSERTVAL: Invalid struct index
 INSERT-IDXS: INSERTVAL: Invalid type
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-no-proper-module.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=NO-MODULE %s
+
+NO-MODULE: Malformed IR file

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9014.23731.patch
Type: text/x-patch
Size: 1236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150414/07df0991/attachment.bin>


More information about the llvm-commits mailing list