BitcodeReader: Allow METADATA_STRINGS to only have !""
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 29 Mar 2016 05:25:17 +0000 (05:25 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 29 Mar 2016 05:25:17 +0000 (05:25 +0000)
Support parsing a METADATA_STRINGS record that only has a single piece
of metadata, !"".  Fixes a corner case in r264551.

llvm-svn: 264699

llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/test/Bitcode/metadata-only-empty-string.ll [new file with mode: 0644]

index cb2784f..72ac217 100644 (file)
@@ -1899,7 +1899,7 @@ std::error_code BitcodeReader::parseMetadataStrings(ArrayRef<uint64_t> Record,
   unsigned StringsOffset = Record[1];
   if (!NumStrings)
     return error("Invalid record: metadata strings with no strings");
-  if (StringsOffset >= Blob.size())
+  if (StringsOffset > Blob.size())
     return error("Invalid record: metadata strings corrupt offset");
 
   StringRef Lengths = Blob.slice(0, StringsOffset);
diff --git a/llvm/test/Bitcode/metadata-only-empty-string.ll b/llvm/test/Bitcode/metadata-only-empty-string.ll
new file mode 100644 (file)
index 0000000..f8331e3
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+; CHECK: !named = !{!0}
+!named = !{!0}
+
+; CHECK: !0 = !{!""}
+!0 = !{!""}