[cfe-commits] r101297 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Frontend/CompilerInstance.cpp test/SemaCXX/missing-header.cpp

Douglas Gregor dgregor at apple.com
Wed Apr 14 15:19:45 PDT 2010


Author: dgregor
Date: Wed Apr 14 17:19:45 2010
New Revision: 101297

URL: http://llvm.org/viewvc/llvm-project?rev=101297&view=rev
Log:
Once we've emitted a fatal diagnostic, keep counting errors but with a
separate count of "suppressed" errors. This way, semantic analysis
bits that depend on the error count to determine whether problems
occured (e.g., some template argument deduction failures, jump-scope
checking) will not get confused.

The actual problem here is that a missing #include (which is a fatal
error) could cause the jump-scope checker to run on invalid code,
which it is not prepared to do. Trivial fix for both
<rdar://problem/7775941> and <rdar://problem/7775709>.


Added:
    cfe/trunk/test/SemaCXX/missing-header.cpp
Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/lib/Frontend/CompilerInstance.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=101297&r1=101296&r2=101297&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Apr 14 17:19:45 2010
@@ -214,7 +214,8 @@
 
   unsigned NumWarnings;       // Number of warnings reported
   unsigned NumErrors;         // Number of errors reported
-
+  unsigned NumErrorsSuppressed; // Number of errors suppressed
+  
   /// CustomDiagInfo - Information for uniquing and looking up custom diags.
   diag::CustomDiagInfo *CustomDiagInfo;
 
@@ -343,6 +344,7 @@
   bool hasFatalErrorOccurred() const { return FatalErrorOccurred; }
 
   unsigned getNumErrors() const { return NumErrors; }
+  unsigned getNumErrorsSuppressed() const { return NumErrorsSuppressed; }
   unsigned getNumWarnings() const { return NumWarnings; }
 
   /// getCustomDiagID - Return an ID for a diagnostic with the specified message

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=101297&r1=101296&r2=101297&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Apr 14 17:19:45 2010
@@ -227,6 +227,7 @@
   
   NumWarnings = 0;
   NumErrors = 0;
+  NumErrorsSuppressed = 0;
   CustomDiagInfo = 0;
   CurDiagID = ~0U;
   LastDiagLevel = Ignored;
@@ -537,8 +538,14 @@
 
   // If a fatal error has already been emitted, silence all subsequent
   // diagnostics.
-  if (FatalErrorOccurred)
+  if (FatalErrorOccurred) {
+    if (DiagLevel >= Diagnostic::Error) {
+      ++NumErrors;
+      ++NumErrorsSuppressed;
+    }
+    
     return false;
+  }
 
   // If the client doesn't care about this message, don't issue it.  If this is
   // a note and the last real diagnostic was ignored, ignore it too.

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=101297&r1=101296&r2=101297&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Wed Apr 14 17:19:45 2010
@@ -515,7 +515,8 @@
 
   if (getDiagnosticOpts().ShowCarets) {
     unsigned NumWarnings = getDiagnostics().getNumWarnings();
-    unsigned NumErrors = getDiagnostics().getNumErrors();
+    unsigned NumErrors = getDiagnostics().getNumErrors() - 
+                               getDiagnostics().getNumErrorsSuppressed();
     
     if (NumWarnings)
       OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s");

Added: cfe/trunk/test/SemaCXX/missing-header.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/missing-header.cpp?rev=101297&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/missing-header.cpp (added)
+++ cfe/trunk/test/SemaCXX/missing-header.cpp Wed Apr 14 17:19:45 2010
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#include "not exist" // expected-error{{'not exist' file not found}}
+
+class AnalysisContext {};
+static ControlFlowKind CheckFallThrough(AnalysisContext &AC) {
+  if (const AsmStmt *AS = dyn_cast<AsmStmt>(S)) {}
+  bool NoReturnEdge = false;
+}





More information about the cfe-commits mailing list