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
changes.h
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
color.h
column-options.h
context-options.h
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
diagnostic-info.h
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
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
dumping.h
event-id.h
file-cache.cc
file-cache.h
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
kinds.h
lazy-paths.cc diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
lazy-paths.h
logging.cc
logging.h
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
option-classifier.cc
option-classifier.h diagnostics: use diagnostic.h in fewer places 2025-09-18 16:06:39 -04:00
option-id-manager.h
option-id.h
output-file.h
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
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
selftest-context.cc diagnostics: add class sink::extension 2025-10-09 11:38:50 -04:00
selftest-context.h
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
selftest-source-printing.h
sink.h diagnostics: add class sink::extension 2025-10-09 11:38:50 -04:00
source-printing-effects.h
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
url.h