From 13b7691238f189c7a233aedec49306a7cb2b0a15 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 28 Feb 2020 10:06:57 -0500 Subject: [PATCH] analyzer: don't print the duplicate count by default The note about duplicates attached to analyzer diagnostics feels like an implementation detail; it's likely just noise from the perspective of an end-user. This patch disables it by default, introducing a flag to re-enable it. gcc/analyzer/ChangeLog: * 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. gcc/ChangeLog: * doc/invoke.texi (-fanalyzer-show-duplicate-count): New. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c: Add -fanalyzer-show-duplicate-count. --- gcc/ChangeLog | 4 ++++ gcc/analyzer/ChangeLog | 7 +++++++ gcc/analyzer/analyzer.opt | 4 ++++ gcc/analyzer/diagnostic-manager.cc | 2 +- gcc/doc/invoke.texi | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ .../gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c | 2 ++ 7 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2944f8f4c50..d8ac9f8c577 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2020-03-02 David Malcolm + + * doc/invoke.texi (-fanalyzer-show-duplicate-count): New. + 2020-03-02 David Malcolm * doc/invoke.texi (Static Analyzer Options): Add diff --git a/gcc/analyzer/ChangeLog b/gcc/analyzer/ChangeLog index e5d7bdbbf7e..fa0fbcd1959 100644 --- a/gcc/analyzer/ChangeLog +++ b/gcc/analyzer/ChangeLog @@ -1,3 +1,10 @@ +2020-03-02 David Malcolm + + * 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. + 2020-03-02 David Malcolm PR analyzer/93959 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. +fanalyzer-show-duplicate-count +Common Var(flag_analyzer_show_duplicate_count) Init(0) +Issue a note when diagnostics are deduplicated. + fanalyzer-state-purge 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", num_dupes); 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/ChangeLog b/gcc/testsuite/ChangeLog index 33fa9bc972b..5eae7d8173c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-02 David Malcolm + + * gcc.dg/analyzer/CVE-2005-1689-dedupe-issue.c: Add + -fanalyzer-show-duplicate-count. + 2020-03-02 David Malcolm PR analyzer/93959 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 typedef struct _krb5_data { -- 2.30.2