Index: tools/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
==================================================================
--- tools/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ tools/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -102,12 +102,13 @@
 
 void VerifyDiagnosticConsumer::HandleDiagnostic(
       DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) {
 #ifndef NDEBUG
   if (Info.hasSourceManager()) {
-    const SourceManager &SM = Info.getSourceManager();
-    FilesWithDiagnostics.insert(SM.getFileID(Info.getLocation()));
+    FileID FID = Info.getSourceManager().getFileID(Info.getLocation());
+    if (!FID.isInvalid())
+      FilesWithDiagnostics.insert(FID);
   }
 #endif
   // Send the diagnostic to the buffer, we will check it once we reach the end
   // of the source file (or are destructed).
   Buffer->HandleDiagnostic(DiagLevel, Info);

Index: tools/clang/test/Frontend/verify.c
==================================================================
--- tools/clang/test/Frontend/verify.c
+++ tools/clang/test/Frontend/verify.c
@@ -106,5 +106,20 @@
 // CHECK5-NEXT:   Line 1 (directive at {{.*}}verify-directive.h:2): include file test
 // CHECK5-NEXT:   Line 50 (directive at {{.*}}verify.c:103): source file test
 // CHECK5-NEXT: 2 errors generated.
 #endif
 
+#if 0
+// RUN: %clang_cc1 -verify %t.invalid 2>&1 | FileCheck -check-prefix=CHECK6 %s
+
+//      CHECK6: error: 'error' diagnostics seen but not expected:
+// CHECK6-NEXT:   (frontend): error reading '{{.*}}verify.c.tmp.invalid'
+// CHECK6-NEXT: 1 error generated.
+
+// RUN: echo -e '//expected-error@2{{1}}\n#error 2' | %clang_cc1 -verify 2>&1 | FileCheck -check-prefix=CHECK7 %s
+
+//      CHECK7: error: 'error' diagnostics expected but not seen:
+// CHECK7-NEXT:   Line 2 (directive at <stdin>:1): 1
+// CHECK7-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK7-NEXT:   Line 2: 2
+// CHECK7-NEXT: 2 errors generated.
+#endif

