]> granicus.if.org Git - clang/commitdiff
Once we've emitted a fatal diagnostic, keep counting errors but with a
authorDouglas Gregor <dgregor@apple.com>
Wed, 14 Apr 2010 22:19:45 +0000 (22:19 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 14 Apr 2010 22:19:45 +0000 (22:19 +0000)
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>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101297 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
lib/Frontend/CompilerInstance.cpp
test/SemaCXX/missing-header.cpp [new file with mode: 0644]

index 8c959b7cea23c635f4ec24b07f3207db0dfa300f..21e2b3e1a5fc7c746d923bd189f2bc239b0fdb3e 100644 (file)
@@ -214,7 +214,8 @@ private:
 
   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 @@ public:
   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
index bd1d6e8b70e9efaa2ce26ddb8cda143d26d44239..755fbed66f3bea4639d83d5c5a62e9840ceb636a 100644 (file)
@@ -227,6 +227,7 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
   
   NumWarnings = 0;
   NumErrors = 0;
+  NumErrorsSuppressed = 0;
   CustomDiagInfo = 0;
   CurDiagID = ~0U;
   LastDiagLevel = Ignored;
@@ -537,8 +538,14 @@ bool Diagnostic::ProcessDiag() {
 
   // 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.
index 685e6c281cc26e9a907cbb4755646136cb84542a..5ed9c409a3dcecc3a875fd07630cd4d98fc41efe 100644 (file)
@@ -515,7 +515,8 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
 
   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");
diff --git a/test/SemaCXX/missing-header.cpp b/test/SemaCXX/missing-header.cpp
new file mode 100644 (file)
index 0000000..f436579
--- /dev/null
@@ -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;
+}