summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-03-27 01:50:55 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-03-27 01:50:55 +0000
commitb6766f07c87ba14aa647a6193c549f6a3f059ce5 (patch)
tree95dd8019f47ea34cf32e8e67006141b8942e534b /clang/lib
parentaf66980d8ab79ead2f740aba9a93ec41b2f372d1 (diff)
downloadbcm5719-llvm-b6766f07c87ba14aa647a6193c549f6a3f059ce5.tar.gz
bcm5719-llvm-b6766f07c87ba14aa647a6193c549f6a3f059ce5.zip
Add an option to suppress include stack printing on note diagnostics.
These stacks are often less important than those on primary diagnostics. As the number of notes grows, this becomes increasingly important. The include stack printing is clever and doesn't print stacks for adjacent diagnostics from the same file, but when a note is in between a sequence of errors in a header file, and the notes all refer to some other file, we end up getting a worst-case ping-pong of include stacks that take up a great deal of vertical space. Still, for now, the default behavior isn't changed. We can evaluate user feedback with the flag. Patch by Richard Trieu, a couple of style tweaks from me. llvm-svn: 128371
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Driver/Tools.cpp10
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp7
-rw-r--r--clang/lib/Frontend/TextDiagnosticPrinter.cpp25
3 files changed, 32 insertions, 10 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 81585c85674..721117071ba 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -1732,6 +1732,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(A->getValue(Args));
}
+ if (Arg *A = Args.getLastArg(
+ options::OPT_fdiagnostics_show_note_include_stack,
+ options::OPT_fno_diagnostics_show_note_include_stack)) {
+ if (A->getOption().matches(
+ options::OPT_fdiagnostics_show_note_include_stack))
+ CmdArgs.push_back("-fdiagnostics-show-note-include-stack");
+ else
+ CmdArgs.push_back("-fno-diagnostics-show-note-include-stack");
+ }
+
// Color diagnostics are the default, unless the terminal doesn't support
// them.
if (Args.hasFlag(options::OPT_fcolor_diagnostics,
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 980c75200e7..431f5f4d2f4 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -989,6 +989,13 @@ static void ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location);
Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option);
+ // Default behavior is to show note include stacks.
+ Opts.ShowNoteIncludeStack = true;
+ if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack,
+ OPT_fno_diagnostics_show_note_include_stack))
+ if (A->getOption().matches(OPT_fno_diagnostics_show_note_include_stack))
+ Opts.ShowNoteIncludeStack = false;
+
llvm::StringRef ShowOverloads =
Args.getLastArgValue(OPT_fshow_overloads_EQ, "all");
if (ShowOverloads == "best")
diff --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
index 084915311dc..867d919fb30 100644
--- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -53,8 +53,11 @@ TextDiagnosticPrinter::~TextDiagnosticPrinter() {
delete &OS;
}
-void TextDiagnosticPrinter::
-PrintIncludeStack(SourceLocation Loc, const SourceManager &SM) {
+void TextDiagnosticPrinter::PrintIncludeStack(Diagnostic::Level Level,
+ SourceLocation Loc,
+ const SourceManager &SM) {
+ if (!DiagOpts->ShowNoteIncludeStack && Level == Diagnostic::Note) return;
+
if (Loc.isInvalid()) return;
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
@@ -62,7 +65,7 @@ PrintIncludeStack(SourceLocation Loc, const SourceManager &SM) {
return;
// Print out the other include frames first.
- PrintIncludeStack(PLoc.getIncludeLoc(), SM);
+ PrintIncludeStack(Level, PLoc.getIncludeLoc(), SM);
if (DiagOpts->ShowLocation)
OS << "In file included from " << PLoc.getFilename()
@@ -289,7 +292,8 @@ static void SelectInterestingSourceRegion(std::string &SourceLine,
}
}
-void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
+void TextDiagnosticPrinter::EmitCaretDiagnostic(Diagnostic::Level Level,
+ SourceLocation Loc,
CharSourceRange *Ranges,
unsigned NumRanges,
const SourceManager &SM,
@@ -313,7 +317,7 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
SourceLocation OneLevelUp = SM.getImmediateInstantiationRange(Loc).first;
// FIXME: Map ranges?
- EmitCaretDiagnostic(OneLevelUp, Ranges, NumRanges, SM, 0, 0, Columns,
+ EmitCaretDiagnostic(Level, OneLevelUp, Ranges, NumRanges, SM, 0, 0, Columns,
OnMacroInst + 1, MacroSkipStart, MacroSkipEnd);
// Map the location.
@@ -339,7 +343,7 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
// "included from" lines.
if (LastWarningLoc != PLoc.getIncludeLoc()) {
LastWarningLoc = PLoc.getIncludeLoc();
- PrintIncludeStack(LastWarningLoc, SM);
+ PrintIncludeStack(Level, LastWarningLoc, SM);
}
if (DiagOpts->ShowLocation) {
@@ -351,8 +355,9 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc,
}
OS << "note: instantiated from:\n";
- EmitCaretDiagnostic(Loc, Ranges, NumRanges, SM, Hints, NumHints, Columns,
- OnMacroInst + 1, MacroSkipStart, MacroSkipEnd);
+ EmitCaretDiagnostic(Level, Loc, Ranges, NumRanges, SM, Hints, NumHints,
+ Columns, OnMacroInst + 1, MacroSkipStart,
+ MacroSkipEnd);
return;
}
@@ -805,7 +810,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
// "included from" lines.
if (LastWarningLoc != PLoc.getIncludeLoc()) {
LastWarningLoc = PLoc.getIncludeLoc();
- PrintIncludeStack(LastWarningLoc, SM);
+ PrintIncludeStack(Level, LastWarningLoc, SM);
StartOfLocationInfo = OS.tell();
}
@@ -1034,7 +1039,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
}
}
- EmitCaretDiagnostic(LastLoc, Ranges, NumRanges, LastLoc.getManager(),
+ EmitCaretDiagnostic(Level, LastLoc, Ranges, NumRanges, LastLoc.getManager(),
Info.getFixItHints(),
Info.getNumFixItHints(),
DiagOpts->MessageLength,
OpenPOWER on IntegriCloud