diff options
author | David Malcolm <dmalcolm@redhat.com> | 2022-06-23 14:59:24 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2022-06-23 14:59:24 -0400 |
commit | 0b14f590e3e9d95b8211b77d992589d5ab4c25f0 (patch) | |
tree | 39ac2b3f184303c93ca038cf58bb5fd36f231157 /gcc/diagnostic-format-sarif.cc | |
parent | 7c1c7e120cca183671b11ba68a6350c8800823c0 (diff) | |
download | gcc-0b14f590e3e9d95b8211b77d992589d5ab4c25f0.tar.gz |
diagnostics: add ability to associate diagnostics with rules from coding standards
gcc/ChangeLog:
* common.opt (fdiagnostics-show-rules): New option.
* diagnostic-format-json.cc (diagnostic_output_format_init_json):
Fix up context->show_rules.
* diagnostic-format-sarif.cc
(diagnostic_output_format_init_sarif): Likewise.
* diagnostic-metadata.h (diagnostic_metadata::rule): New class.
(diagnostic_metadata::precanned_rule): New class.
(diagnostic_metadata::add_rule): New.
(diagnostic_metadata::get_num_rules): New.
(diagnostic_metadata::get_rule): New.
(diagnostic_metadata::m_rules): New field.
* diagnostic.cc (diagnostic_initialize): Initialize show_rules.
(print_any_rules): New.
(diagnostic_report_diagnostic): Call it.
* diagnostic.h (diagnostic_context::show_rules): New field.
* doc/invoke.texi (-fno-diagnostics-show-rules): New option.
* opts.cc (common_handle_option): Handle
OPT_fdiagnostics_show_rules.
* toplev.cc (general_init): Set up global_dc->show_rules.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-metadata.c: Expect " [STR34-C]" to
be emitted at the "gets" call.
* gcc.dg/plugin/diagnostic_plugin_test_metadata.c
(pass_test_metadata::execute): Associate the "gets" diagnostic
with a rule named "STR34-C".
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/diagnostic-format-sarif.cc')
-rw-r--r-- | gcc/diagnostic-format-sarif.cc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 0c33179e8cf..a7bb9fb639d 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -1556,6 +1556,7 @@ diagnostic_output_format_init_sarif (diagnostic_context *context) /* The metadata is handled in SARIF format, rather than as text. */ context->show_cwe = false; + context->show_rules = false; /* The option is handled in SARIF format, rather than as text. */ context->show_option_requested = false; |