summaryrefslogtreecommitdiffstats
path: root/lib/Basic/Diagnostic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Basic/Diagnostic.cpp')
-rw-r--r--lib/Basic/Diagnostic.cpp70
1 files changed, 51 insertions, 19 deletions
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index 2b7fcd0..1870195 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -11,24 +11,24 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/PartialDiagnostic.h"
-
-#include "clang/Lex/LexDiagnostic.h"
-#include "clang/Parse/ParseDiagnostic.h"
#include "clang/AST/ASTDiagnostic.h"
-#include "clang/Sema/SemaDiagnostic.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Analysis/AnalysisDiagnostic.h"
-#include "clang/Driver/DriverDiagnostic.h"
-
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/PartialDiagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Lex/LexDiagnostic.h"
+#include "clang/Parse/ParseDiagnostic.h"
+#include "clang/Sema/SemaDiagnostic.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
+
#include <vector>
#include <map>
#include <cstring>
@@ -223,9 +223,12 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
ErrorOccurred = false;
FatalErrorOccurred = false;
- NumDiagnostics = 0;
-
+ ErrorLimit = 0;
+ TemplateBacktraceLimit = 0;
+
+ NumWarnings = 0;
NumErrors = 0;
+ NumErrorsSuppressed = 0;
CustomDiagInfo = 0;
CurDiagID = ~0U;
LastDiagLevel = Ignored;
@@ -286,11 +289,18 @@ bool Diagnostic::isBuiltinNote(unsigned DiagID) {
}
/// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
-/// ID is for an extension of some sort.
+/// ID is for an extension of some sort. This also returns EnabledByDefault,
+/// which is set to indicate whether the diagnostic is ignored by default (in
+/// which case -pedantic enables it) or treated as a warning/error by default.
///
-bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID) {
- return DiagID < diag::DIAG_UPPER_LIMIT &&
- getBuiltinDiagClass(DiagID) == CLASS_EXTENSION;
+bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID,
+ bool &EnabledByDefault) {
+ if (DiagID >= diag::DIAG_UPPER_LIMIT ||
+ getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
+ return false;
+
+ EnabledByDefault = StaticDiagInfo[DiagID].Mapping != diag::MAP_IGNORE;
+ return true;
}
@@ -529,8 +539,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.
@@ -551,11 +567,20 @@ bool Diagnostic::ProcessDiag() {
if (DiagLevel >= Diagnostic::Error) {
ErrorOccurred = true;
++NumErrors;
+
+ // If we've emitted a lot of errors, emit a fatal error after it to stop a
+ // flood of bogus errors.
+ if (ErrorLimit && NumErrors >= ErrorLimit &&
+ DiagLevel == Diagnostic::Error)
+ SetDelayedDiagnostic(diag::fatal_too_many_errors);
}
// Finally, report it.
Client->HandleDiagnostic(DiagLevel, Info);
- if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics;
+ if (Client->IncludeInDiagnosticCounts()) {
+ if (DiagLevel == Diagnostic::Warning)
+ ++NumWarnings;
+ }
CurDiagID = ~0U;
@@ -1026,8 +1051,15 @@ static void WriteSourceLocation(llvm::raw_ostream &OS,
Location = SM->getInstantiationLoc(Location);
std::pair<FileID, unsigned> Decomposed = SM->getDecomposedLoc(Location);
-
- WriteString(OS, SM->getFileEntryForID(Decomposed.first)->getName());
+
+ const FileEntry *FE = SM->getFileEntryForID(Decomposed.first);
+ if (FE)
+ WriteString(OS, FE->getName());
+ else {
+ // Fallback to using the buffer name when there is no entry.
+ WriteString(OS, SM->getBuffer(Decomposed.first)->getBufferIdentifier());
+ }
+
WriteUnsigned(OS, SM->getLineNumber(Decomposed.first, Decomposed.second));
WriteUnsigned(OS, SM->getColumnNumber(Decomposed.first, Decomposed.second));
}
OpenPOWER on IntegriCloud