arphaman created this revision.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D35069

Files:
  lib/Frontend/SerializedDiagnosticReader.cpp
  test/Index/Inputs/empty.dia
  test/Index/read-empty-diags.test


Index: test/Index/read-empty-diags.test
===================================================================
--- /dev/null
+++ test/Index/read-empty-diags.test
@@ -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
Index: lib/Frontend/SerializedDiagnosticReader.cpp
===================================================================
--- lib/Frontend/SerializedDiagnosticReader.cpp
+++ lib/Frontend/SerializedDiagnosticReader.cpp
@@ -27,6 +27,9 @@
   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' ||


Index: test/Index/read-empty-diags.test
===================================================================
--- /dev/null
+++ test/Index/read-empty-diags.test
@@ -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
Index: lib/Frontend/SerializedDiagnosticReader.cpp
===================================================================
--- lib/Frontend/SerializedDiagnosticReader.cpp
+++ lib/Frontend/SerializedDiagnosticReader.cpp
@@ -27,6 +27,9 @@
   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' ||
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D35069: [F... Alex Lorenz via Phabricator via cfe-commits

Reply via email to