[committed] analyzer: don't print the duplicate count by default

Message ID 20200302214951.9624-1-dmalcolm@redhat.com
State New
Headers show
  • [committed] analyzer: don't print the duplicate count by default
Related show

Commit Message

David Malcolm March 2, 2020, 9:49 p.m.
The note about duplicates attached to analyzer diagnostics feels like an
implementation detail; it's likely just noise from the perspective of an

This patch disables it by default, introducing a flag to re-enable it.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to master as 13b7691238f189c7a233aedec49306a7cb2b0a15.

	* analyzer.opt (fanalyzer-show-duplicate-count): New option.
	* diagnostic-manager.cc
	(diagnostic_manager::emit_saved_diagnostic): Use the above to
	guard the printing of the duplicate count.

	* doc/invoke.texi (-fanalyzer-show-duplicate-count): New.

	* gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c: Add
 gcc/analyzer/analyzer.opt                                 | 4 ++++
 gcc/analyzer/diagnostic-manager.cc                        | 2 +-
 gcc/doc/invoke.texi                                       | 8 ++++++++
 .../gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c          | 2 ++
 4 files changed, 15 insertions(+), 1 deletion(-)



diff --git a/gcc/analyzer/analyzer.opt b/gcc/analyzer/analyzer.opt
index 4d122f3593a..22cf4b0ad3b 100644
--- a/gcc/analyzer/analyzer.opt
+++ b/gcc/analyzer/analyzer.opt
@@ -114,6 +114,10 @@  fanalyzer-fine-grained
 Common Var(flag_analyzer_fine_grained) Init(0)
 Avoid combining multiple statements into one exploded edge.
+Common Var(flag_analyzer_show_duplicate_count) Init(0)
+Issue a note when diagnostics are deduplicated.
 Common Var(flag_analyzer_state_purge) Init(1)
 Purge unneeded state during analysis.
diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc
index b8e59334374..7435092e2d7 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -541,7 +541,7 @@  diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg,
   auto_cfun sentinel (sd.m_snode->m_fun);
   if (sd.m_d->emit (&rich_loc))
-      if (num_dupes > 0)
+      if (flag_analyzer_show_duplicate_count && num_dupes > 0)
 	inform_n (stmt->location, num_dupes,
 		  "%i duplicate", "%i duplicates",
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index dc7440db103..54375ebd679 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -8477,6 +8477,14 @@  By default, an edge in this graph can contain the effects of a run
 of multiple statements within a basic block.  With
 @option{-fanalyzer-fine-grained}, each statement gets its own edge.
+@item -fanalyzer-show-duplicate-count
+@opindex fanalyzer-show-duplicate-count
+@opindex fno-analyzer-show-duplicate-count
+This option is intended for analyzer developers: if multiple diagnostics
+have been detected as being duplicates of each other, it emits a note when
+reporting the best diagnostic, giving the number of additional diagnostics
+that were suppressed by the deduplication logic.
 @item -fno-analyzer-state-merge
 @opindex fanalyzer-state-merge
 @opindex fno-analyzer-state-merge
diff --git a/gcc/testsuite/gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c b/gcc/testsuite/gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c
index 53c046ed12f..b43148cb4a7 100644
--- a/gcc/testsuite/gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c
+++ b/gcc/testsuite/gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c
@@ -1,3 +1,5 @@ 
+/* { dg-additional-options "-fanalyzer-show-duplicate-count" } */
 #include <stdlib.h>
 typedef struct _krb5_data {