]> granicus.if.org Git - clang/commitdiff
Add an option to suppress include stack printing on note diagnostics.
authorChandler Carruth <chandlerc@gmail.com>
Sun, 27 Mar 2011 01:50:55 +0000 (01:50 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 27 Mar 2011 01:50:55 +0000 (01:50 +0000)
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.

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

include/clang/Driver/CC1Options.td
include/clang/Driver/Options.td
include/clang/Frontend/DiagnosticOptions.h
include/clang/Frontend/TextDiagnosticPrinter.h
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Frontend/TextDiagnosticPrinter.cpp

index b29d73fd026d172df84705fbcac9ed4050185234..6e1c61c99f5ee319e897c77799013c73bf31cfcc 100644 (file)
@@ -210,6 +210,9 @@ def fno_caret_diagnostics : Flag<"-fno-caret-diagnostics">,
   HelpText<"Do not include source line and caret with diagnostics">;
 def fno_diagnostics_fixit_info : Flag<"-fno-diagnostics-fixit-info">,
   HelpText<"Do not include fixit information in diagnostics">;
+def fno_diagnostics_show_note_include_stack :
+  Flag<"-fno-diagnostics-show-note-include-stack">,
+  HelpText<"Display include stacks for diagnostic notes">;
 def w : Flag<"-w">, HelpText<"Suppress all warnings">;
 def pedantic : Flag<"-pedantic">;
 def pedantic_errors : Flag<"-pedantic-errors">;
@@ -227,7 +230,9 @@ def fdiagnostics_show_option : Flag<"-fdiagnostics-show-option">,
   HelpText<"Print diagnostic name with mappable diagnostics">;
 def fdiagnostics_show_category : Separate<"-fdiagnostics-show-category">,
   HelpText<"Print diagnostic category">;
-
+def fdiagnostics_show_note_include_stack :
+  Flag<"-fdiagnostics-show-note-include-stack">,
+  HelpText<"Display include stacks for diagnostic notes">;
 def ftabstop : Separate<"-ftabstop">, MetaVarName<"<N>">,
   HelpText<"Set the tab stop distance.">;
 def ferror_limit : Separate<"-ferror-limit">, MetaVarName<"<N>">,
index 6cd5645cdff1ff1b7be2693bfd7be687197215c2..b831c9193f7b0c050a550f4f4e8b0e0a1ce530fc 100644 (file)
@@ -271,6 +271,7 @@ def fdiagnostics_fixit_info : Flag<"-fdiagnostics-fixit-info">, Group<f_Group>;
 def fdiagnostics_print_source_range_info : Flag<"-fdiagnostics-print-source-range-info">, Group<f_Group>;
 def fdiagnostics_parseable_fixits : Flag<"-fdiagnostics-parseable-fixits">, Group<f_Group>;
 def fdiagnostics_show_option : Flag<"-fdiagnostics-show-option">, Group<f_Group>;
+def fdiagnostics_show_note_include_stack : Flag<"-fdiagnostics-show-note-include-stack">, Group<f_Group>;
 def fdiagnostics_show_category_EQ : Joined<"-fdiagnostics-show-category=">, Group<f_Group>;
 def fdollars_in_identifiers : Flag<"-fdollars-in-identifiers">, Group<f_Group>;
 def felide_constructors : Flag<"-felide-constructors">, Group<f_Group>;
@@ -329,6 +330,7 @@ def fno_constant_cfstrings : Flag<"-fno-constant-cfstrings">, Group<f_Group>;
 def fno_cxx_exceptions: Flag<"-fno-cxx-exceptions">, Group<f_Group>;
 def fno_diagnostics_fixit_info : Flag<"-fno-diagnostics-fixit-info">, Group<f_Group>;
 def fno_diagnostics_show_option : Flag<"-fno-diagnostics-show-option">, Group<f_Group>;
+def fno_diagnostics_show_note_include_stack : Flag<"-fno-diagnostics-show-note-include-stack">, Group<f_Group>;
 def fno_dollars_in_identifiers : Flag<"-fno-dollars-in-identifiers">, Group<f_Group>;
 def fno_elide_constructors : Flag<"-fno-elide-constructors">, Group<f_Group>;
 def fno_eliminate_unused_debug_symbols : Flag<"-fno-eliminate-unused-debug-symbols">, Group<f_Group>;
index f7f498bff0240b0d47a170742813b91383ec0c6a..4e46b4fbf021aae1af3af1b71343054c8a1ff936 100644 (file)
@@ -33,6 +33,7 @@ public:
   unsigned ShowParseableFixits : 1; /// Show machine parseable fix-its.
   unsigned ShowOptionNames : 1;  /// Show the diagnostic name for mappable
                                  /// diagnostics.
+  unsigned ShowNoteIncludeStack : 1; /// Show include stacks for notes.
   unsigned ShowCategories : 2;   /// Show categories: 0 -> none, 1 -> Number,
                                  /// 2 -> Full Name.
   unsigned ShowColors : 1;       /// Show diagnostics with ANSI color sequences.
index f5302947a5935ca3dbd01a6bb9853c32d274ca9b..d7d2692cb547e0505c4e21cf66def0203906d6d9 100644 (file)
@@ -53,7 +53,8 @@ public:
     LangOpts = 0;
   }
 
-  void PrintIncludeStack(SourceLocation Loc, const SourceManager &SM);
+  void PrintIncludeStack(Diagnostic::Level Level, SourceLocation Loc,
+                         const SourceManager &SM);
 
   void HighlightRange(const CharSourceRange &R,
                       const SourceManager &SrcMgr,
@@ -61,7 +62,7 @@ public:
                       std::string &CaretLine,
                       const std::string &SourceLine);
 
-  void EmitCaretDiagnostic(SourceLocation Loc,
+  void EmitCaretDiagnostic(Diagnostic::Level Level, SourceLocation Loc,
                            CharSourceRange *Ranges, unsigned NumRanges,
                            const SourceManager &SM,
                            const FixItHint *Hints,
@@ -71,7 +72,7 @@ public:
                            unsigned MacroSkipStart,
                            unsigned MacroSkipEnd);
 
-  virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
+  virtual void HandleDiagnostic(Diagnostic::Level Level,
                                 const DiagnosticInfo &Info);
 };
 
index 81585c85674daf1f70780bf496b1d0e50acde99a..721117071ba383617101677c230e3f04340cac09 100644 (file)
@@ -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,
index 980c75200e7ee3228524a532021556fc0fccd13a..431f5f4d2f4b656d0c34ce2b59fe75aaa38d3ae9 100644 (file)
@@ -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")
index 084915311dcc1875c6fbc2cc57b222b1d921c5aa..867d919fb30bdc3c42a6c982e4c324559da36185 100644 (file)
@@ -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,