[Frontend] Verify that the bitstream is not empty before reading

the serialised diagnostics

Clang should avoid calling report_fatal_error when the file with the serialised
diagnostics is empty. This commit changes Clang's serialised diagnostic reader,
now it reports an appropriate error instead of crashing.

rdar://31939877

Differential Revision: https://reviews.llvm.org/D35069

llvm-svn: 307384
This commit is contained in:
Alex Lorenz 2017-07-07 10:25:12 +00:00
parent 66a6d0146a
commit 5ff6b8655a
3 changed files with 5 additions and 0 deletions

View File

@ -27,6 +27,9 @@ std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) {
llvm::BitstreamCursor Stream(**Buffer);
Optional<llvm::BitstreamBlockInfo> BlockInfo;
if (Stream.AtEndOfStream())
return SDError::InvalidSignature;
// Sniff for the signature.
if (Stream.Read(8) != 'D' ||
Stream.Read(8) != 'I' ||

View File

View File

@ -0,0 +1,2 @@
// RUN: not c-index-test -read-diagnostics %S/Inputs/empty.dia 2>&1 | FileCheck %s
// CHECK: Trouble deserializing file (Invalid File): Invalid diagnostics signature