gcc/gcc/diagnostics
David Malcolm c89bd48e7e diagnostics: generalize state graph code to use json::property instances (v2)
In r16-1631-g2334d30cd8feac I added support for capturing state
information from -fanalyzer in the form of embedded XML strings
in SARIF output.

In r16-2211-ga5d9debedd2f46 I rewrote this so the state was captured in
the form of a SARIF directed graph, using various custom types.

I want to add the ability to capture other kinds of graph in our SARIF
output (e.g. inheritance hierarchies, CFGs, etc), so  the following patch
reworks the state graph handling code to minimize the use of custom types.
Instead, the patch introduces various json::property types, and
describes the state graph serialization in terms of instances of these
properties, rather than hardcoding string attribute names in readers and
writers.  The custom SARIF properties live in a new
"gcc/custom-sarif-properties/" directory.

The "experimental-html" scheme keys "show-state-diagrams-dot-src" and
"show-state-diagrams-sarif" become "show-graph-dot-src" and
"show-graph-dot-src" in preparation for new kinds of graph in the output.

This is an updated version of the patch, tested to build with GCC 5
(which the previous version didn't leading to PR bootstrap/122151)

contrib/ChangeLog:
	* gcc.doxy (INPUT): Add gcc/custom-sarif-properties

gcc/ChangeLog:
	* Makefile.in (OBJS-libcommon): Add
	custom-sarif-properties/digraphs.o and
	custom-sarif-properties/state-graphs.o.  Remove
	diagnostics/state-graphs.o.
	* configure: Regenerate.
	* configure.ac: Add custom-sarif-properties to subdir iteration.
	* custom-sarif-properties/digraphs.cc: New file.
	* custom-sarif-properties/digraphs.h: New file.
	* custom-sarif-properties/state-graphs.cc: New file.
	* custom-sarif-properties/state-graphs.h: New file.
	* diagnostics/diagnostics-selftests.cc
	(run_diagnostics_selftests): Drop call of state_graphs_cc_tests.
	* diagnostics/diagnostics-selftests.h (state_graphs_cc_tests):
	Delete decl.
	* diagnostics/digraphs.cc: Include
	"custom-sarif-properties/digraphs.h".  Move include of
	"selftest.h" to within CHECKING_P section.
	(using digraph_object): New.
	(namespace properties): New.
	(diagnostics::digraphs::object::get_attr): Delete.
	(diagnostics::digraphs::object::set_attr): Delete.
	(diagnostics::digraphs::object::set_json_attr): Delete.
	(digraph_object::get_property): New definitions, for various
	property types.
	(digraph_object::set_property): Likewise.
	(digraph_object::maybe_get_property): New.
	(digraph_object::get_property_as_tristate): New.
	(digraph_object::ensure_property_bag): New.
	(digraph::get_graph_kind): New.
	(digraph::set_graph_kind): New.
	Add include of "custom-sarif-properties/state-graphs.h".
	(selftest::test_simple_graph): Rewrite to use json::property
	instances rather than string attribute names.
	(selftest::test_property_objects): New test.
	(selftest::digraphs_cc_tests): Call it.
	* diagnostics/digraphs.h: Include "tristate.h".
	(object::get_attr): Delete.
	(object::set_attr): Delete.
	(object::get_property): New decls.
	(object::set_property): New decls.
	(object::maybe_get_property): New.
	(object::get_property_as_tristate): New.
	(object::set_json_attr): Delete.
	(object::ensure_property_bag): New.
	(graph::get_graph_kind): New.
	(graph::set_graph_kind): New.
	* diagnostics/html-sink.cc
	(html_generation_options::html_generation_options): Update for
	field renamings.
	(html_generation_options::dump): Likewise.
	(html_builder::maybe_make_state_diagram): Likewise.
	(html_builder::add_graph): Show SARIF and .dot src inline, if
	requested.
	* diagnostics/html-sink.h
	(html_generation_options::m_show_state_diagrams_sarif): Rename
	to...
	(html_generation_options::m_show_graph_sarif): ...this.
	(html_generation_options::m_show_state_diagrams_dot_src): Rename
	to...
	(html_generation_options::m_show_graph_dot_src0): ...this.
	* diagnostics/output-spec.cc
	(html_scheme_handler::maybe_handle_kv): Rename keys.
	(html_scheme_handler::get_keys): Likewise.
	* diagnostics/state-graphs-to-dot.cc: : Reimplement throughout to
	use json::property instances found within custom_sarif_properties
	throughout, rather than types in diagnostics::state_graphs.
	* diagnostics/state-graphs.cc: Deleted file.
	* diagnostics/state-graphs.h: Delete almost all, except decl of
	diagnostics::state_graphs::make_dot_graph.
	* doc/invoke.texi: Update for changes to "experimental-html" sink
	keys.
	* json.cc (json::object::set_string): New.
	(json::object::set_integer): New.
	(json::object::set_bool): New.
	(json::object::set_array_of_string): New.
	* json.h: Include "label-text.h".
	(struct json::property): New template.
	(json::string_property): New.
	(json::integer_property): New.
	(json::bool_property): New.
	(json::json_property): New.
	(using json::array_of_string_property): New.
	(struct json::enum_traits): New.
	(enum_json::property): New.
	(json::value::dyn_cast_array): New vfunc.
	(json::value::dyn_cast_integer_number): New vfunc.
	(json::value::set_string): New.
	(json::value::set_integer): New.
	(json::value::set_bool): New.
	(json::value::set_array_of_string): New.
	(json::value::maybe_get_enum): New.
	(json::value::set_enum): New.
	(json::array::dyn_cast_array): New.
	(json::integer_number::dyn_cast_integer_number): New.
	(object::maybe_get_enum): New.
	(object::set_enum): New.

gcc/analyzer/ChangeLog:
	* ana-state-to-diagnostic-state.cc: Reimplement throughout to use
	json::property instances found within custom_sarif_properties
	throughout, rather than types in diagnostics::state_graphs.
	* ana-state-to-diagnostic-state.h: Likewise.
	* checker-event.cc: Likewise.
	* sm-malloc.cc: Likewise.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic_plugin_test_graphs.cc
	(report_diag_with_graphs): Port from set_attr to set_property.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-10-16 17:39:03 -04:00
..
buffering.cc diagnostics: add class sink::extension 2025-10-09 11:38:50 -04:00
buffering.h diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
changes.cc restore bootstrap with --enable-checking=release [PR121260] 2025-07-28 10:55:31 -04:00
changes.h diagnostics: move diagnostics::edit_context -> diagnostics::changes::change_set 2025-07-25 15:13:41 -04:00
client-data-hooks.h diagnostics: add dump methods to client_data_hooks and logical_location_manager 2025-09-18 16:07:09 -04:00
color.cc diagnostics: reorganize selftests 2025-07-25 15:13:41 -04:00
color.h diagnostics: move gcc/diagnostic-color.{h,cc} to gcc/diagnostics/color.{h,cc} 2025-07-25 15:13:40 -04:00
column-options.h diagnostics: introduce struct column_options 2025-08-08 16:55:43 -04:00
context-options.h diagnostics: introduce context-options.h 2025-07-25 15:13:44 -04:00
context.cc diagnostics: add class sink::extension 2025-10-09 11:38:50 -04:00
context.h diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
counters.h diagnostics: move diagnostics::counters to its own header 2025-08-04 10:45:30 -04:00
diagnostic-info.h diagnostics: convert diagnostic_t to enum class diagnostics::kind 2025-07-25 15:13:43 -04:00
diagnostics-selftests.cc diagnostics: generalize state graph code to use json::property instances (v2) 2025-10-16 17:39:03 -04:00
diagnostics-selftests.h diagnostics: generalize state graph code to use json::property instances (v2) 2025-10-16 17:39:03 -04:00
diagram.h diagnostics: move diagnostic_diagram to diagnostics::diagram 2025-07-25 15:13:35 -04:00
digraphs.cc diagnostics: generalize state graph code to use json::property instances (v2) 2025-10-16 17:39:03 -04:00
digraphs.h diagnostics: generalize state graph code to use json::property instances (v2) 2025-10-16 17:39:03 -04:00
dumping.cc diagnostics: fix build on hosts where unsigned == size_t 2025-08-09 09:15:04 -04:00
dumping.h diagnostics: fix build on hosts where unsigned == size_t 2025-08-09 09:15:04 -04:00
event-id.h diagnostics: introduce namespace diagnostics::paths 2025-07-25 15:13:36 -04:00
file-cache.cc diagnostics: fix build on hosts where unsigned == size_t 2025-08-09 09:15:04 -04:00
file-cache.h diagnostics: move file_cache from input.{cc,h} to diagnostics/file-cache.{cc,h} 2025-07-25 15:13:44 -04:00
html-sink.cc diagnostics: generalize state graph code to use json::property instances (v2) 2025-10-16 17:39:03 -04:00
html-sink.h diagnostics: generalize state graph code to use json::property instances (v2) 2025-10-16 17:39:03 -04:00
kinds.def diagnostics: convert diagnostic_t to enum class diagnostics::kind 2025-07-25 15:13:43 -04:00
kinds.h diagnostics: add GCC_DIAGNOSTICS_LOG 2025-08-29 14:39:37 -04:00
lazy-paths.cc diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
lazy-paths.h diagnostics: introduce namespace diagnostics::paths 2025-07-25 15:13:36 -04:00
logging.cc diagnostics: add GCC_DIAGNOSTICS_LOG 2025-08-29 14:39:37 -04:00
logging.h diagnostics: Fix bootstrap fail on Darwin 32b hosts. 2025-09-01 19:17:13 +01:00
logical-locations.h diagnostics: add dump methods to client_data_hooks and logical_location_manager 2025-09-18 16:07:09 -04:00
macro-unwinding.cc diagnostics: add class sink::extension 2025-10-09 11:38:50 -04:00
macro-unwinding.h diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
metadata.h diagnostics: minor cleanups 2025-08-08 16:55:45 -04:00
option-classifier.cc diagnostics: convert diagnostic_t to enum class diagnostics::kind: restore build with GCC 5 2025-07-26 16:02:20 +02:00
option-classifier.h diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
option-id-manager.h diagnostics: rename option_manager to option_id_manager and split out from context.h 2025-08-04 10:45:30 -04:00
option-id.h diagnostics: rename diagnostic_option_id to diagnostics::option_id and move to its own header 2025-07-25 15:13:42 -04:00
output-file.h diagnostics: add GCC_DIAGNOSTICS_LOG 2025-08-29 14:39:37 -04:00
output-spec.cc diagnostics: generalize state graph code to use json::property instances (v2) 2025-10-16 17:39:03 -04:00
output-spec.h diagnostics::output_spec: support client-specific keys 2025-10-02 10:44:54 -04:00
paths-output.cc diagnostics/libcpp: convert enum location_aspect to enum class 2025-09-18 16:07:04 -04:00
paths.cc diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
paths.h diagnostics: move/rename output formats to diagnostics as "sinks" 2025-07-25 15:13:37 -04:00
sarif-sink.cc sarif output: add descriptions to fix-it hints (§3.55.2) [PR121986] 2025-09-23 16:45:12 -04:00
sarif-sink.h diagnostics: revamp of dumping of "diagnostics" internal state 2025-08-08 16:55:45 -04:00
selftest-context.cc diagnostics: add class sink::extension 2025-10-09 11:38:50 -04:00
selftest-context.h diagnostics: make context::m_source_printing private 2025-07-25 15:13:45 -04:00
selftest-logical-locations.cc diagnostics: add dump methods to client_data_hooks and logical_location_manager 2025-09-18 16:07:09 -04:00
selftest-logical-locations.h diagnostics: add dump methods to client_data_hooks and logical_location_manager 2025-09-18 16:07:09 -04:00
selftest-paths.cc diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
selftest-paths.h diagnostics: reorganize selftests 2025-07-25 15:13:41 -04:00
selftest-source-printing.h diagnostics: move file_cache from input.{cc,h} to diagnostics/file-cache.{cc,h} 2025-07-25 15:13:44 -04:00
sink.h diagnostics: add class sink::extension 2025-10-09 11:38:50 -04:00
source-printing-effects.h diagnostics: introduce diagnostics/source-printing.cc 2025-07-25 15:13:37 -04:00
source-printing-options.h diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
source-printing.cc diagnostics/libcpp: convert enum location_aspect to enum class 2025-09-18 16:07:04 -04:00
state-graphs-to-dot.cc diagnostics: generalize state graph code to use json::property instances (v2) 2025-10-16 17:39:03 -04:00
state-graphs.h diagnostics: generalize state graph code to use json::property instances (v2) 2025-10-16 17:39:03 -04:00
text-sink.cc diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
text-sink.h diagnostics: enable nested diagnostics by default [PR116253] 2025-08-08 16:55:46 -04:00
url.h diagnostics: gcc/diagnostic-url.h -> gcc/diagnostics/url.h 2025-07-25 15:13:40 -04:00