Age | Commit message (Collapse) | Author | Files | Lines |
|
In r16-1631-g2334d30cd8feac I added support for capturing state
information from -fanalyzer in XML form, and adding a way to visualize
these states in HTML output. The data was optionally captured in SARIF
output (with "xml-state=yes"), stashing the XML in string form in
a property bag.
This worked, but there was no way to round-trip the stored data back
from SARIF without adding an XML parser to GCC, which I don't want to
do.
SARIF supports capturing directed graphs, so this patch:
(a) adds a new namespace diagnostics::digraphs, with classes digraph,
node, and edge, representing directed graphs in a form similar to
what SARIF can serialize
(b) adds support to GCC's diagnostic subsystem for reporting graphs,
either "globally" or as part of a diagnostic. An example in a testsuite
plugin emits an error that has a couple of dummy graphs associated with
it, and captures the optimization passes as a digraph "globally".
Graphs are ignored by text sinks, but are captured by sarif sinks,
and the "experimental-html" sink gains SVG-based rendering of any graphs
using dot. This HTML output is rather crude; an example can be seen
here:
https://dmalcolm.fedorapeople.org/gcc/2025-07-10/diagnostic-test-graphs-html.c.html
(c) adds support to libgdiagnostics for the above
(d) adds support to sarif-replay for the above (round-tripping any
graph information)
(e) replaces the XML representation of state with a representation
based on the above directed graphs, using property bags to stash
additional information (e.g. "this is an on-stack buffer")
(f) implements round-tripping of this information in sarif-replay
To summarize:
- previously we could generate HTML diagrams for debugging
-fanalyzer directly from gcc, but not from stored .sarif output.
- with this patch, we can generate such HTML diagrams both directly
*and* from stored .sarif output (provided the SARIF sink was created
with "state-graphs=yes")
Examples of HTML output can be seen here:
https://dmalcolm.fedorapeople.org/gcc/2025-07-10/
where as before j/k can be used to cycle through the events.
which is almost identical to the output from the old XML-based
implementation seen at:
https://dmalcolm.fedorapeople.org/gcc/2025-06-23/
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add diagnostic-digraphs.o and
diagnostic-state-graphs.o.
gcc/ChangeLog:
* diagnostic-format-html.cc: Include "diagnostic-format-sarif.h",
Replace include of "diagnostic-state.h" with includes of
"diagnostic-digraphs.h" and "diagnostic-state-graphs.h".
(html_generation_options::html_generation_options): Update for
field renaming.
(html_builder::m_body_element): New field.
(html_builder::html_builder): Initialize m_body_element.
(html_builder::maybe_make_state_diagram): Port from XML
implementation to state graph implementation.
(html_builder::make_element_for_diagnostic): Add any
per-diagnostic graphs.
(html_builder::add_graph): New.
(html_builder::emit_global_graph): New.
(html_output_format::report_global_digraph): New.
* diagnostic-format-html.h
(html_generation_options::m_show_state_diagram_xml): Replace
with...
(html_generation_options::m_show_state_diagrams_sarif): ...this.
(html_generation_options::m_show_state_diagram_dot_src): Rename
to...
(html_generation_options::m_show_state_diagrams_dot_src): ...this.
* diagnostic-format-sarif.cc: Include "diagnostic-digraphs.h" and
"diagnostic-state-graphs.h".
(sarif_builder::m_run_graphs): New field.
(sarif_result::on_nested_diagnostic): Update call to
make_location_object to pass arg by pointer.
(sarif_builder::sarif_builder): Initialize m_run_graphs.
(sarif_builder::report_global_digraph): New.
(sarif_builder::make_result_object): Add any graphs to
the result object.
(sarif_builder::make_locations_arr): Update call to
make_location_object to pass arg by pointer.
(sarif_builder::make_location_object): Pass param "loc_mgr" by
pointer rather than by reference so that it can be null, and
handle this case.
(copy_any_property_bag): New.
(make_sarif_graph): New.
(make_sarif_node): New.
(make_sarif_edge): New.
(sarif_property_bag::set_graph): New.
(populate_thread_flow_location_object): Port from XML
implementation to state graph implementation.
(make_run_object): Store any graphs.
(sarif_output_format::report_global_digraph): New.
(sarif_generation_options::sarif_generation_options): Rename
m_xml_state to m_state_graph.
(selftest::test_make_location_object): Update for change to
make_location_object.
* diagnostic-format-sarif.h:
(sarif_generation_options::m_xml_state): Replace with...
(sarif_generation_options::m_state_graph): ...this.
(class sarif_location_manager): Add forward decl.
(diagnostics::digraphs::digraph): New forward decl.
(diagnostics::digraphs::node): New forward decl.
(diagnostics::digraphs::edge): New forward decl.
(sarif_property_bag::set_graph): New decl.
(class sarif_graph): New.
(class sarif_node): New.
(class sarif_edge): New.
(make_sarif_graph): New decl.
(make_sarif_node): New decl.
(make_sarif_edge): New decl.
* diagnostic-format-text.h
(diagnostic_text_output_format::report_global_digraph): New.
* diagnostic-format.h
(diagnostic_output_format::report_global_digraph): New vfunc.
* diagnostic-digraphs.cc: New file.
* diagnostic-digraphs.h: New file.
* diagnostic-metadata.h (diagnostics::digraphs::lazy_digraphs):
New forward decl.
(diagnostic_metadata::diagnostic_metadata): Initialize
m_lazy_digraphs.
(diagnostic_metadata::set_lazy_digraphs): New.
(diagnostic_metadata::get_lazy_digraphs): New.
(diagnostic_metadata::m_lazy_digraphs): New field.
* diagnostic-output-spec.cc (sarif_scheme_handler::make_sink):
Update for XML to state graph changes.
(sarif_scheme_handler::make_sarif_gen_opts): Likewise.
(html_scheme_handler::make_sink): Rename "show-state-diagram-xml"
to "show-state-diagrams-sarif" and use pluralization consistently.
* diagnostic-path.cc: Replace include of "xml.h" with
"diagnostic-state-graphs.h".
(diagnostic_event::maybe_make_xml_state): Replace with...
(diagnostic_event::maybe_make_diagnostic_state_graph): ...this.
* diagnostic-path.h (diagnostics::digraphs::digraph): New forward
decl.
(diagnostic_event::maybe_make_xml_state): Replace with...
(diagnostic_event::maybe_make_diagnostic_state_graph): ...this.
* diagnostic-state-graphs.cc: New file.
* diagnostic-state-graphs.h: New file.
* diagnostic-state-to-dot.cc: Port implementation from XML to
state graphs.
* diagnostic-state.h: Deleted file.
* diagnostic.cc (diagnostic_context::report_global_digraph): New.
* diagnostic.h (diagnostics::digraphs::lazy_digraph): New forward
decl.
(diagnostic_context::report_global_digraph): New decl.
* doc/analyzer.texi (Debugging the Analyzer): Update to reflect
change from XML to state graphs.
* doc/invoke.texi ("sarif" diagnostics sink): Replace "xml-state"
with "state-graphs".
("experimental-html" diagnostics sink): Replace
"show-state-diagrams-xml" with "show-state-diagrams-sarif"
* doc/libgdiagnostics/topics/compatibility.rst
(LIBGDIAGNOSTICS_ABI_3): New.
* doc/libgdiagnostics/topics/graphs.rst: New file.
* doc/libgdiagnostics/topics/index.rst: Add graphs.rst.
* graphviz.h (node_id::operator=): New.
* json.h (json::value::dyn_cast_string): New.
(json::object::get_num_keys): New accessor.
(json::object::get_key): New accessor.
(json::string::dyn_cast_string): New.
* libgdiagnostics++.h (class libgdiagnostics::graph): New.
(class libgdiagnostics::node): New.
(class libgdiagnostics::edge): New.
(class libgdiagnostics::diagnostic::take_graph): New.
(class libgdiagnostics::manager::take_global_graph): New.
(class libgdiagnostics::graph::set_description): New.
(class libgdiagnostics::graph::get_node_by_id): New.
(class libgdiagnostics::graph::get_edge_by_id): New.
(class libgdiagnostics::graph::add_edge): New.
(class libgdiagnostics::node::set_label): New.
(class libgdiagnostics::node::set_location): New.
(class libgdiagnostics::node::set_logical_location): New.
* libgdiagnostics-private.h: New file.
* libgdiagnostics.cc: Define INCLUDE_STRING. Include
"diagnostic-digraphs.h", "diagnostic-state-graphs.h", and
"libgdiagnostics-private.h".
(struct diagnostic_graph): New.
(struct diagnostic_node): New.
(struct diagnostic_edge): New.
(libgdiagnostics_path_event::libgdiagnostics_path_event): Add
state_graph param.
(libgdiagnostics_path_event::maybe_make_diagnostic_state_graph):
New.
(libgdiagnostics_path_event::m_state_graph): New field.
(diagnostic_execution_path::add_event_va): Add state_graph param.
(class prebuilt_digraphs): New.
(diagnostic::diagnostic): Use m_graphs in m_metadata.
(diagnostic::take_graph): New.
(diagnostic::get_graphs): New accessor.
(diagnostic::m_graphs): New field.
(diagnostic_manager::take_global_graph): New.
(diagnostic_execution_path_add_event): Update for new param to
add_event_va.
(diagnostic_execution_path_add_event_va): Likewise.
(diagnostic_graph::add_node_with_id): New public entrypoint.
(diagnostic_graph::add_edge_with_label): New public entrypoint.
(diagnostic_manager_new_graph): New public entrypoint.
(diagnostic_manager_take_global_graph): New public entrypoint.
(diagnostic_take_graph): New public entrypoint.
(diagnostic_graph_release): New public entrypoint.
(diagnostic_graph_set_description): New public entrypoint.
(diagnostic_graph_add_node): New public entrypoint.
(diagnostic_graph_add_edge): New public entrypoint.
(diagnostic_graph_get_node_by_id): New public entrypoint.
(diagnostic_graph_get_edge_by_id): New public entrypoint.
(diagnostic_node_set_location): New public entrypoint.
(diagnostic_node_set_label): New public entrypoint.
(diagnostic_node_set_logical_location): New public entrypoint.
(private_diagnostic_execution_path_add_event_2): New private
entrypoint.
(private_diagnostic_graph_set_property_bag): New private
entrypoint.
(private_diagnostic_node_set_property_bag): New private
entrypoint.
(private_diagnostic_edge_set_property_bag): New private
entrypoint.
* libgdiagnostics.h (diagnostic_graph): New typedef.
(diagnostic_node): New typedef.
(diagnostic_edge): New typedef.
(diagnostic_manager_new_graph): New decl.
(diagnostic_manager_take_global_graph): New decl.
(diagnostic_take_graph): New decl.
(diagnostic_graph_release): New decl.
(diagnostic_graph_set_description): New decl.
(diagnostic_graph_add_node): New decl.
(diagnostic_graph_add_edge): New decl.
(diagnostic_graph_get_node_by_id): New decl.
(diagnostic_graph_get_edge_by_id): New decl.
(diagnostic_node_set_label): New decl.
(diagnostic_node_set_location): New decl.
(diagnostic_node_set_logical_location): New decl.
* libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_3): New.
* libsarifreplay.cc: Include "libgdiagnostics-private.h".
(id_map): New "using".
(sarif_replayer::report_invalid_sarif): Update for change to
report_problem params.
(sarif_replayer::report_unhandled_sarif): Likewise.
(sarif_replayer::report_note): New.
(sarif_replayer::report_problem): Pass param "ref" by
pointer rather than reference and handle it being null.
(sarif_replayer::maybe_get_property_bag): New.
(sarif_replayer::maybe_get_property_bag_value): New.
(sarif_replayer::handle_run_obj): Handle run-level "graphs" as per
§3.14.20.
(sarif_replayer::handle_result_obj): Handle result-level "graphs"
as per §3.27.19.
(handle_thread_flow_location_object): Optionally handle graphs
stored in property "gcc/diagnostic_event/state_graph" as state
graphs.
(sarif_replayer::handle_graph_object): New.
(sarif_replayer::handle_node_object): New.
(sarif_replayer::handle_edge_object): New.
(sarif_replayer::get_graph_node_by_id_property): New.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::diagnostic_graph_cc_tests and
selftest::diagnostic_state_graph_cc_tests.
* selftest.h (selftest::diagnostic_graph_cc_tests): New decl.
(selftest::diagnostic_state_graph_cc_tests): New decl.
gcc/analyzer/ChangeLog:
* ana-state-to-diagnostic-state.cc: Reimplement, replacing
XML-based implementation with one based on state graphs.
* ana-state-to-diagnostic-state.h: Likewise.
* checker-event.cc: Replace include of "xml.h" with include of
"diagnostic-state-graphs.h".
(checker_event::maybe_make_xml_state): Replace with...
(checker_event::maybe_make_diagnostic_state_graph): ...this.
* checker-event.h: Add include of "diagnostic-digraphs.h".
(checker_event::maybe_make_xml_state): Replace decl with...
(checker_event::maybe_make_diagnostic_state_graph): ...this.
* engine.cc (exploded_node::on_stmt_pre): Replace
"_analyzer_dump_xml" with "__analyzer_dump_sarif".
* program-state.cc: Replace include of "diagnostic-state.h" with
"diagnostic-state-graphs.h".
(program_state::dump_dot): Port from XML to state graphs.
* program-state.h: Drop reduntant forward decl of xml::document.
(program_state::make_xml): Replace decl with...
(program_state::make_diagnostic_state_graph): ...this.
(program_state::dump_xml_to_pp): Drop decl.
(program_state::dump_xml_to_file): Drop decl.
(program_state::dump_xml): Drop decl.
(program_state::dump_dump_sarif): New decl.
* sm-malloc.cc (get_dynalloc_state_for_state): New.
(malloc_state_machine::add_state_to_xml): Replace with...
(malloc_state_machine::add_state_to_state_graph): ...this.
* sm.cc (state_machine::add_state_to_xml): Replace with...
(state_machine::add_state_to_state_graph): ...this.
(state_machine::add_global_state_to_xml): Replace with...
(state_machine::add_global_state_to_state_graph): ...this.
* sm.h (class xml_state): Drop forward decl.
(class analyzer_state_graph): New forward decl.
(state_machine::add_state_to_xml): Replace decl with...
(state_machine::add_state_to_state_graph): ...this.
(state_machine::add_global_state_to_xml): Replace decl with...
(state_machine::add_global_state_to_state_graph): ...this.
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/state-diagram-1-sarif.py (test_xml_state):
Rename to...
(test_state_graph): ...this. Port from XML to SARIF graphs.
* gcc.dg/analyzer/state-diagram-1.c: Update sink option
from "sarif:xml-state=yes" to "sarif:state-graphs=yes".
* gcc.dg/analyzer/state-diagram-5-sarif.c: Likewise.
* gcc.dg/analyzer/state-diagram-5-sarif.py: Drop import of ET.
(test_nested_types_in_xml_state): Rename to...
(test_nested_types_in_state_graph): ...this. Port from XML to
SARIF graphs.
* gcc.dg/plugin/diagnostic-test-graphs-html.c: New test.
* gcc.dg/plugin/diagnostic-test-graphs-html.py: New test script.
* gcc.dg/plugin/diagnostic-test-graphs-sarif.c: New test.
* gcc.dg/plugin/diagnostic-test-graphs-sarif.py: New test script.
* gcc.dg/plugin/diagnostic-test-graphs.c: New test.
* gcc.dg/plugin/diagnostic_plugin_test_graphs.cc: New test plugin.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above.
* lib/sarif.py (get_xml_state): Delete.
(get_state_graph): New.
(def get_state_node_attr): New.
(get_state_node_kind): New.
(get_state_node_name): New.
(get_state_node_type): New.
(get_state_node_value): New.
* sarif-replay.dg/2.1.0-invalid/3.40.2-duplicate-node-id.sarif:
New test.
* sarif-replay.dg/2.1.0-invalid/3.41.4-unrecognized-node-id.sarif:
New test.
* sarif-replay.dg/2.1.0-valid/graphs-check-html.py: New test
script.
* sarif-replay.dg/2.1.0-valid/graphs-check-sarif-roundtrip.py: New
test script.
* sarif-replay.dg/2.1.0-valid/graphs.sarif: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Modernization; no functional change intended.
gcc/analyzer/ChangeLog:
* checker-event.cc (function_entry_event::get_meaning): Convert
diagnostic_event::meaning enums to enum class.
(cfg_edge_event::get_meaning): Likewise.
(call_event::get_meaning): Likewise.
(return_event::get_meaning): Likewise.
(start_consolidated_cfg_edges_event::get_meaning): Likewise.
(inlined_call_event::get_meaning): Likewise.
(warning_event::get_meaning): Likewise.
* sm-fd.cc (fd_diagnostic::get_meaning_for_state_change):
Likewise.
* sm-file.cc (file_diagnostic::get_meaning_for_state_change):
Likewise.
* sm-malloc.cc (malloc_diagnostic::get_meaning_for_state_change):
Likewise.
* sm-sensitive.cc
(exposure_through_output_file::get_meaning_for_state_change):
Likewise.
* sm-taint.cc (taint_diagnostic::get_meaning_for_state_change):
Likewise.
* varargs.cc
(va_list_sm_diagnostic::get_meaning_for_state_change): Likewise.
gcc/ChangeLog:
* diagnostic-format-sarif.cc
(sarif_builder::maybe_make_kinds_array): Convert
diagnostic_event::meaning enums to enum class.
* diagnostic-path-output.cc (path_label::get_text): Likewise.
* diagnostic-path.cc
(diagnostic_event::meaning::maybe_get_verb_str): Likewise.
(diagnostic_event::meaning::maybe_get_noun_str): Likewise.
(diagnostic_event::meaning::maybe_get_property_str): Likewise.
* diagnostic-path.h (diagnostic_event::verb): Likewise.
(diagnostic_event::noun): Likewise.
(diagnostic_event::property): Likewise.
(diagnostic_event::meaning): Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_gil_plugin.cc
(gil_diagnostic::get_meaning_for_state_change): Convert
diagnostic_event::meaning enums to enum class.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
The "json" output format for diagnostics was deprecated in GCC 15, with
advice to users seeking machine-readable diagnostics from GCC to use
SARIF instead.
This patch eliminates it from GCC 16, simplifying the diagnostics
subsystem somewhat.
Note that the Ada frontend seems to have its own implementation of this
in errout.adb (Output_JSON_Message), and documented in
gnat_ugn.texi. This patch does not touch Ada.
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Drop diagnostic-format-json.o.
* common.opt (fdiagnostics-format=): Drop
"json|json-stderr|json-file".
(diagnostics_output_format): Drop values "json", "json-stderr",
and "json-file".
* diagnostic-format-json.cc: Delete file.
* diagnostic-format.h
(diagnostic_output_format_init_json_stderr): Delete.
(diagnostic_output_format_init_json_file): Delete.
* diagnostic.cc (diagnostic_output_format_init): Delete cases for
DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR and
DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE.
* diagnostic.h (DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR): Delete.
(DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE): Delete.
* doc/invoke.texi: Remove references to json output format.
* doc/ux.texi: Likewise.
* selftest-run-tests.cc (selftest::run_tests): Drop call to
deleted selftest::diagnostic_format_json_cc_tests.
* selftest.h (selftest::diagnostic_format_json_cc_tests): Delete.
gcc/testsuite/ChangeLog:
* c-c++-common/analyzer/out-of-bounds-diagram-1-json.c: Deleted test.
* c-c++-common/diagnostic-format-json-1.c: Deleted test.
* c-c++-common/diagnostic-format-json-2.c: Deleted test.
* c-c++-common/diagnostic-format-json-3.c: Deleted test.
* c-c++-common/diagnostic-format-json-4.c: Deleted test.
* c-c++-common/diagnostic-format-json-5.c: Deleted test.
* c-c++-common/diagnostic-format-json-file-1.c: Deleted test.
* c-c++-common/diagnostic-format-json-stderr-1.c: Deleted test.
* c-c++-common/pr106133.c: Deleted test.
* g++.dg/pr90462.C: Deleted test.
* gcc.dg/plugin/diagnostic-test-paths-3.c: Deleted test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Remove deleted
test.
* gfortran.dg/diagnostic-format-json-1.F90: Deleted test.
* gfortran.dg/diagnostic-format-json-2.F90: Deleted test.
* gfortran.dg/diagnostic-format-json-3.F90: Deleted test.
* gfortran.dg/diagnostic-format-json-pr105916.F90: Deleted test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch adds various support for debugging diagnostic paths and
events, intended initially for myself to help with debugging -fanalyzer.
It adds the optional ability for a diagnostic_event to supply a
description of the predicted state of the program at that point along
the diagnostic_path. To isolate the diagnostic subsystem from the
analyzer, this representation is currently an xml::document with custom
elements. The XML representation is similar to the analyzer's internal
state but can be easier to read - for example, rather than storing the
contents of memory via byte offsets, it uses fields for structs and
element indexes for arrays, recursively.
These states are handled by the HTML and SARIF diagnostic sinks.
The SARIF sink simply embeds the XML as a string in a property bag of the
threadFlowLocation object (SARIF v2.1.0 section 3.38).
For HTML output, the "experimental-html" sink gains a new
"show-state-diagrams=yes" option i.e.:
-fdiagnostics-add-output=experimental-html:show-state-diagrams=yes
which converts the state XML into SVG diagrams visualizing the state of
memory at each event, inspired by the "ddd" debugger. These can be seen
by pressing 'j' and 'k' to single-step forward and backward through
events, making it *much* easier to debug -fanalyzer.
An example of output can be seen here:
https://dmalcolm.fedorapeople.org/gcc/2025-06-23/state-diagram-1.c.html
showing an issue in a singly-linked list; there are various other
examples in the parent directory.
Generating the SVG diagrams requires an invocation of "dot" per event,
so it noticeable slows down diagnostic emission, hence the opt-in
command-line flag. However, I'm already finding bugs in -fanalyzer with
this that I hadn't seen before.
Given that the UI is rather clunky and there is lots of room for
improvement to the visualizations, for now this feature is marked
as being for GCC developers, not end-users.
The patch also adds a dot::ast_node class hierarachy to make it easy to
create GraphViz dot files with the correct escaping, and adds a C++
wrapper around pex adding some syntactic sugar for invoking
subprocesses.
gcc/ChangeLog:
PR other/116792
* Makefile.in (ANALYZER_OBJS): Add
analyzer/ana-state-to-diagnostic-state.o.
(OBJS): Move graphviz.o to...
(OBJS-libcommon): ...here. Add diagnostic-state-to-dot.o and pex.o.
* diagnostic-format-html.cc: Include "diagnostic-state.h" and
"graphviz.h".
(html_generation_options::html_generation_options): Initialize the
new flags.
(HTML_SCRIPT): Add function "get_any_state_diagram". Use it
when changing current focus id to update the visibility of the
pertinent diagram, if any.
(print_pre_source): New.
(html_builder::maybe_make_state_diagram): New.
(html_path_label_writer::html_path_label_writer): Add "path" param.
Initialize m_path and m_curr_event_id.
(html_path_label_writer::begin_label): Store current event id.
(html_path_label_writer::end_label): Attempt to make a state
diagram and add it if successful.
(html_path_label_writer::get_element_id): New.
(html_path_label_writer::m_path): New field.
(html_path_label_writer::m_curr_event_id): New field.
(html_builder::make_element_for_diagnostic): Pass path to label
writer.
* diagnostic-format-html.h
(html_generation_options::m_show_state_diagrams): New field.
(html_generation_options::m_show_state_diagram_xml): New field.
(html_generation_options::m_show_state_diagram_dot_src): New field.
* diagnostic-format-sarif.cc: Include "xml.h".
(populate_thread_flow_location_object): If requested, attempt to
generate xml state and add it to the proeprty bag as
"gcc/diagnostic_event/xml_state" in xml source form.
(sarif_generation_options::sarif_generation_options): Initialize
m_xml_state.
* diagnostic-format-sarif.h
(sarif_generation_options::m_xml_state): New field.
* diagnostic-path.cc: Define INCLUDE_MAP. Include "xml.h".
(diagnostic_event::maybe_make_xml_state): New.
* diagnostic-path.h (class xml::document): New forward decl.
(diagnostic_event::maybe_make_xml_state): New vfunc decl.
* diagnostic-state-to-dot.cc: New file.
* diagnostic-state.h: New file.
* digraph.cc: Define INCLUDE_STRING and INCLUDE_VECTOR.
* doc/analyzer.texi: Document state diagrams in html output.
(__analyzer_dump_dot): New.
(__analyzer_dump_xml): New.
* doc/invoke.texi (sarif): Add "xml-state" key.
(experimental-html): Add keys "show-state-diagrams",
"show-state-diagrams-dot-src" and "show-state-diagrams-xml".
* graphviz.cc: Define INCLUDE_MAP, INCLUDE_STRING, and
INCLUDE_VECTOR. Include "xml.h", "xml-printer.h", "pex.h" and
"selftest.h".
(graphviz_out::graphviz_out): Extract...
(dot::writer::writer): ...this.
(graphviz_out::write_indent): Convert to...
(dot::writer::write_indent): ...this.
(graphviz_out::print): Use get_pp.
(graphviz_out::println): Likewise.
(graphviz_out::begin_tr): Likewise.
(graphviz_out::end_tr): Likewise.
(graphviz_out::begin_td): Likewise.
(graphviz_out::end_td): Likewise.
(graphviz_out::begin_trtd): Likewise.
(graphviz_out::end_tdtr): Likewise.
(dot::ast_node::dump): New.
(dot::id::id): New.
(dot::id::print): New.
(dot::id::is_identifier_p): New.
(dot::kv_pair::print): New.
(dot::attr_list::print): New.
(dot::stmt_list::print): New.
(dot::stmt_list::add_edge): New.
(dot::stmt_list::add_attr): New.
(dot::graph::print): New.
(dot::stmt_with_attr_list::set_label): New.
(dot::node_stmt::print): New.
(dot::attr_stmt::print): New.
(dot::kv_stmt::print): New.
(dot::node_id::print): New.
(dot::port::print): New.
(dot::edge_stmt::print): New.
(dot::subgraph::print): New.
(dot::make_svg_document_buffer_from_graph): New.
(dot::make_svg_from_graph): New.
(selftest:test_ids): New.
(selftest:test_trivial_graph): New.
(selftest:test_layout_example): New.
(selftest:graphviz_cc_tests): New.
* graphviz.h (xml::node): New forward decl.
(class graphviz_out): Split out into...
(class dot::writer): ...this new class
(struct dot::ast_node): New.
(struct dot::id): New.
(struct dot::kv_pair): New.
(struct dot::attr_list): New.
(struct dot::stmt_list): New.
(struct dot::graph): New.
(struct dot::stmt): New.
(struct dot::stmt_with_attr_list): New.
(struct dot::node_stmt): New.
(struct dot::attr_stmt): New.
(struct dot::kv_stmt): New.
(enum class dot::compass_pt): New.
(struct dot::port): New.
(struct dot::node_id): New.
(struct dot::edge_stmt): New.
(struct dot::subgraph): New.
(dot::make_svg_from_graph): New.
* opts-diagnostic.cc (sarif_scheme_handler::make_sink): Add
"xml-state" flag.
(html_scheme_handler::make_sink): Add flags "show-state-diagrams",
"show-state-diagram-dot-src", and "show-state-diagram-xml".
* pex.cc: New file.
* pex.h: New file.
* selftest-run-tests.cc (selftest::run_tests): Call
graphviz_cc_tests.
* selftest.h (selftest::graphviz_cc_tests): New decl.
* xml.cc (xml::node_with_children::add_comment): New.
(xml::node_with_children::find_child_element): New.
(xml::element::get_attr): New.
(xml::comment::write_as_xml): New.
(selftest::test_printer): Add coverage of find_child_element and
get_attr.
(selftest::test_comment): New.
(selftest::xml_cc_tests): Call test_comment.
* xml.h: New forward decls.
(xml::node::dyn_cast_text): Use nullptr.
(xml::node::dyn_cast_element): New vfunc.
(xml::node_with_children::add_comment): New decl.
(xml::node_with_children::find_child_element): New decl.
(xml::element::dyn_cast_element): New vfunc impl.
(xml::element::get_attr): New decl.
(struct xml::comment): New xml::node subclass.
gcc/analyzer/ChangeLog:
PR other/116792
* ana-state-to-diagnostic-state.cc: New file.
* ana-state-to-diagnostic-state.h: New file.
* checker-event.cc: Include "xml.h".
(checker_event::checker_event): Initialize m_path.
(checker_event::prepare_for_emission): Store the path pointer into
m_path.
(checker_event::maybe_make_xml_state): New.
(function_entry_event::function_entry_event): Add "state" param
and use it to initialize m_state.
(superedge_event::get_program_state): New.
(call_event::get_program_state): New.
(warning_event::get_program_state): New.
* checker-event.h (checker_event::get_program_state): New vfunc.
(checker_event::maybe_make_xml_state): New decl.
(checker_event::m_path): New field.
(statement_event::get_program_state): New vfunc impl.
(function_entry_event::function_entry_event): Add "state" param.
(function_entry_event::get_program_state): New vfunc impl.
(function_entry_event::m_state): New field.
(state_change_event::get_program_state): New vfunc impl.
(superedge_event::get_program_state): New vfunc decl.
(warning_event::warning_event): Add "program_state_" param and
copy it.
(warning_event::get_program_state): New vfunc decl.
(warning_event::m_program_state): New field.
* checker-path.h (checker_path::checker_path): Add ext_state param.
(checker_path::get_ext_state): New accessor.
(checker_path::m_ext_state): New field.
* common.h: Define INCLUDE_MAP and INCLUDE_STRING.
* diagnostic-manager.cc (saved_diagnostic::operator==): Don't
deduplicate dump_path_diagnostic instances.
(diagnostic_manager::emit_saved_diagnostic): Pass ext_state to
checker_path ctor.
* engine.cc:
(impl_region_model_context::on_state_leak): Pass old and new state
to state_machine::on_leak.
(exploded_node::on_stmt_pre): Implement __analyzer_dump_xml and
__analyzer_dump_dot.
* exploded-graph.h (impl_region_model_context::get_state): New.
* infinite-recursion.cc
(recursive_function_entry_event::recursive_function_entry_event):
Add "dst_state" param and pass to function_entry_event ctor.
(infinite_recursion_diagnostic::add_function_entry_event): Pass state
to event ctor.
* kf-analyzer.cc: Include "analyzer/program-state.h"
(dump_path_diagnostic::dump_path_diagnostic): Add "state" param.
(dump_path_diagnostic::get_final_state): New.
(dump_path_diagnostic::m_state): New field.
(kf_analyzer_dump_path::impl_call_pre): Pass state to warning.
* pending-diagnostic.cc
(pending_diagnostic::add_function_entry_event): Pass state to
function_entry_event.
(pending_diagnostic::add_final_event): Likewise to warning_event.
* pending-diagnostic.h (pending_diagnostic::get_final_state): New
vfunc decl.
* program-state.cc: Include "diagnostic-state.h", "graphviz.h" and
"analyzer/ana-state-to-diagnostic-state.h".
(program_state::dump_dot): New.
* program-state.h: Include "text-art/tree-widget.h" and
"analyzer/store.h".
(class xml::document): New forward decl.
(make_xml): New.
(dump_xml_to_pp): New.
(dump_xml_to_file): New.
(dump_xml): New.
(dump_dot): New.
* record-layout.cc (record_layout::record_layout): Make param
const_tree.
* record-layout.h (item::item): Likewise.
(item::m_field): Likewise.
(record_layout::record_layout): Likewise.
(record_layout::begin): New.
(record_layout::end): New.
* region-model.cc
(exposure_through_uninit_copy::complain_about_fully_uninit_item):
Use const_tree.
(exposure_through_uninit_copy::complain_about_partially_uninit_item):
Likewise.
* region-model.h (region_model_context::get_state): New vfunc.
(noop_region_model_context::get_state): New.
(region_model_context_decorator::get_state): New.
* sm-fd.cc (fd_leak::fd_leak): Add "final_state" param and capture
it if present.
(fd_leak::get_final_state): New.
(fd_leak::m_final_state): New.
(fd_state_machine::on_open): Pass nullptr for new "final_state"
param.
(fd_state_machine::on_creat): Likewise.
(fd_state_machine::on_socket): Likewise.
(fd_state_machine::on_accept): Likewise.
(fd_state_machine::on_leak): Add state params and pass new state
as final state to fd_leak ctor.
* sm-file.cc: Include "analyzer/program-state.h".
(file_leak::file_leak): Add "final_state" param and capture it if
present.
(file_leak::get_final_state): New.
(file_leak::m_final_state): New.
(fileptr_state_machine::on_leak): Add state params and pass new
state as final state to fd_leak ctor.
* sm-malloc.cc: Include
"analyzer/ana-state-to-diagnostic-state.h".
(malloc_leak::malloc_leak): Add "final_state" param and use it.
(malloc_leak::get_final_state): New vfunc impl.
(malloc_leak::m_final_state): New field.
(malloc_state_machine::on_leak): Add state params; capture final
state.
(malloc_state_machine::add_state_to_xml): New.
* sm.cc (state_machine::on_leak): Add "old_state" and "new_state"
params. Use nullptr.
(state_machine::add_state_to_xml): New.
(state_machine::add_global_state_to_xml): New.
* sm.h (class xml_state): New forward decl.
(state_machine::on_leak): Add state params.
(state_machine::add_state_to_xml): New vfunc decl.
(state_machine::add_global_state_to_xml): New vfunc decl.
* store.h (bit_range::operator<): New.
* varargs.cc (va_list_leak::va_list_leak): Add final_state param
and capture it if non-null.
(va_list_leak::get_final_state): New.
(va_list_leak::m_final_state): New.
(va_list_state_machine::on_leak): Add state params and pass final
state to va_list_leak ctor.
gcc/testsuite/ChangeLog:
PR other/116792
* g++.dg/analyzer/state-diagram.C: New test.
* gcc.dg/analyzer/analyzer-decls.h (__analyzer_dump_dot): New
decl.
(__analyzer_dump_xml): New decl.
* gcc.dg/analyzer/state-diagram-1-sarif.py: New test script.
* gcc.dg/analyzer/state-diagram-1.c: New test.
* gcc.dg/analyzer/state-diagram-2.c: New test.
* gcc.dg/analyzer/state-diagram-3.c: New test.
* gcc.dg/analyzer/state-diagram-4.c: New test.
* gcc.dg/analyzer/state-diagram-5-html.py: New test script.
* gcc.dg/analyzer/state-diagram-5-sarif.py: New test script.
* gcc.dg/analyzer/state-diagram-5.c: New test.
* gcc.dg/plugin/analyzer_cpython_plugin.cc: Define INCLUDE_STRING.
* gcc.dg/plugin/analyzer_gil_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_kernel_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_known_fns_plugin.cc: Likewise.
* lib/htmltest.py (ns): Add SVG namespace.
* lib/sarif.py (get_result_by_index): New.
(get_xml_state): New.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch to the "experimental-html" diagnostic sink:
* adds use of the PatternFly 3 CSS library (via an optional link
in the generated html to a copy in a CDN)
* uses PatternFly's "alert" pattern to show severities for diagnostics,
properly nesting "note" diagnostics for diagnostic groups.
Example:
before: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/before/diagnostic-ranges.c.html
after: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/after/diagnostic-ranges.c.html
* adds initial support for logical locations and physical locations
* adds initial support for multi-level nested diagnostics such as those
for C++ concepts diagnostics. Ideally this would show a clickable
disclosure widget to expand/collapse a level, but for now it uses
nested <ul> elements with <li> for the child diagnostics.
Example:
before: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/before/nested-diagnostics-1.C.html
after: https://dmalcolm.fedorapeople.org/gcc/2025-06-10/after/nested-diagnostics-1.C.html
gcc/ChangeLog:
PR other/116792
* diagnostic-format-html.cc: Include "diagnostic-path.h" and
"diagnostic-client-data-hooks.h".
(html_builder::m_logical_loc_mgr): New field.
(html_builder::m_cur_nesting_levels): New field.
(html_builder::m_last_logical_location): New field.
(html_builder::m_last_location): New field.
(html_builder::m_last_expanded_location): New field.
(HTML_STYLE): Add "white-space: pre;" to .source and .annotation.
Add "gcc-quoted-text" CSS class.
(html_builder::html_builder): Initialize the new fields. If CSS
is enabled, add CDN links to PatternFly 3 stylesheets.
(html_builder::add_stylesheet): New.
(html_builder::on_report_diagnostic): Add "alert" param to
make_element_for_diagnostic, setting it by default, but unsetting
it for nested diagnostics below the top level. Use
add_at_nesting_level for nested diagnostics.
(add_nesting_level_attr): New.
(html_builder::add_at_nesting_level): New.
(get_pf_class_for_alert_div): New.
(get_pf_class_for_alert_icon): New.
(get_label_for_logical_location_kind): New.
(add_labelled_value): New.
(html_builder::make_element_for_diagnostic): Add leading comment.
Add "alert" param. Drop class="gcc-diagnostic" from <div> tag,
instead adding the class for a PatternFly 3 alert if "alert" is
true, and adding a <span> with an alert icon, both according to
the diagnostic severity. Add a severity prefix to the message for
alerts. Add any metadata/option text as suffixes to the message.
Show any logical location. Show any physical location. Don't
show the locus if the last location is unchanged within the
diagnostic_group. Wrap any execution path element in a
<div id="execution-path"> and add a label to it. Wrap any
generated patch in a <div id="suggested-fix"> and add a label
to it.
(selftest::test_simple_log): Update expected HTML.
gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/html-output/missing-semicolon.py: Update for changes
to diagnostic elements.
* gcc.dg/format/diagnostic-ranges-html.py: Likewise.
* gcc.dg/plugin/diagnostic-test-metadata-html.py: Likewise. Drop
out-of-date comment.
* gcc.dg/plugin/diagnostic-test-paths-2.py: Likewise.
* gcc.dg/plugin/diagnostic-test-paths-4.py: Likewise. Drop
out-of-date comment.
* gcc.dg/plugin/diagnostic-test-show-locus.py: Likewise.
* lib/htmltest.py (get_diag_by_index): Update to use search by id.
(get_message_within_diag): Update to use search by class.
libcpp/ChangeLog:
PR other/116792
* include/line-map.h (typedef expanded_location): Convert to...
(struct expanded_location): ...this.
(operator==): New decl, for expanded_location.
(operator!=): Likewise.
* line-map.cc (operator==): New decl, for expanded_location.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch reworks the HTML output from the the option
-fdiagnostics-add-output=experimental-html
so that for source quoting and path printing, rather than simply adding
the textual output inside <pre> elements, it breaks up the output
into HTML tags reflecting the structure of the output, using CSS, SVG
and a little javascript to help the user navigate the diagnostics and
the events within any paths.
This uses ideas from the patch I posted in:
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558603.html
but reworks the above patch so that:
* rather than printing source to a pretty_printer, the HTML is created
by building a DOM tree in memory, using a new xml::printer class. This
should be less error-prone than the pretty_printer approach, since it
ought to solve escaping issues. Instead of a text vs html boolean,
the code is generalized via templates with to_text vs to_html sinks.
This templatization applies both to path-printing and
diagnostic-show-locus.cc.
* the HTML output can have multiple diagnostics and multiple paths rather
than just a single path. The javascript keyboard controls now cycle
through all diagnostics and all events within them
An example of the output can be seen at:
https://dmalcolm.fedorapeople.org/gcc/2025-05-27/malloc-1.c.html
where the keys "j" and "k" cycle through diagnostics and events
within them.
gcc/ChangeLog:
PR other/116792
* diagnostic-format-html.cc: Define INCLUDE_STRING.
Include "xml.h", "xml-printer.h", and "json.h".
(html_generation_options::html_generation_options): New.
(namespace xml): Move decls to xml.h and convert from using
label_text to std::string.
(xml::text::write_as_xml): Reimplement indentation so it is done
by this node, rather than the parent.
(xml::node_with_children::add_text): Convert from label_text to
std::string. Consolidate runs of text into a single node.
(xml::document::write_as_xml): Reimplement indentation.
(xml::element::write_as_xml): Reimplement indentation so it is
done by this node, rather than the parent. Convert from
label_text to std::string. Update attribute-printing to new
representation to preserve insertion order.
(xml::element::set_attr): Convert from label_text to std::string.
Record insertion order.
(xml::raw::write_as_xml): New.
(xml::printer::printer): New.
(xml::printer::push_tag): New.
(xml::printer::push_tag_with_class): New.
(xml::printer::pop_tag): New.
(xml::printer::set_attr): New.
(xml::printer::add_text): New.
(xml::printer::add_raw): New.
(xml::printer::push_element): New.
(xml::printer::append): New.
(xml::printer::get_insertion_point): New.
(html_builder::add_focus_id): New.
(html_builder::m_html_gen_opts): New field.
(html_builder::m_head_element): New field.
(html_builder::m_next_diag_id): New field.
(html_builder::m_ui_focus_ids): New field.
(make_div): Convert from label_text to std::string.
(make_span): Likewise.
(HTML_STYLE): New.
(HTML_SCRIPT): New.
(html_builder::html_builder): Fix indentation. Add
"html_gen_opts" param. Initialize new fields. Reimplement
using xml::printer. Optionally add style and script tags.
(class html_path_label_writer): New.
(html_builder::make_element_for_diagnostic): Convert from
label_text to std::string. Set "id" on "gcc-diagnostic" and
"gcc-message" <div> elements; add the latter to the focus ids.
Use diagnostic_context::maybe_show_locus_as_html rather than
html_builder::make_element_for_source. Use print_path_as_html
rather than html_builder::make_element_for_path.
(html_builder::make_element_for_source): Drop.
(html_builder::make_element_for_path): Drop.
(html_builder::make_element_for_patch): Convert from label_text to
std::string.
(html_builder::make_metadata_element): Likewise. Use
xml::printer.
(html_builder::make_element_for_metadata): Convert from label_text
to std::string.
(html_builder::emit_diagram): Expand comment.
(html_builder::flush_to_file): Write out initializer for
"focus_ids" into javascript.
(html_output_format::html_output_format): Add param
"html_gen_opts" and use it to initialize m_builder.
(html_file_output_format::html_file_output_format): Likewise, to
initialize base class.
(make_html_sink): Likewise, to pass to ctor.
(selftest::test_html_diagnostic_context::test_html_diagnostic_context):
Set up html_generation_options.
(selftest::html_buffered_output_format::html_buffered_output_format):
Add html_gen_opts param.
(selftest::test_simple_log): Add id attributes to expected text
for "gcc-diagnostic" and "gcc-message" elements. Update
whitespace for indentation fixes.
(selftest::test_metadata): Update whitespace for indentation
fixes.
(selftest::test_printer): New selftest.
(selftest::test_attribute_ordering): New selftest.
(selftest::diagnostic_format_html_cc_tests): Call the new
selftests.
* diagnostic-format-html.h (struct html_generation_options): New.
(make_html_sink): Add "html_gen_opts" param.
(print_path_as_html): New decl.
* diagnostic-path-output.cc: Define INCLUDE_MAP. Add includes of
"diagnostic-format-html.h", "xml.h", and "xml-printer.h".
(path_print_policy::path_print_policy): Add ctor.
(path_print_policy::get_diagram_theme): Fix whitespace.
(struct stack_frame): New.
(begin_html_stack_frame): New function.
(end_html_stack_frame): New function.
(emit_svg_arrow): New function.
(event_range::print): Rename to...
(event_range::print_as_text): ...this. Update call to
diagnostic_start_span.
(event_range::print_as_html): New, based on the above, but ported
from pretty_printer to xml::printer.
(thread_event_printer::print_swimlane_for_event_range): Rename
to...
(thread_event_printer::print_swimlane_for_event_range_as_text):
...this. Update for renaming of event_range::print to
event_range::print_as_text.
(thread_event_printer::print_swimlane_for_event_range_as_html):
New.
(print_path_summary_as_text): Update for "_as_text" renaming.
(print_path_summary_as_html): New.
(print_path_as_html): New.
* diagnostic-show-locus.cc: Add defines of INCLUDE_MAP and
INCLUDE_STRING. Add includes of "xml.h" and "xml-printer.h".
(struct char_display_policy): Replace "m_print_cb" with
"m_print_text_cb" and "m_print_html_cb".
(struct to_text): New.
(struct to_html): New.
(get_printer): New.
(default_diagnostic_start_span_fn<to_text>): New.
(default_diagnostic_start_span_fn<to_html>): New.
(class layout): Update "friend class layout_printer;" for
template.
(enum class margin_kind): New.
(class layout_printer): Convert into a template.
(layout_printer::m_pp): Replace field with...
(layout_printer::m_sink): ...this.
(layout_printer::m_colorizer): Drop field in favor of a pointer
in the "to_text" sink.
(default_print_decoded_ch): Convert into a template.
(escape_as_bytes_print): Likewise.
(escape_as_unicode_print): Likewise.
(make_char_policy): Update to use both text and html callbacks.
(layout_printer::print_gap_in_line_numbering): Replace with...
(layout_printer<to_text>::print_gap_in_line_numbering): ...this
(layout_printer<to_html>::print_gap_in_line_numbering): ...and
this.
(layout_printer::print_source_line): Convert to template, using
m_sink.
(layout_printer::print_leftmost_column): Likewise.
(layout_printer::start_annotation_line): Likewise.
(layout_printer<to_text>::end_line): New.
(layout_printer<to_html>::end_line): New.
(layout_printer::print_annotation_line): Convert to template,
using m_sink.
(class line_label): Add field m_original_range_idx.
(layout_printer<to_text>::begin_label): New.
(layout_printer<to_html>::begin_label): New.
(layout_printer<to_text>::end_label): New.
(layout_printer<to_html>::end_label): New.
(layout_printer::print_any_labels): Convert to template, using
m_sink.
(layout_printer::print_leading_fixits): Likewise.
(layout_printer::print_trailing_fixits): Likewise.
(layout_printer::print_newline): Drop.
(layout_printer::move_to_column): Convert to template, using
m_sink.
(layout_printer::show_ruler): Likewise.
(layout_printer::print_line): Likewise.
(layout_printer::print_any_right_to_left_edge_lines): Likewise.
(layout_printer::layout_printer): Likewise.
(diagnostic_context::maybe_show_locus_as_html): New.
(diagnostic_source_print_policy::diagnostic_source_print_policy):
Update for split of start_span_cb into text vs html variants.
(diagnostic_source_print_policy::print): Update for use of
templates; use to_text.
(diagnostic_source_print_policy::print_as_html): New.
(layout_printer::print): Convert to template, using m_sink.
(selftest::make_element_for_locus): New.
(selftest::make_raw_html_for_locus): New.
(selftest::test_layout_x_offset_display_utf8): Update for use of
templates.
(selftest::test_layout_x_offset_display_tab): Likewise.
(selftest::test_one_liner_caret_and_range): Add test coverage of
HTML output.
(selftest::test_one_liner_labels): Likewise.
* diagnostic.cc (diagnostic_context::initialize): Update for split
of start_span_cb into text vs html variants.
(default_diagnostic_start_span_fn): Move to
diagnostic-show-locus.cc, converting to template.
* diagnostic.h (class xml::printer): New forward decl.
(diagnostic_start_span_fn): Replace typedef with "using",
converting to a template.
(struct to_text): New forward decl.
(struct to_html): New forward decl.
(get_printer): New decl.
(diagnostic_location_print_policy::print_text_span_start): New
decl.
(diagnostic_location_print_policy::print_html_span_start): New
decl.
(class html_label_writer): New.
(diagnostic_source_print_policy::print_as_html): New decl.
(diagnostic_source_print_policy::get_start_span_fn): Replace
with...
(diagnostic_source_print_policy::get_text_start_span_fn): ...this
(diagnostic_source_print_policy::get_html_start_span_fn): ...and
this
(diagnostic_source_print_policy::m_start_span_cb): Replace with...
(diagnostic_source_print_policy::m_text_start_span_cb): ...this
(diagnostic_source_print_policy::m_html_start_span_cb): ...and
this.
(diagnostic_context::maybe_show_locus_as_html): New decl.
(diagnostic_context::m_text_callbacks::m_start_span): Replace
with...
(diagnostic_context::m_text_callbacks::m_text_start_span): ...this
(diagnostic_context::m_text_callbacks::m_html_start_span): ...and
this.
(diagnostic_start_span): Update for template change.
(diagnostic_show_locus_as_html): New inline function.
(default_diagnostic_start_span_fn): Convert to template.
* doc/invoke.texi (experimental-html): Add "css" and "javascript"
keys.
* opts-diagnostic.cc (html_scheme_handler::make_sink): Likewise.
* selftest-diagnostic.cc
(selftest::test_diagnostic_context::start_span_cb): Update for
template changes.
* selftest-diagnostic.h
(selftest::test_diagnostic_context::start_span_cb): Likewise.
* xml-printer.h: New file.
* xml.h: New file, based on material in diagnostic-format-html.cc,
but using std::string rather than label_text.
(xml::element::m_key_insertion_order): New field.
(struct xml::raw): New.
gcc/fortran/ChangeLog
PR other/116792
* error.cc (gfc_diagnostic_start_span): Update for diagnostic.h
changes.
gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/html-output/missing-semicolon.c: Add ":javascript=no" to
html output.
* gcc.dg/html-output/missing-semicolon.py: Move repeated
definitions into lib/htmltest.py.
* gcc.dg/plugin/diagnostic_group_plugin.cc: Update for template
changes.
* gcc.dg/plugin/diagnostic-test-metadata-html.c: Add
":javascript=no" to html output. Add
"-fdiagnostics-show-line-numbers".
* gcc.dg/plugin/diagnostic-test-metadata-html.py: Move repeated
definitions into lib/htmltest.py. Add checks of annotated source.
* gcc.dg/plugin/diagnostic-test-paths-2.c: Add ":javascript=no" to
html output.
* gcc.dg/plugin/diagnostic-test-paths-2.py: Move repeated
definitions into lib/htmltest.py. Add checks of execution path.
* gcc.dg/plugin/diagnostic-test-paths-4.c: Add
-fdiagnostics-add-output=experimental-html:javascript=no. Add
invocation ot diagnostic-test-paths-4.py.
* gcc.dg/plugin/diagnostic-test-paths-4.py: New test script.
* gcc.dg/plugin/diagnostic-test-show-locus-bw-line-numbers.c: Add
-fdiagnostics-add-output=experimental-html:javascript=no. Add
invocation of diagnostic-test-show-locus.py.
* gcc.dg/plugin/diagnostic-test-show-locus.py: New test script.
* lib/htmltest.py: New test support script.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Add barebones support for
* diagnostic metadata rules
* quoted source
* generated patches
* execution paths
gcc/ChangeLog:
PR other/116792
* diagnostic-format-html.cc: Include "diagnostic-format-text.h",
"pretty-print-urlifier.h" and "edit-context.h".
(html_builder::html_builder): Fix indentation in decl.
(html_builder::make_element_for_diagnostic): Split out metadata
code into make_element_for_metadata. Call
make_element_for_source, make_element_for_path, and
make_element_for_patch.
(html_builder::make_element_for_source): New.
(html_builder::make_element_for_path): New.
(html_builder::make_element_for_patch): New.
(html_builder::make_metadata_element): New.
(html_builder::make_element_for_metadata): New.
(html_output_format::get_builder): New.
(selftest::test_html_diagnostic_context::get_builder): New.
(selftest::test_simple_log): Update test to print a quoted string,
and verify that it uses a "gcc-quoted-text" span.
(selftest::test_metadata): New.
(selftest::diagnostic_format_html_cc_tests): Call it.
gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/html-output/missing-semicolon.py: Verify that we don't
have an empty "gcc-annotated-source" and we do have a
"gcc-generated-patch".
* gcc.dg/plugin/diagnostic-test-metadata-html.c: New test.
* gcc.dg/plugin/diagnostic-test-metadata-html.py: New test script.
* gcc.dg/plugin/diagnostic-test-paths-2.c: Add
"-fdiagnostics-add-output=experimental-html" to options. Add
invocation of diagnostic-test-paths-2.py.
* gcc.dg/plugin/diagnostic-test-paths-2.py: New test script.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
diagnostic-test-metadata-html.c.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
[PR116792]
In r15-3752-g48261bd26df624 I added a test plugin that overrode the
regular output, instead emitting diagnostics in crude HTML form.
In r15-4760-g0b73e9382ab51c I added support for multiple kinds of
diagnostic output simultaneously, adding
-fdiagnostics-add-output=DIAGNOSTICS-OUTPUT-SPEC
-fdiagnostics-set-output=DIAGNOSTICS-OUTPUT-SPEC
for adding/changing the kind of diagnostics output, supporting
"text" and "sarif" output schemes.
This patch promotes the HTML output code from the test plugins so
that it is available from "-fdiagnostics-add-output=", using a
new "experimental-html" scheme, to allow simultaneous text, sarif
and html output, and to make it easier to experiment with. The
patch adds Python-based testing of the emitted HTML.
The patch does not affect the generated HTML, which is still crude, and
not yet ready for end-users. I hope to improve it in followups.
gcc/ChangeLog:
PR other/116792
* Makefile.in (OBJS-libcommon): Add diagnostic-format-html.o.
* diagnostic-format-html.cc: Move here from
testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc.
Simplify includes. Rename "xhtml" to "html" throughout.
(write_escaped_text): Drop.
(class xhtml_stream_output_format): Drop.
(class html_file_output_format): Reimplement using
diagnostic_output_file.
(diagnostic_output_format_init_xhtml): Drop.
(diagnostic_output_format_init_xhtml_stderr): Drop.
(diagnostic_output_format_init_xhtml_file): Drop.
(diagnostic_output_format_open_html_file): New.
(make_html_sink): New.
(xhtml_format_selftests): Convert to...
(diagnostic_format_html_cc_tests): ...this.
(plugin_is_GPL_compatible): Drop.
(plugin_init): Drop.
* diagnostic-format-html.h: New file.
* doc/invoke.texi (-fdiagnostics-add-output=): Add
"experimental-html" scheme.
* opts-diagnostic.cc: Include "diagnostic-format-html.h".
(class html_scheme_handler): New.
(output_factory::output_factory): Add html_scheme_handler.
(html_scheme_handler::make_sink): New.
* selftest-run-tests.cc (selftest::run_tests): Call the new
selftests.
* selftest.h (selftest::diagnostic_format_html_cc_tests): New
decl.
gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc: Move to
gcc/diagnostic-format-html.cc.
* gcc.dg/html-output/html-output.exp: New support script.
* gcc.dg/html-output/missing-semicolon.c: New test.
* gcc.dg/html-output/missing-semicolon.py: New test script.
* gcc.dg/plugin/diagnostic-test-xhtml-1.c: Deleted test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Drop moved plugin
and its deleted test.
* lib/gcc-dg.exp (load_lib): Add load_lib of scanhtml.exp.
* lib/htmltest.py: New support script.
* lib/scanhtml.exp: New support script, based on scansarif.exp.
libatomic/ChangeLog:
PR other/116792
* testsuite/lib/libatomic.exp: Add load_lib of scanhtml.exp.
libgomp/ChangeLog:
PR other/116792
* testsuite/lib/libgomp.exp: Add load_lib of scanhtml.exp.
libitm/ChangeLog:
PR other/116792
* testsuite/lib/libitm.exp: Add load_lib of scanhtml.exp.
libphobos/ChangeLog:
PR other/116792
* testsuite/lib/libphobos-dg.exp: Add load_lib of scanhtml.exp.
libvtv/ChangeLog:
PR other/116792
* testsuite/lib/libvtv-dg.exp: Add load_lib of scanhtml.exp.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
The backport of the PR108900 fix to 14 branch broke building chromium
because static_assert (__LINE__ == expected_line_number, ""); now triggers
as the __LINE__ values are off by one.
This isn't the case on the trunk and 15 branch because we've switched
to 64-bit location_t and so one actually needs far longer header files
to trigger it.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061#c11
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061#c12
contain (large) testcases in patch form which show on the 14 branch
that the first one used to fail before the PR108900 backport and now
works correctly, while the second one attempts to match the chromium
behavior and it used to pass before the PR108900 backport and now it
FAILs.
The two testcases show rare problematic cases, because
do_include_common -> parse_include -> check_eol -> check_eol_1 ->
cpp_get_token_1 -> _cpp_lex_token -> _cpp_lex_direct -> linemap_line_start
triggers there
/* Allocate the new line_map. However, if the current map only has a
single line we can sometimes just increase its column_bits instead. */
if (line_delta < 0
|| last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map)
|| SOURCE_COLUMN (map, highest) >= (1U << (column_bits - range_bits))
|| ( /* We can't reuse the map if the line offset is sufficiently
large to cause overflow when computing location_t values. */
(to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
>= (((uint64_t) 1)
<< (CHAR_BIT * sizeof (linenum_type) - column_bits)))
|| range_bits < map->m_range_bits)
map = linemap_check_ordinary
(const_cast <line_map *>
(linemap_add (set, LC_RENAME,
ORDINARY_MAP_IN_SYSTEM_HEADER_P (map),
ORDINARY_MAP_FILE_NAME (map),
to_line)));
and so creates a new ordinary map on the line right after the
(problematic) #include line.
Now, in the spot that r14-11679-g8a884140c2bcb7 patched,
pfile->line_table->highest_location in all 3 tests (also
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061#c13
) is before the decrement the start of the line after the #include line and so
the decrement is really desirable in that case to put highest_location
somewhere on the line where the #include actually is.
But at the same time it is also undesirable, because if we do decrement it,
then linemap_add LC_ENTER called from _cpp_do_file_change will then
/* Generate a start_location above the current highest_location.
If possible, make the low range bits be zero. */
location_t start_location = set->highest_location + 1;
unsigned range_bits = 0;
if (start_location < LINE_MAP_MAX_LOCATION_WITH_COLS)
range_bits = set->default_range_bits;
start_location += (1 << range_bits) - 1;
start_location &= ~((1 << range_bits) - 1);
linemap_assert (!LINEMAPS_ORDINARY_USED (set)
|| (start_location
>= MAP_START_LOCATION (LINEMAPS_LAST_ORDINARY_MAP (set))));
and we can end up with the new LC_ENTER ordinary map having the same
start_location as the preceding LC_RENAME one.
Next thing that happens is computation of included_from:
if (reason == LC_ENTER)
{
if (set->depth == 0)
map->included_from = 0;
else
/* The location of the end of the just-closed map. */
map->included_from
= (((map[0].start_location - 1 - map[-1].start_location)
& ~((1 << map[-1].m_column_and_range_bits) - 1))
+ map[-1].start_location);
The normal case (e.g. with the testcase included at the start of this comment) is
that map[-1] starts somewhere earlier and so map->included_from computation above
nicely computes location_t which expands to the start of the #include line.
With r14-11679 reverted, for #c11 as well as #c12
map[0].start_location == map[-1].start_location above, and so it is
((location_t) -1 & ~((1 << map[-1].m_column_and_range_bits) - 1)))
+ map[-1].start_location,
which happens to be start of the #include line.
For #c11 map[0].start_location is 0x500003a0 and map[-1] has
m_column_and_range_bits 7 and map[-2] has m_column_and_range_bits 12 and
map[0].included_from is set to 0x50000320.
For #c12 map[0].start_location is 0x606c0402 and map[-2].start_location is
0x606c0400 and m_column_and_range_bits is 0 for all 3 maps.
map[0].included_from is set to 0x606c0401.
The last important part is again in linemap_add when doing LC_LEAVE:
/* (MAP - 1) points to the map we are leaving. The
map from which (MAP - 1) got included should be the map
that comes right before MAP in the same file. */
from = linemap_included_from_linemap (set, map - 1);
/* A TO_FILE of NULL is special - we use the natural values. */
if (to_file == NULL)
{
to_file = ORDINARY_MAP_FILE_NAME (from);
to_line = SOURCE_LINE (from, from[1].start_location);
sysp = ORDINARY_MAP_IN_SYSTEM_HEADER_P (from);
}
Here it wants to compute the right to_line which ought to be the line after
the #include directive.
On the #c11 testcase that doesn't work correctly though, because
map[-1].included_from is 0x50000320, from[0] for that is LC_ENTER with
start_location 0x4080 and m_column_and_range_bits 12 but note that we've
earlier computed map[-1].start_location + (-1 & 0xffffff80) and so only
decreased by 7 bits, so to_line is still on the line with #include and not
after it. In the #c12 that doesn't happen, all the ordinary maps involved
there had 0 m_column_and_range_bits and so this computes correct line.
Below is a fix for the trunk including testcases using the
location_overflow_plugin hack to simulate the bugs without needing huge
files (in the 14 case it is just 330KB and almost 10MB, but in the 15
case it would need to be far bigger).
The pre- r15-9018 trunk has
FAIL: gcc.dg/plugin/location-overflow-test-pr116047.c -fplugin=./location_overflow_plugin.so scan-file static_assert[^\n\r]*6[^\n\r]*== 6
and current trunk
FAIL: gcc.dg/plugin/location-overflow-test-pr116047.c -fplugin=./location_overflow_plugin.so scan-file static_assert[^\n\r]*6[^\n\r]*== 6
FAIL: gcc.dg/plugin/location-overflow-test-pr120061.c -fplugin=./location_overflow_plugin.so scan-file static_assert[^\n\r]*5[^\n\r]*== 5
and with the patch everything PASSes.
I'll post afterwards a 14 version of the patch.
The patch reverts the r15-9018 change, because it is incorrect,
we really need to decrement it even when crossing ordinary map
boundaries, so that the location is not on the line after the #include
line but somewhere on the #include line. It also patches two spots
in linemap_add mentioned above to make sure we get correct locations
both in the included_from location_t when doing LC_ENTER (second
line-map.cc hunk) and when doing LC_LEAVE to compute the right to_line
(first line-map.cc hunk), both in presence of an added LC_RENAME
with the same start_location as the following LC_ENTER (i.e. the
problematic cases).
The LC_ENTER hunk is mostly to ensure included_form location_t is
at the start of the #include line (column 0), without it we can
decrease include_from not enough and end up at some random column
in the middle of the line, because it is masking away
map[-1].m_column_and_range_bits bits even when in the end the resulting
include_from location_t will be found in map[-2] map with perhaps
different m_column_and_range_bits. That alone doesn't fix the bug
though.
The more important is the LC_LEAVE hunk and the problem there is
caused by linemap_line_start not actually doing
r = set->highest_line + (line_delta << map->m_column_and_range_bits);
when adding a new map (the LC_RENAME one because we need to switch to
different number of directly encoded ranges, or columns, etc.).
So, in the original PR108900 case that
to_line = SOURCE_LINE (from, from[1].start_location);
doesn't do the right thing, from there is the last < 0x50000000 map
with m_column_and_range_bits 12, from[1] is the first one above it
and map[-1].included_from is the correct location of column 0 on
the #include line, but as the new LC_RENAME map has been created without
actually increasing highest_location to be on the new line (we've just
set to_line of the new LC_RENAME map to the correct line),
to_line = SOURCE_LINE (from, from[1].start_location);
stays on the same source line. I've tried to just replace that with
to_line = SOURCE_LINE (from, linemap_included_from (map - 1)) + 1;
i.e. just find out the #include line from map[-1].included_from and
add 1 to it, unfortunately that breaks the
c-c++-common/cpp/line-4.c
test where we expect to stay on the same 0 line for LC_LEAVE from
<command line> and gcc.dg/cpp/trad/Wunused.c, gcc.dg/cpp/trad/builtins.c
and c-c++-common/analyzer/named-constants-via-macros-traditional.c tests
all with -traditional-cpp preprocessing where to_line is also off-by-one
from the expected one.
So, this patch instead conditionalizes it, uses the
to_line = SOURCE_LINE (from, linemap_included_from (map - 1)) + 1;
way only if from[1] is a LC_RENAME map (rather than the usual
LC_ENTER one), that should limit it to the problematic cases of when
parse_include peeked after EOL and had to create LC_RENAME map with
the same start_location as the LC_ENTER after it.
Some further justification for the LC_ENTER hunk, using the
https://gcc.gnu.org/pipermail/gcc-patches/2025-May/682774.html testcase
(old is 14 before r14-11679, vanilla current 14 and new with the 14 patch)
I get
$ /usr/src/gcc-14/obj/gcc/cc1.old -quiet -std=c23 pr116047.c -nostdinc
In file included from pr116047-1.h:327677:21,
from pr116047.c:4:
pr116047-2.h:1:1: error: unknown type name ‘a’
1 | a b c;
| ^
pr116047-2.h:1:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘c’
1 | a b c;
| ^
pr116047-1.h:327677:1: error: static assertion failed: ""
327677 | #include "pr116047-2.h"
| ^~~~~~~~~~~~~
$ /usr/src/gcc-14/obj/gcc/cc1.vanilla -quiet -std=c23 pr116047.c -nostdinc
In file included from pr116047-1.h:327678,
from pr116047.c:4:
pr116047-2.h:1:1: error: unknown type name ‘a’
1 | a b c;
| ^
pr116047-2.h:1:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘c’
1 | a b c;
| ^
$ /usr/src/gcc-14/obj/gcc/cc1.new -quiet -std=c23 pr116047.c -nostdinc
In file included from pr116047-1.h:327677,
from pr116047.c:4:
pr116047-2.h:1:1: error: unknown type name ‘a’
1 | a b c;
| ^
pr116047-2.h:1:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘c’
1 | a b c;
| ^
pr116047-1.h has on lines 327677+327678:
#include "pr116047-2.h"
static_assert (__LINE__ == 327678, "");
so the static_assert failure is something that was dealt mainly in the
LC_LEAVE hunk and files.cc reversion, but please have a look at the
In file included from lines.
14.2 emits correct line (#include "pr116047-2.h" is indeed on line
327677) but some random column in there (which is not normally printed
for smaller headers; 21 is the . before extension in the filename).
Current trunk emits incorrect line (327678 instead of 327677, clearly
it didn't decrement).
And the patched compiler emits the right line with no column, as would
be printed if I remove e.g. 300000 newlines from the file.
2025-05-07 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/108900
PR preprocessor/116047
PR preprocessor/120061
* files.cc (_cpp_stack_file): Revert 2025-03-28 change.
* line-map.cc (linemap_add): Use
SOURCE_LINE (from, linemap_included_from (map - 1)) + 1; instead of
SOURCE_LINE (from, from[1].start_location); to compute to_line
for LC_LEAVE. For LC_ENTER included_from computation, look at
map[-2] or even lower if map[-1] has the same start_location as
map[0].
* gcc.dg/plugin/plugin.exp: Add location-overflow-test-pr116047.c
and location-overflow-test-pr120061.c.
* gcc.dg/plugin/location_overflow_plugin.cc (plugin_init): Don't error
on unknown values, instead just break. Handle 0x4fHHHHHH arguments
differently.
* gcc.dg/plugin/location-overflow-test-pr116047.c: New test.
* gcc.dg/plugin/location-overflow-test-pr116047-1.h: New test.
* gcc.dg/plugin/location-overflow-test-pr116047-2.h: New test.
* gcc.dg/plugin/location-overflow-test-pr120061.c: New test.
* gcc.dg/plugin/location-overflow-test-pr120061-1.h: New test.
* gcc.dg/plugin/location-overflow-test-pr120061-2.h: New test.
|
|
Previously we used an abstract base class logical_location with
concrete subclasses to separate the diagnostics subsystem from
implementation details of "tree" and of libgdiagnostics.
This approach required allocating implementation objects on the heap
whenever working with logical locations, and made comparing logical
locations awkward.
This patch reworks things so that the type "logical_location" becomes a
boxed pointer (const void *), and client code provides a single object
implementing a new logical_location_manager abstract base class. The
manager class has responsibility for providing meaning to the boxed
pointers. Within the compiler we use a manager in which they are "tree"
pointers, whereas within libgdiagnostics we use a manager in which they
are pointers to instances of libgdiagnostics'
"struct diagnostic_logical_location". Other kinds of manager could be
implemented.
gcc/analyzer/ChangeLog:
* checker-event.cc (checker_event::checker_event): Update
initialization of m_logical_loc.
(checker_event::maybe_add_sarif_properties): Add "builder" param.
Replace call to make_sarif_logical_location_object with call to
sarif_property_bag::set_logical_location.
(superedge_event::maybe_add_sarif_properties): Add "builder"
param.
* checker-event.h (checker_event::get_logical_location):
Reimplement.
(checker_event::maybe_add_sarif_properties): Add "builder" param.
(checker_event::maybe_add_sarif_properties): Add "builder" param.
(checker_event::m_logical_loc): Convert from tree_logical_location
to logical_location.
(superedge_event::maybe_add_sarif_properties): Add sarif_builder
param.
* checker-path.h (checker_path::checker_path): Add logical_loc_mgr
param.
* diagnostic-manager.cc
(diagnostic_manager::emit_saved_diagnostic): Pass logical location
manager to emission_path ctor.
(diagnostic_manager::get_logical_location_manager): New.
* diagnostic-manager.h
(diagnostic_manager::get_logical_location_manager): New decl.
gcc/ChangeLog:
* diagnostic-client-data-hooks.h: Include "logical-location.h".
(diagnostic_client_data_hooks::get_logical_location_manager): New.
(diagnostic_client_data_hooks::get_current_logical_location):
Convert return type from const logical_location * to
logical_location.
* diagnostic-format-json.cc: Include
"diagnostic-client-data-hooks.h".
(make_json_for_path): Update to use logical_location_manager from
the context.
* diagnostic-format-sarif.cc
(sarif_builder::get_logical_location_manager): New.
(sarif_builder::make_location_object): Update type of logical_loc
from "const logical_location *" to "logical_location".
(sarif_builder::set_any_logical_locs_arr): Likewise.
(sarif_builder::m_logical_loc_mgr): New field.
(sarif_result::on_nested_diagnostic): Use logical_location default
ctor rather than nullptr.
(sarif_builder::sarif_builder): Initialize m_logical_loc_mgr from
context's client data hooks.
(sarif_builder::make_locations_arr): Convert type of logical_loc
from from "const logical_location *" to "logical_location".
(sarif_builder::set_any_logical_locs_arr): Likewise. Pass manager
to make_sarif_logical_location_object.
(sarif_builder::make_location_object): Likewise.
(sarif_property_bag::set_logical_location): New.
(make_sarif_logical_location_object): Update for introduction of
logical_location_manager.
(populate_thread_flow_location_object): Pass builder to
ev.maybe_add_sarif_properties.
(selftest::test_make_location_object): Use logical_location
default ctor rather than nullptr.
* diagnostic-format-sarif.h (class logical_location): Replace
forward decl with include of "logical-location.h".
(class sarif_builder): New forward decl.
(sarif_property_bag::set_logical_location): New.
(make_sarif_logical_location_object): Add "mgr" param.
* diagnostic-path.cc
(diagnostic_path::get_first_event_in_a_function): Update for
change of logical_location type.
(per_thread_summary::per_thread_summary): Pass in
"logical_loc_mgr".
(per_thread_summary::m_logical_loc_mgr): New field.
(event_range::m_logical_loc): Update for change of
logical_location type.
(path_summary::get_logical_location_manager): New accessor.
(path_summary::m_logical_loc_mgr): New field.
(path_summary::get_or_create_events_for_thread_id): Pass
m_logical_loc_mgr to per_thread_summary ctor.
(path_summary::path_summary): Initialize m_logical_loc_mgr.
(thread_event_printer::print_swimlane_for_event_range): Add param
"logical_loc_mgr". Update for change in logical_loc type.
(print_path_summary_as_text): Pass manager to
thread_event_printer::print_swimlane_for_event_range.
(diagnostic_text_output_format::print_path): Update for
introduction of logical_location_manager.
* diagnostic-path.h: Include "logical-location.h".
(class sarif_builder): New forward decl.
(diagnostic_event::get_logical_location): Convert return type from
"const logical_location *" to "logical_location".
(diagnostic_event::maybe_add_sarif_properties): Add sarif_builder
param.
(diagnostic_path::get_logical_location_manager): New accessor.
(diagnostic_path::diagnostic_path): New ctor, taking manager.
(diagnostic_path::m_logical_loc_mgr): New field.
* diagnostic.cc
(diagnostic_context::get_logical_location_manager): New.
(logical_location::function_p): Convert to...
(logical_location_manager::function_p): ...this.
* diagnostic.h (class logical_location): Replace forward decl
with...
(class logical_location_manager): ...this.
(diagnostic_context::get_logical_location_manager): New decl.
* lazy-diagnostic-path.cc
(selftest::test_lazy_path::test_lazy_path): Pass m_logical_loc_mgr
to path ctor.
(selftest::test_lazy_path::make_inner_path): Likewise.
(selftest::test_lazy_path::m_logical_loc_mgr): New field.
* lazy-diagnostic-path.h
(lazy_diagnostic_path::lazy_diagnostic_path): New ctor.
* libgdiagnostics.cc (struct diagnostic_logical_location): Convert
from subclass of logical_location to a plain struct, dropping
accessors.
(class impl_logical_location_manager): New.
(impl_diagnostic_client_data_hooks::get_logical_location_manager):
New
(impl_diagnostic_client_data_hooks::m_logical_location_manager):
New field.
(diagnostic_manager::get_logical_location_manager): New.
(libgdiagnostics_path_event::get_logical_location): Reimplement.
(diagnostic_execution_path::diagnostic_execution_path): Add
logical_loc_mgr and pass to base class.
(diagnostic_execution_path::same_function_p): Update for change to
logical_location type.
(diagnostic::add_execution_path): Pass logical_loc_mgr to path
ctor.
(impl_diagnostic_client_data_hooks::get_current_logical_location):
Reimplement.
(diagnostic_text_sink::text_starter): Reimplement printing of
logical location.
(diagnostic_manager::new_execution_path): Pass mgr to path ctor.
(diagnostic_manager_debug_dump_logical_location): Update for
changes to diagnostic_logical_location.
(diagnostic_logical_location_get_kind): Likewise.
(diagnostic_logical_location_get_parent): Likewise.
(diagnostic_logical_location_get_short_name): Likewise.
(diagnostic_logical_location_get_fully_qualified_name): Likewise.
(diagnostic_logical_location_get_decorated_name): Likewise.
* logical-location.h (class logical_location_manager): New.
(class logical_location): Convert to typedef of
logical_location_manager::key.
* selftest-diagnostic-path.cc
(selftest::test_diagnostic_path::test_diagnostic_path): Pass
m_test_logical_loc_mgr to base ctor.
(selftest::test_diagnostic_path::same_function_p): Use pointer
comparison.
(selftest::test_diagnostic_path::add_event): Use
logical_location_from_funcname.
(selftest::test_diagnostic_path::add_thread_event): Likewise.
(selftest::test_diagnostic_path::logical_location_from_funcname):
New.
(selftest::test_diagnostic_event::test_diagnostic_event): Fix
indentation. Pass logical_location rather than const char *.
* selftest-diagnostic-path.h
(selftest::test_diagnostic_event::test_diagnostic_event):
Likewise.
(selftest::test_diagnostic_event::get_logical_location): Update
for change to logical_location type.
(selftest::test_diagnostic_event::get_function_name): Drop.
(selftest::test_diagnostic_event::m_logical_loc): Convert from
test_logical_location to logical_location.
(selftest::test_diagnostic_path::logical_location_from_funcname):
New.
(selftest::test_diagnostic_path::m_test_logical_loc_mgr): New
field.
* selftest-logical-location.cc: Include "selftest.h".
(selftest::test_logical_location::test_logical_location): Drop.
(selftest::test_logical_location_manager::~test_logical_location_manager):
New.
(selftest::test_logical_location::get_short_name): Replace with...
(selftest::test_logical_location_manager::get_short_name):
...this.
(selftest::test_logical_location::get_name_with_scope): Replace
with...
(selftest::test_logical_location_manager::get_name_with_scope):
...this.
(selftest::test_logical_location::get_internal_name): Replace
with...
(selftest::test_logical_location_manager::get_internal_name):
...this.
(selftest::test_logical_location::get_kind): Replace with...
(selftest::test_logical_location_manager::get_kind): ...this.
(selftest::test_logical_location::get_name_for_path_output):
Replace with...
(selftest::test_logical_location_manager::get_name_for_path_output):
...this.
(selftest::test_logical_location_manager::logical_location_from_funcname):
New.
(selftest::test_logical_location_manager::item_from_funcname):
New.
(selftest::selftest_logical_location_cc_tests): New.
* selftest-logical-location.h (class test_logical_location):
Replace with...
(class test_logical_location_manager): ...this.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest_logical_location_cc_tests.
* selftest.h (selftest::selftest_logical_location_cc_tests): New
decl.
* simple-diagnostic-path.cc
(simple_diagnostic_path::simple_diagnostic_path): Add
"logical_loc_mgr" param and pass it to base ctor.
(simple_diagnostic_event::simple_diagnostic_event): Update init of
m_logical_loc.
(selftest::test_intraprocedural_path): Update for changes to
logical locations.
* simple-diagnostic-path.h: Likewise.
* tree-diagnostic-client-data-hooks.cc
(compiler_data_hooks::get_logical_location_manger): New.
(compiler_data_hooks::get_current_logical_location): Update.
(compiler_data_hooks::m_current_fndecl_logical_loc): Replace
with...
(compiler_data_hooks::m_logical_location_manager): ...this.
* tree-logical-location.cc
(compiler_logical_location::get_short_name_for_tree): Replace
with...
(tree_logical_location_manager::get_short_name): ...this.
(compiler_logical_location::get_name_with_scope_for_tree): Replace
with...
(tree_logical_location_manager::get_name_with_scope): ...this.
(compiler_logical_location::get_internal_name_for_tree): Replace
with...
(tree_logical_location_manager::get_internal_name): ...this.
(compiler_logical_location::get_kind_for_tree): Replace with...
(tree_logical_location_manager::get_kind): ...this.
(compiler_logical_location::get_name_for_tree_for_path_output):
Replace with...
(tree_logical_location_manager::get_name_for_path_output):
...this.
(tree_logical_location::get_short_name): Drop.
(tree_logical_location::get_name_with_scope): Drop.
(tree_logical_location::get_internal_name): Drop.
(tree_logical_location::get_kind): Drop.
(tree_logical_location::get_name_for_path_output): Drop.
(current_fndecl_logical_location::get_short_name): Drop.
(current_fndecl_logical_location::get_name_with_scope): Drop.
(current_fndecl_logical_location::get_internal_name): Drop.
(current_fndecl_logical_location::get_kind): Drop.
(current_fndecl_logical_location::get_name_for_path_output): Drop.
* tree-logical-location.h (class compiler_logical_location): Drop.
(class tree_logical_location): Drop.
(class current_fndecl_logical_location): Drop.
(class tree_logical_location_manager): New.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic_plugin_test_paths.cc: Update for
changes to simple_diagnostic_path.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
C++11 does not provide a std::make_unique so in
r13-3627-g00d7c8ff16e683 I added a make-unique.h
declaring a ::make_unique.
As of r15-4719-ga9ec1bc06bd3cc we can use C++14, so make-unique.h is no
longer needed: we can use simply use std::make_unique instead.
This patch removes make-unique.h and updates every place using it
to use std::make_unique.
No functional change intended.
gcc/analyzer/ChangeLog:
* access-diagram.cc: Replace uses of ::make_unique with
std::make_unique.
* analyzer.cc: Likewise.
* bounds-checking.cc: Likewise.
* call-details.cc: Likewise.
* call-info.cc: Likewise.
* call-string.cc: Likewise.
* checker-path.cc: Likewise.
* common.h: Drop include of "make-unique.h".
* constraint-manager.cc: Replace uses of ::make_unique with
std::make_unique.
* diagnostic-manager.cc: Likewise.
* engine.cc: Likewise.
* infinite-loop.cc: Likewise.
* infinite-recursion.cc: Likewise.
* kf-analyzer.cc: Likewise.
* kf-lang-cp.cc: Likewise.
* kf.cc: Likewise.
* pending-diagnostic.cc: Likewise.
* program-point.cc: Likewise; drop #include.
* program-state.cc: Likewise.
* ranges.cc: Likewise.
* region-model.cc: Likewise.
* region.cc: Likewise; drop #include.
* sm-fd.cc: Likewise.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-pattern-test.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* sm.cc: Likewise.
* store.cc: Likewise.
* supergraph.cc: Likewise.
* svalue.cc: Likewise; drop #include.
* varargs.cc: Likewise.
gcc/c-family/ChangeLog:
* c-pretty-print.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
gcc/c/ChangeLog:
* c-decl.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
* c-objc-common.cc: Likewise.
* c-parser.cc: Likewise.
gcc/cp/ChangeLog:
* cxx-pretty-print.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
* error.cc: Likewise.
* name-lookup.cc: Likewise.
* parser.cc: Likewise.
gcc/ChangeLog:
* diagnostic-format-json.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
* diagnostic-format-sarif.cc: Likewise.
* diagnostic-format-text.cc: Likewise.
* diagnostic.cc: Likewise.
* dumpfile.cc: Likewise.
* gcc-attribute-urlifier.cc: Likewise.
* gcc-urlifier.cc: Likewise.
* json-parsing.cc: Likewise.
* json.cc: Likewise.
* lazy-diagnostic-path.cc: Likewise.
* libgdiagnostics.cc: Likewise.
* libsarifreplay.cc: Likewise.
* lto-wrapper.cc: Likewise.
* make-unique.h: Delete.
* opts-diagnostic.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
* pretty-print.cc: Likewise.
* text-art/style.cc: Likewise.
* text-art/styled-string.cc: Likewise.
* text-art/table.cc: Likewise.
* text-art/tree-widget.cc: Likewise.
* text-art/widget.cc: Likewise.
* timevar.cc: Likewise.
* toplev.cc: Likewise.
* tree-diagnostic-client-data-hooks.cc: Likewise.
gcc/jit/ChangeLog:
* dummy-frontend.cc: Drop include of "make-unique.h".
Replace uses of ::make_unique with std::make_unique.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.cc: Drop include of
"make-unique.h". Replace uses of ::make_unique with
std::make_unique.
* gcc.dg/plugin/analyzer_gil_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_kernel_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_known_fns_plugin.cc: Likewise.
* gcc.dg/plugin/diagnostic_group_plugin.cc: Likewise.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
No functional change intended.
gcc/analyzer/ChangeLog:
* analyzer.cc: Convert gcall * to gcall & where we know the
pointer must be non-null.
* call-details.cc: Likewise.
* call-details.h: Likewise.
* call-info.cc: Likewise.
* call-info.h: Likewise.
* call-summary.h: Likewise.
* checker-event.cc: Likewise.
* checker-event.h: Likewise.
* common.h: Likewise.
* diagnostic-manager.cc: Likewise.
* engine.cc: Likewise.
* exploded-graph.h: Likewise.
* kf-analyzer.cc: Likewise.
* kf-lang-cp.cc: Likewise.
* kf.cc: Likewise.
* known-function-manager.cc: Likewise.
* program-state.cc: Likewise.
* program-state.h: Likewise.
* region-model.cc: Likewise.
* region-model.h: Likewise.
* sm-fd.cc: Likewise.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* sm.h: Likewise.
* store.cc: Likewise.
* store.h: Likewise.
* supergraph.cc: Likewise.
* supergraph.h: Likewise.
* svalue.h: Likewise.
* varargs.cc: Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_gil_plugin.cc: Convert gcall * to gcall &
where we know the pointer must be non-null.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Modernization; no functional change intended.
gcc/analyzer/ChangeLog:
* access-diagram.cc: Convert enum access_direction to
"enum class".
* bounds-checking.cc: Likewise.
* checker-event.cc: Convert enum event_kind to "enum class".
* checker-event.h: Likewise.
* checker-path.cc: Likewise.
* common.h: Convert enum access_direction to "enum class".
* constraint-manager.cc: Convert enum bound_kind to "enum class".
* constraint-manager.h: Likewise.
* diagnostic-manager.cc: Convert enum event_kind to "enum class".
* engine.cc: Convert enum status to "enum class".
* exploded-graph.h: Likewise.
* infinite-loop.cc: Likewise.
* kf-lang-cp.cc: Convert enum poison_kind to "enum class".
* kf.cc: Likewise.
* region-model-manager.cc: Likewise.
* region-model.cc: Likewise; also for enum access_direction.
* svalue.cc: Likewise.
* svalue.h: Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.cc: Convert
enum poison_kind to "enum class".
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Our headers are a major pain to work with: many require certain other
headers to be included in a particular (undocumented) order in order
to be includable.
Simplify includes in the analyzer by renaming analyzer/analyzer.h to
analyzer/common.h and have it include all the common headers needed
throughout the analyzer, thus encapsulating the rules about e.g. being
able to include "gimple.h" in one place in the analyzer subdirectory.
Doing so also makes it easier to e.g. define INCLUDE_SET in one place,
rather than in many source files.
gcc/analyzer/ChangeLog:
* analyzer.h: Rename to...
* common.h: ...this. Add define of INCLUDE_VECTOR, includes of
"config.h", "system.h", "coretypes.h", "make-unique.h", "tree.h",
"function.h", "basic-block.h", "gimple.h", "options.h",
"bitmap.h", "diagnostic-core.h", and "diagnostic-path.h".
* access-diagram.h: Don't include "analyzer/analyzer.h".
* access-diagram.cc: Reorganize includes to #include
"analyzer/common.h" first, then group by subsystem, dropping
redundant headers.
* analysis-plan.cc: Likewise.
* analyzer-language.cc: Likewise.
* analyzer-pass.cc: Likewise.
* analyzer-selftests.cc: Likewise.
* analyzer.cc: Likewise.
* bounds-checking.cc: Likewise.
* call-details.cc: Likewise.
* call-info.cc: Likewise.
* call-string.cc: Likewise.
* call-summary.cc: Likewise.
* checker-event.cc: Likewise.
* checker-path.cc: Likewise.
* complexity.cc: Likewise.
* constraint-manager.cc: Likewise.
* diagnostic-manager.cc: Likewise.
* engine.cc: Likewise.
* feasible-graph.cc: Likewise.
* infinite-loop.cc: Likewise.
* infinite-recursion.cc: Likewise.
* kf-analyzer.cc: Likewise.
* kf-lang-cp.cc: Likewise.
* kf.cc: Likewise.
* known-function-manager.cc: Likewise.
* pending-diagnostic.cc: Likewise.
* program-point.cc: Likewise.
* program-state.cc: Likewise.
* ranges.cc: Likewise.
* record-layout.cc: Likewise.
* region-model-asm.cc: Likewise.
* region-model-manager.cc: Likewise.
* region-model-reachability.cc: Likewise.
* region-model.cc: Likewise.
* region.cc: Likewise.
* sm-fd.cc: Likewise.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-pattern-test.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* sm.cc: Likewise.
* state-purge.cc: Likewise.
* store.cc: Likewise.
* supergraph.cc: Likewise.
* svalue.cc: Likewise.
* symbol.cc: Likewise.
* trimmed-graph.cc: Likewise.
* varargs.cc: Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.cc: Update for renaming
of analyzer/analyzer.h to analyzer/common.h.
* gcc.dg/plugin/analyzer_gil_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_kernel_plugin.cc: Likewise.
* gcc.dg/plugin/analyzer_known_fns_plugin.cc: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Use __SIZE_TYPE__ for size_t types so that it works for
llp64.
Signed-off-by: Jonathan Yong <10walls@gmail.com>
gcc/testsuite/ChangeLog:
* gcc.dg/graphite/id-15.c: Use __SIZE_TYPE__ instead of
unsigned long.
* gcc.dg/plugin/infoleak-net-ethtool-ioctl.c: ditto.
|
|
Found by dg-lint.
gcc/testsuite/ChangeLog:
* gcc.dg/ipa/pr110377.c: Fix missing trailing " }" in dg-do
directive.
* gcc.dg/plugin/infoleak-1.c: Fix dg-bogus directive.
* gcc.dg/pr101364-1.c: Fix missing trailing " }" in dg-options
directive.
* gcc.dg/pr113207.c: Fix dg-do.
* gcc.dg/sarif-output/include-chain-2.c: Fix ordering of dg-do
and dg-require-effective-target.
* gcc.dg/strub-pr118007.c: Likewise.
* gcc.dg/tanhbysinh.c: Fix missing whitespace after opening
brace and before closing brace in 6 dg-final directives.
* gcc.dg/uninit-pred-3_c.c: Fix missing whitespace after opening
brace in 6 dg-final directive.
* gcc.dg/uninit-pred-3_d.c: Likewise.
* gcc.dg/variable-sized-type-flex-array.c: Fix missing space
between dg-bogus and message in 2 places.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
|
|
libgdiagnostics was written before the fixes for PR other/116613 allowed
a diagnostic_context to have multiple output sinks.
Hence each libgdiagnostics sink had its own diagnostic_context with just
one diagnostic_output_format.
This wart is no longer necessary and makes it harder to move state
into the manager/context; in particular for quoting source code
from the .sarif file (PR sarif-replay/117943).
Simplify, by making libgdiagnostics' implementation more similar to
GCC's implementation, by moving the diagnostic_context from sink into
diagnostic_manager.
Doing so requires generalizing where the
diagnostic_source_printing_options comes from in class
diagnostic_text_output_format: for GCC we use
the instance within the diagnostic_context, whereas for
libgdiagnostics each diagnostic_text_sink has its own instance.
No functional change intended.
gcc/c-family/ChangeLog:
PR sarif-replay/117943
* c-format.cc (selftest::test_type_mismatch_range_labels): Use
dc.m_source_printing.
* c-opts.cc (c_diagnostic_text_finalizer): Use source-printing
options from text_output.
gcc/cp/ChangeLog:
PR sarif-replay/117943
* error.cc (auto_context_line::~auto_context_line): Use
source-printing options from text_output.
gcc/ChangeLog:
PR sarif-replay/117943
* diagnostic-format-text.cc
(diagnostic_text_output_format::append_note): Use source-printing
options from text_output.
(diagnostic_text_output_format::update_printer): Copy
source-printing options from dc.
(default_diagnostic_text_finalizer): Use source-printing
options from text_output.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Add optional diagnostic_source_printing_options param, using
the context's if null.
(diagnostic_text_output_format::get_source_printing_options): New
accessor.
(diagnostic_text_output_format::m_source_printing): New field.
* diagnostic-path.cc (event_range::print): Use source-printing
options from text_output.
(selftest::test_interprocedural_path_1): Use source-printing
options from dc.
* diagnostic-show-locus.cc
(gcc_rich_location::add_location_if_nearby): Likewise.
(diagnostic_context::maybe_show_locus): Add "opts" param
and use in place of m_source_printing. Pass it to source_policy
ctor.
(diagnostic_source_print_policy::diagnostic_source_print_policy):
Add overload taking a const diagnostic_source_printing_options &.
* diagnostic.cc (diagnostic_context::initialize): Pass nullptr
for source options when creating text sink, so that it uses
the dc's options.
(diagnostic_context::dump): Add an "output sinks:" heading and
print "(none)" if there aren't any.
(diagnostic_context::set_output_format): Split out code into...
(diagnostic_context::remove_all_output_sinks): ...this new
function.
* diagnostic.h
(diagnostic_source_print_policy::diagnostic_source_print_policy):
Add overload taking a const diagnostic_source_printing_options &.
(diagnostic_context::maybe_show_locus): Add "opts" param.
(diagnostic_context::remove_all_output_sinks): New decl.
(diagnostic_context::m_source_printing): New field.
(diagnostic_show_locus): Add "opts" param and pass to
maybe_show_locus.
* libgdiagnostics.cc (sink::~sink): Delete.
(sink::begin_group): Delete.
(sink::end_group): Delete.
(sink::emit): Delete.
(sink::m_dc): Drop field.
(diagnostic_text_sink::on_begin_text_diagnostic): Delete.
(diagnostic_text_sink::get_source_printing_options): Use
m_souece_printing.
(diagnostic_text_sink::m_current_logical_loc): Drop field.
(diagnostic_text_sink::m_inner_sink): New field.
(diagnostic_text_sink::m_source_printing): New field.
(diagnostic_manager::diagnostic_manager): Update for changes
to fields. Initialize m_dc.
(diagnostic_manager::~diagnostic_manager): Call diagnostic_finish.
(diagnostic_manager::get_file_cache): Drop.
(diagnostic_manager::get_dc): New accessor.
(diagnostic_manager::begin_group): Reimplement.
(diagnostic_manager::end_group): Reimplement.
(diagnostic_manager::get_prev_diag_logical_loc): New accessor.
(diagnostic_manager::m_dc): New field.
(diagnostic_manager::m_file_cache): Drop field.
(diagnostic_manager::m_edit_context): Convert to a std::unique_ptr
so that object can be constructed after m_dc is initialized.
(diagnostic_manager::m_prev_diag_logical_loc): New field.
(diagnostic_text_sink::diagnostic_text_sink): Reimplement.
(get_color_rule): Delete.
(diagnostic_text_sink::set_colorize): Reimplement.
(diagnostic_text_sink::text_starter): New.
(sarif_sink::sarif_sink): Reimplement.
(diagnostic_manager::write_patch): Update for change to
m_edit_context.
(diagnostic_manager::emit): Update now that each sink has a
corresponding diagnostic_output_format object within m_dc.
gcc/fortran/ChangeLog:
PR sarif-replay/117943
* error.cc (gfc_diagnostic_text_starter): Use source-printing
options from text_output.
gcc/testsuite/ChangeLog:
PR sarif-replay/117943
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc
(custom_diagnostic_text_finalizer): Use source-printing options
from text_output.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc
(xhtml_builder::make_element_for_diagnostic): Use source-printing
options from diagnostic_context.
* gcc.dg/plugin/expensive_selftests_plugin.cc (test_richloc):
Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch is a followup to:
"c++: use diagnostic nesting [PR116253]"
This patch tweaks how text output with experimental-nesting=yes
prints nested diagnostics, by omitting the leading "note: " from
nested notes.
This reduces the amount of visual cruft the user has to ignore when
reading C++ template errors; see the examples in the testsuite.
This doesn't affect the output for users who have not opted-in
to nested diagnostic-printing.
gcc/ChangeLog:
PR other/116253
* diagnostic-format-text.cc (build_prefix): Don't add the
"note: " prefix when showing nested diagnostics.
gcc/testsuite/ChangeLog:
PR other/116253
* g++.dg/concepts/nested-diagnostics-1-truncated.C: Update
expected output.
* g++.dg/concepts/nested-diagnostics-1.C: Likewise.
* g++.dg/concepts/nested-diagnostics-2.C: Likewise.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c:
Likewise.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c:
Likewise.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Change location_t to be a 64-bit integer instead of a 32-bit integer in
libcpp.
Also included in this change are the two other patches in the original
series which depended on this one; I am committing them all at once in case
it needs to be reverted later:
-Support for 64-bit location_t: gimple parts
The size of struct gimple increased by 8 bytes with the change in size of
location_t from 32- to 64-bit; adjust the WORD markings in the comments
accordingly. It seems that most of the WORD markings were off by one already,
probably not having been updated after a previous reduction in the size of a
gimple, so they have become retroactively correct again, and only a couple
needed adjustment actually.
Also add a comment that there is now 32 bits of unused padding available in
struct gimple for 64-bit hosts.
-Support for 64-bit location_t: Remove -flarge-source-files
The option -flarge-source-files became unnecessary with 64-bit location_t
and harms performance compared to the new default setting, so silently
ignore it.
libcpp/ChangeLog:
* include/cpplib.h (struct cpp_token): Adjust comment about the
struct size.
* include/line-map.h (location_t): Change typedef from 32-bit to 64-bit
integer.
(LINE_MAP_MAX_COLUMN_NUMBER): Increase size to be appropriate for
64-bit location_t.
(LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES): Likewise.
(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.
(LINE_MAP_MAX_LOCATION): Likewise.
(MAX_LOCATION_T): Likewise.
(line_map_suggested_range_bits): Likewise.
(struct line_map): Adjust comment about the struct size.
(struct line_map_macro): Likewise.
(struct line_map_ordinary): Likewise. Rearrange fields to optimize
padding.
gcc/testsuite/ChangeLog:
* g++.dg/diagnostic/pr77949.C: Adapt the test for 64-bit location_t,
when the previously expected failure doesn't actually happen.
* g++.dg/modules/loc-prune-4.C: Adjust the expected output for the
64-bit location_t case.
* gcc.dg/plugin/expensive_selftests_plugin.cc: Don't try to test
the maximum supported column number in 64-bit location_t mode.
* gcc.dg/plugin/location_overflow_plugin.cc: Adjust the base_location
so it can effectively test 64-bit location_t.
gcc/ChangeLog:
* gimple.h (struct gphi): Update word marking comments to reflect
the new size of location_t.
(struct gimple): Likewise. Add a comment about padding.
* common.opt: Mark -flarge-source-files as Ignored.
* common.opt.urls: Regenerate.
* doc/invoke.texi: Remove -flarge-source-files.
* toplev.cc (process_options): Remove support for
-flarge-source-files.
|
|
As discussed earlier, we currently clear padding bits even when we
don't have to and that causes pessimization of emitted code,
e.g. for
union U { int a; long b[64]; };
void bar (union U *);
void
foo (void)
{
union U u = { 0 };
bar (&u);
}
we need to clear just u.a, not the whole union, but on the other side
in cases where the standard requires padding bits to be zeroed, like for
C23 {} initializers of aggregates with padding bits, or for C++11 zero
initialization we don't do that.
This patch
a) moves some of the stuff into complete_ctor_at_level_p (but not
all the *p_complete = 0; case, for that it would need to change
so that it passes around the ctor rather than just its type) and
changes the handling of unions
b) introduces a new option, so that users can either get the new
behavior (only what is guaranteed by the standards, the default),
or previous behavior (union padding zero initialization, no such
guarantees in structures) or also a guarantee in structures
c) introduces a new CONSTRUCTOR flag which says that the padding bits
(if any) should be zero initialized (and sets it for now in the C
FE for C23 {} initializers).
Am not sure the CONSTRUCTOR_ZERO_PADDING_BITS flag is really needed
for C23, if there is just empty initializer, I think we already mark
it as incomplete if there are any missing initializers. Maybe with
some designated initializer games, say
void foo () {
struct S { char a; long long b; };
struct T { struct S c; } t = { .c = {}, .c.a = 1, .c.b = 2 };
...
}
Is this supposed to initialize padding bits in C23 and then the .c.a = 1
and .c.b = 2 stores preserve those padding bits, so is that supposed
to be different from struct T t2 = { .c = { 1, 2 } };
? What about just struct T t3 = { .c.a = 1, .c.b = 2 }; ?
And I haven't touched the C++ FE for the flag, because I'm afraid I'm lost
on where exactly is zero-initialization done (vs. other types of
initialization) and where is e.g. zero-initialization of a temporary then
(member-wise) copied.
Say
struct S { char a; long long b; };
struct T { constexpr T (int a, int b) : c () { c.a = a; c.b = b; } S c; };
void bar (T *);
void
foo ()
{
T t (1, 2);
bar (&t);
}
Is the c () value-initialization of t.c followed by c.a and c.b updates
which preserve the zero initialized padding bits? Or is there some
copy construction involved which does member-wise copying and makes the
padding bits undefined?
Looking at (older) clang++ with -O2, it initializes also the padding bits
when c () is used and doesn't with c {}.
For GCC, note that there is that optimization from Alex to zero padding bits
for optimization purposes for small aggregates, so either one needs to look
at -O0 -fdump-tree-gimple dumps, or use larger structures which aren't
optimized that way.
2024-11-28 Jakub Jelinek <jakub@redhat.com>
PR c++/116416
gcc/
* flag-types.h (enum zero_init_padding_bits_kind): New type.
* tree.h (CONSTRUCTOR_ZERO_PADDING_BITS): Define.
* common.opt (fzero-init-padding-bits=): New option.
* expr.cc (categorize_ctor_elements_1): Handle
CONSTRUCTOR_ZERO_PADDING_BITS or
flag_zero_init_padding_bits == ZERO_INIT_PADDING_BITS_ALL. Fix
up *p_complete = -1; setting for unions.
(complete_ctor_at_level_p): Handle unions differently for
flag_zero_init_padding_bits == ZERO_INIT_PADDING_BITS_STANDARD.
* gimple-fold.cc (type_has_padding_at_level_p): Fix up UNION_TYPE
handling, return also true for UNION_TYPE with no FIELD_DECLs
and non-zero size, handle QUAL_UNION_TYPE like UNION_TYPE.
* doc/invoke.texi (-fzero-init-padding-bits=@var{value}): Document.
gcc/c/
* c-parser.cc (c_parser_braced_init): Set CONSTRUCTOR_ZERO_PADDING_BITS
for flag_isoc23 empty initializers.
* c-typeck.cc (constructor_zero_padding_bits): New variable.
(struct constructor_stack): Add zero_padding_bits member.
(really_start_incremental_init): Save and clear
constructor_zero_padding_bits.
(push_init_level): Save constructor_zero_padding_bits. Or into it
CONSTRUCTOR_ZERO_PADDING_BITS from previous value if implicit.
(pop_init_level): Set CONSTRUCTOR_ZERO_PADDING_BITS if
constructor_zero_padding_bits and restore
constructor_zero_padding_bits.
gcc/testsuite/
* gcc.dg/plugin/infoleak-1.c (test_union_2b, test_union_4b): Expect
diagnostics.
* gcc.dg/c23-empty-init-5.c: New test.
* gcc.dg/gnu11-empty-init-1.c: New test.
* gcc.dg/gnu11-empty-init-2.c: New test.
* gcc.dg/gnu11-empty-init-3.c: New test.
* gcc.dg/gnu11-empty-init-4.c: New test.
|
|
In r12-6650-g5c69acb32329d4 we updated our sources from .c to .cc
since for some time GCC has been implemented in C++, not C.
GCC plugins are also implemented in C++, not C, but the plugins
in our testsuite still have .c extensions.
Rename the plugin implementation files in the testsuite from .c to .cc,
for consistency with GCC's implementation files (as opposed to .C,
which is used in C++ parts of the testsuite).
Don't rename the files that the plugins are tested *on*.
gcc/testsuite/ChangeLog:
* g++.dg/plugin/plugin.exp (plugin_test_list): Update for renaming
of all plugin implementation files from .c to .cc.
* g++.dg/plugin/attribute_plugin.c: Rename to...
* g++.dg/plugin/attribute_plugin.cc: ...this.
* g++.dg/plugin/comment_plugin.c: Rename to...
* g++.dg/plugin/comment_plugin.cc: ...this.
* g++.dg/plugin/decl_plugin.c: Rename to...
* g++.dg/plugin/decl_plugin.cc: ...this.
* g++.dg/plugin/def_plugin.c: Rename to...
* g++.dg/plugin/def_plugin.cc: ...this.
* g++.dg/plugin/dumb_plugin.c: Rename to...
* g++.dg/plugin/dumb_plugin.cc: ...this.
* g++.dg/plugin/header_plugin.c: Rename to...
* g++.dg/plugin/header_plugin.cc: ...this.
* g++.dg/plugin/pragma_plugin.c: Rename to...
* g++.dg/plugin/pragma_plugin.cc: ...this.
* g++.dg/plugin/selfassign.c: Rename to...
* g++.dg/plugin/selfassign.cc: ...this.
* g++.dg/plugin/show_template_tree_color_plugin.c: Rename to...
* g++.dg/plugin/show_template_tree_color_plugin.cc: ...this.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Update for renaming
of all plugin implementation files from .c to .cc.
* gcc.dg/plugin/analyzer_cpython_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_cpython_plugin.cc: ...this.
* gcc.dg/plugin/analyzer_gil_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_gil_plugin.cc: ...this.
* gcc.dg/plugin/analyzer_kernel_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_kernel_plugin.cc: ...this.
* gcc.dg/plugin/analyzer_known_fns_plugin.c: Rename to...
* gcc.dg/plugin/analyzer_known_fns_plugin.cc: ...this.
* gcc.dg/plugin/crash_test_plugin.c: Rename to...
* gcc.dg/plugin/crash_test_plugin.cc: ...this.
* gcc.dg/plugin/diagnostic_group_plugin.c: Rename to...
* gcc.dg/plugin/diagnostic_group_plugin.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_show_trees.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_show_trees.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_inlining.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_inlining.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_metadata.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_metadata.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_nesting.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_nesting.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_paths.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.c: Rename
* gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc: ..to
this.
* gcc.dg/plugin/diagnostic_plugin_test_text_art.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_text_art.cc: ...this.
* gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c:
Rename to...
* gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc:
...this.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Rename to...
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.cc: ...this.
* gcc.dg/plugin/dump_plugin.c: Rename to...
* gcc.dg/plugin/dump_plugin.cc: ...this.
* gcc.dg/plugin/expensive_selftests_plugin.c: Rename to...
* gcc.dg/plugin/expensive_selftests_plugin.cc: ...this.
* gcc.dg/plugin/finish_unit_plugin.c: Rename to...
* gcc.dg/plugin/finish_unit_plugin.cc: ...this.
* gcc.dg/plugin/ggcplug.c: Rename to...
* gcc.dg/plugin/ggcplug.cc: ...this.
* gcc.dg/plugin/location_overflow_plugin.c: Rename to...
* gcc.dg/plugin/location_overflow_plugin.cc: ...this.
* gcc.dg/plugin/must_tail_call_plugin.c: Rename to...
* gcc.dg/plugin/must_tail_call_plugin.cc: ...this.
* gcc.dg/plugin/one_time_plugin.c: Rename to...
* gcc.dg/plugin/one_time_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-01_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-01_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-02_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-02_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-03_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-03_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-04_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-04_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-05_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-05_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-06_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-06_plugin.cc: ...this.
* gcc.dg/plugin/poly-int-07_plugin.c: Rename to...
* gcc.dg/plugin/poly-int-07_plugin.cc: ...this.
* gcc.dg/plugin/selfassign.c: Rename to...
* gcc.dg/plugin/selfassign.cc: ...this.
* gcc.dg/plugin/start_unit_plugin.c: Rename to...
* gcc.dg/plugin/start_unit_plugin.cc: ...this.
* gcc.dg/plugin/wide-int_plugin.c: Rename to...
* gcc.dg/plugin/wide-int_plugin.cc: ...this.
* obj-c++.dg/plugin/plugin.exp: Update for renaming of plugin
implementation file from .c to .cc.
* objc.dg/plugin/plugin.exp: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Previously the diagnostic subsystem supported a one-deep
hierarchy via auto_diagnostic_group, for associating
notes with the warning/error they annotate; this only
affects SARIF output, not text output.
This patch adds support to the diagnostics subsystem for
capturing arbitrarily deep nesting structure within
diagnostic messages.
This patch:
* adds the ability to express nesting internally when
building diagnostics
* captures the nesting in SARIF output in the form documented
in SG15's P3358R0 ("SARIF for Structured Diagnostics") via
a "nestingLevel" property
* adds a new experimental mode to text output to see the
hierarchy, via:
-fdiagnostics-set-output=text:experimental-nesting=yes
* adds test coverage via a plugin, which with the above
option emits:
• note: child 0
• note: grandchild 0 0
• note: grandchild 0 1
• note: grandchild 0 2
• note: child 1
• note: grandchild 1 0
• note: grandchild 1 1
• note: grandchild 1 2
• note: child 2
• note: grandchild 2 0
• note: grandchild 2 1
• note: grandchild 2 2
using '*' rather than '•' if the text_art::theme is ascii-only.
My hope is to eventually:
(a) use this to improve C++'s template diagnostics
(b) remove the "experimental" caveat from the the text output mode
but this patch doesn't touch the C++ frontend, leaving both of these
to followup work.
gcc/c-family/ChangeLog:
PR other/116253
* c-opts.cc (c_diagnostic_text_finalizer): Use
text_output.build_indent_prefix for prefix to
diagnostic_show_locus.
gcc/ChangeLog:
PR other/116253
* diagnostic-core.h (class auto_diagnostic_nesting_level): New.
* diagnostic-format-sarif.cc (class sarif_builder): Update leading
comment re nesting of diagnostics.
(sarif_result::on_nested_diagnostic): Add nestingLevel property.
* diagnostic-format-text.cc (on_report_diagnostic): If we're
showing nested diagnostics, then print changes of location on a
new line, indented, and update m_last_location.
(diagnostic_text_output_format::build_prefix): If m_show_nesting,
then potentially add indentation and a bullet point.
(get_bullet_point_unichar): New.
(use_unicode_p): New.
(diagnostic_text_output_format::build_indent_prefix): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Initialize m_show_nesting and m_show_nesting_levels.
(diagnostic_text_output_format::build_indent_prefix): New decl.
(diagnostic_text_output_format::show_nesting_p): New accessor
(diagnostic_text_output_format::show_locations_in_nesting_p):
Likewise.
(diagnostic_text_output_format::set_show_nesting): New.
(diagnostic_text_output_format::set_show_locations_in_nesting):
New.
(diagnostic_text_output_format::set_show_nesting_levels): New.
(diagnostic_text_output_format::m_show_nesting): New field.
(diagnostic_text_output_format::m_show_locations_in_nesting): New
field.
(diagnostic_text_output_format::m_show_nesting_levels): New field.
* diagnostic-global-context.cc
(auto_diagnostic_nesting_level::auto_diagnostic_nesting_level):
New.
(auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level):
New.
* diagnostic-show-locus.cc (layout_printer::print): Temporarily
set DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE.
* diagnostic.cc (diagnostic_context::initialize): Update for
renaming of m_nesting_depth to m_group_nesting_depth and
initialize m_diagnostic_nesting_level.
(diagnostic_context::finish): Update for renaming of
m_nesting_depth to m_group_nesting_depth.
(diagnostic_context::report_diagnostic): Likewise.
(diagnostic_context::begin_group): Likewise.
(diagnostic_context::end_group): Likewise.
(diagnostic_context::push_nesting_level): New.
(diagnostic_context::pop_nesting_level): New.
(diagnostic_context::set_diagnostic_buffer): Update for renaming
of m_nesting_depth to m_group_nesting_depth. Assert that we don't
have nested diagnostics.
* diagnostic.h (diagnostic_context::push_nesting_level): New decl.
(diagnostic_context::pop_nesting_level): New decl.
(diagnostic_context::get_diagnostic_nesting_level): New accessor.
(diagnostic_context::build_indent_prefix): New decl.
(diagnostic_context::m_diagnostic_groups): Rename m_nesting_depth
to m_group_nesting_depth and add field m_diagnostic_nesting_level.
* doc/invoke.texi (fdiagnostics-add-output): Add note about
"experimental" schemes, keys, and values. Add keys
"experimental-nesting", "experimental-nesting-show-locations",
and "experimental-nesting-show-levels" to text scheme.
* opts-diagnostic.cc (text_scheme_handler::make_sink): Add keys
"experimental-nesting", "experimental-nesting-show-locations",
and "experimental-nesting-show-levels".
gcc/testsuite/ChangeLog:
PR other/116253
* gcc.dg/plugin/diagnostic-test-nesting-sarif.c: New test.
* gcc.dg/plugin/diagnostic-test-nesting-sarif.py: New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c:
New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c:
New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: New test.
* gcc.dg/plugin/diagnostic-test-nesting-text-plain.c: New test.
* gcc.dg/plugin/diagnostic_plugin_test_nesting.c: New test plugin.
* gcc.dg/plugin/plugin.exp: Add the above.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch generalizes diagnostic_context so that rather than having
a single output format, it has a vector of zero or more.
It adds new two options:
-fdiagnostics-add-output=DIAGNOSTICS-OUTPUT-SPEC
-fdiagnostics-set-output=DIAGNOSTICS-OUTPUT-SPEC
which both take a new configuration syntax of the form SCHEME ("text" or
"sarif"), optionally followed by ":" and one or more KEY=VALUE pairs,
in this form:
<SCHEME>
<SCHEME>:<KEY>=<VALUE>
<SCHEME>:<KEY>=<VALUE>,<KEY2>=<VALUE2>
...etc
where each SCHEME supports some set of keys. For example, it's now
possible to use:
-fdiagnostics-add-output=sarif:version=2.1,file=foo.2.1.sarif \
-fdiagnostics-add-output=sarif:version=2.2-prerelease,file=foo.2.2.sarif
to add a pair of outputs, each writing to a different file, using
versions 2.1 and 2.2 of the SARIF standard respectively, whilst also
emitting the classic text form of the diagnostics to stderr.
I hope the new syntax gives us room to potentially add new kinds of
output sink in the future (e.g. RPC notifications), and to add new
key/value pairs as needed by the different sinks.
Implementation-wise, the diagnostic_context's m_printer which previously
was used directly by the single output format now becomes a "reference
printer", created by the client (such as the frontend), with defaults
modified by command-line options. Each of the multiple output sinks has
its own pretty_printer instance, created by cloning the context's
reference printer.
gcc/ChangeLog:
PR other/116613
* Makefile.in (OBJS-libcommon-target): Add opts-diagnostic.o.
* common.opt (fdiagnostics-add-output=): New.
(fdiagnostics-set-output=): New.
(diagnostics_output_format): Drop sarif-file-2.2-prerelease from
enum.
* common.opt.urls: Regenerate.
* diagnostic-buffer.h (diagnostic_buffer::~diagnostic_buffer): New.
(diagnostic_buffer::ensure_per_format_buffer): Rename to...
(diagnostic_buffer::ensure_per_format_buffers): ...this.
(diagnostic_buffer::m_per_format_buffer): Replace with...
(diagnostic_buffer::m_per_format_buffers): ...this, updating type.
* diagnostic-format-json.cc (json_output_format::update_printer):
New.
(json_output_format::follows_reference_printer_p): New.
(diagnostic_output_format_init_json): Drop redundant call to
set_path_format, as this is not a text output format.
* diagnostic-format-sarif.cc: Include "diagnostic-format-text.h".
(sarif_builder::set_printer): New.
(sarif_builder::sarif_builder): Add "printer" param and use it for
m_printer.
(sarif_builder::make_location_object::escape_nonascii_renderer::render):
Rather than using dc.m_printer, create a
diagnostic_text_output_format instance and use its printer.
(sarif_output_format::follows_reference_printer_p): New.
(sarif_output_format::update_printer): New.
(sarif_output_format::sarif_output_format): Pass in correct
printer to m_builder's ctor.
(diagnostic_output_format_init_sarif): Drop redundant call to
set_path_format, as this is not a text output format. Replace
calls to pp_show_color and set_token_printer with call to
update_printer. Drop redundant call to set_show_highlight_colors,
as this printer does not show colors.
(diagnostic_output_format_init_sarif_file): Split out file opening
into...
(diagnostic_output_format_open_sarif_file): ...this new function.
(make_sarif_sink): New.
(selftest::test_make_location_object): Provide a pp for the
builder.
* diagnostic-format-sarif.h
(diagnostic_output_format_open_sarif_file): New decl.
(make_sarif_sink): New decl.
* diagnostic-format-text.cc (diagnostic_text_output_format::dump):
Dump sm_follows_reference_printer.
(diagnostic_text_output_format::on_report_verbatim): New.
(diagnostic_text_output_format::follows_reference_printer_p): New.
(diagnostic_text_output_format::update_printer): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Add optional "follows_reference_printer" param.
(diagnostic_text_output_format::on_report_verbatim): New decl.
(diagnostic_text_output_format::after_diagnostic): Drop "final".
(diagnostic_text_output_format::follows_reference_printer_p): New
decl.
(class diagnostic_text_output_format): Convert private members to
protected.
(diagnostic_text_output_format::m_follows_reference_printer): New
field.
* diagnostic-format.h
(diagnostic_output_format::on_report_verbatim): New vfunc.
(diagnostic_output_format::follows_reference_printer_p): New vfunc.
(diagnostic_output_format::update_printer): New vfunc.
(diagnostic_output_format::get_printer): Use m_printer rather than
a printer from m_context.
(diagnostic_output_format::diagnostic_output_format): Initialize
m_printer by cloning the context's printer.
(diagnostic_output_format::m_printer): New field.
* diagnostic-global-context.cc (verbatim): Reimplement in terms of
global_dc->report_verbatim, moving existing implementation to
diagnostic_text_output_format::on_report_verbatim.
(fnotice): Support multiple output sinks by using a new
global_dc->supports_fnotice_on_stderr_p.
* diagnostic-output-file.h
(diagnostic_output_file::diagnostic_output_file): New default ctor.
(diagnostic_output_file::operator=): Implement move assignment.
* diagnostic-path.cc (selftest::test_interprocedural_path_1): Pass
false for new param of text_output's ctor.
* diagnostic-show-locus.cc
(selftest::test_layout_x_offset_display_utf8): Use reference
printer.
(selftest::test_layout_x_offset_display_tab): Likewise.
(selftest::test_one_liner_fixit_remove): Likewise.
* diagnostic.cc: Include "pretty-print-urlifier.h".
(diagnostic_set_caret_max_width): Update for global_dc's m_printer
becoming reference printer.
(diagnostic_context::initialize): Update for m_printer becoming
m_reference_printer. Use ::make_unique to create it. Update for
m_output_format becoming m_output_sinks.
(diagnostic_context::color_init): Update the reference printer,
then update the printers for any output sinks that follow it.
(diagnostic_context::urls_init): Likewise.
(diagnostic_context::finish): Update comment. Update for
m_output_format becoming m_output_sinks. Update for m_printer
becoming m_reference_printer and use "delete" on it rather than
XDELETE.
(diagnostic_context::dump): Update for m_printer becoming
reference printer, and for multiple output sinks.
(diagnostic_context::set_output_format): Reimplement for
supporting multiple output sinks.
(diagnostic_context::get_output_format): Likewise.
(diagnostic_context::add_sink): New.
(diagnostic_context::supports_fnotice_on_stderr_p): New.
(diagnostic_context::set_pretty_printer): New.
(diagnostic_context::refresh_output_sinks): New.
(diagnostic_context::set_format_decoder): New.
(diagnostic_context::set_show_highlight_colors): New.
(diagnostic_context::set_prefixing_rule): New.
(diagnostic_context::report_diagnostic): Update to support
multiple output sinks.
(diagnostic_context::report_verbatim): New.
(diagnostic_context::emit_diagram): Update to support multiple
output sinks.
(diagnostic_context::error_recursion): Update to use
m_reference_printer.
(fancy_abort): Likewise.
(diagnostic_context::end_group): Update to support multiple
output sinks.
(diagnostic_output_format::dump): Implement.
(diagnostic_output_format::on_report_verbatim): Likewise.
(diagnostic_output_format_init): Drop
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE.
(diagnostic_context::set_diagnostic_buffer): Reimplement to
support multiple output sinks.
(diagnostic_context::clear_diagnostic_buffer): Likewise.
(diagnostic_context::flush_diagnostic_buffer): Likewise.
(diagnostic_buffer::diagnostic_buffer): Initialize
m_per_format_buffers.
(diagnostic_buffer::~diagnostic_buffer): New dtor.
(diagnostic_buffer::dump): Reimplement to support multiple output
sinks.
(diagnostic_buffer::empty_p): Likewise.
(diagnostic_buffer::move_to): Likewise.
(diagnostic_buffer::ensure_per_format_buffer): Likewise, renaming
to...
(diagnostic_buffer::ensure_per_format_buffers): ...this.
* diagnostic.h
(DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE): Delete.
(class diagnostic_context): Add friend class diagnostic_buffer.
(diagnostic_context::set_pretty_printer): New decl.
(diagnostic_context::refresh_output_sinks): New decl.
(diagnostic_context::report_verbatim): New decl.
(diagnostic_context::get_output_format): Drop.
(diagnostic_context::set_show_highlight_colors): Drop body.
(diagnostic_context::set_format_decoder): New decl.
(diagnostic_context::set_prefixing_rule): New decl.
(diagnostic_context::clone_printer): Reimplement.
(diagnostic_context::get_reference_printer): New accessor.
(diagnostic_context::add_sink): New decl.
(diagnostic_context::supports_fnotice_on_stderr_p): New decl.
(diagnostic_context::m_printer): Replace with...
(diagnostic_context::m_reference_printer): ...this, and make
private.
(diagnostic_context::m_output_format): Replace with...
(diagnostic_context::m_output_sinks): ...this.
(diagnostic_format_decoder): Delete.
(diagnostic_prefixing_rule): Delete.
(diagnostic_ready_p): Delete.
* doc/invoke.texi: Document -fdiagnostics-add-output= and
-fdiagnostics-set-output=.
* gcc.cc: Include "opts-diagnostic.h".
(driver_handle_option): Handle cases OPT_fdiagnostics_add_output_
and OPT_fdiagnostics_set_output_.
* opts-diagnostic.cc: New file.
* opts-diagnostic.h (handle_OPT_fdiagnostics_add_output_): New decl.
(handle_OPT_fdiagnostics_set_output_): New decl.
* opts-global.cc (init_options_once): Update for global_dc's
m_printer becoming reference printer. Call
global_dc->refresh_output_sinks.
* opts.cc (common_handle_option): Replace use of
diagnostic_prefixing_rule with dc->set_prefixing_rule. Handle
cases OPT_fdiagnostics_add_output_ and
OPT_fdiagnostics_set_output_. Update for m_printer becoming
reference printer.
* selftest-diagnostic.cc
(selftest::test_diagnostic_context::test_diagnostic_context):
Update for m_printer becoming reference printer.
(test_diagnostic_context::test_show_locus): Likewise.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::opts_diagnostic_cc_tests.
* selftest.h (selftest::opts_diagnostic_cc_tests): New decl.
* simple-diagnostic-path.cc
(selftest::simple_diagnostic_path_cc_tests): Use reference
printer.
* toplev.cc (announce_function): Update for global_dc's m_printer
becoming reference printer.
(toplev::main): Likewise.
* tree-diagnostic.cc (tree_diagnostics_defaults): Replace use of
diagnostic_format_decoder with context->set_format_decoder.
* tree-diagnostic.h
(tree_dump_pretty_printer::tree_dump_pretty_printer): Update for
global_dc's m_printer becoming reference printer.
* tree.cc (escaped_string::escape): Likewise.
(selftest::test_escaped_strings): Likewise.
gcc/ada/ChangeLog:
PR other/116613
* gcc-interface/misc.cc (internal_error_function): Update for
m_printer becoming reference printer.
gcc/analyzer/ChangeLog:
PR other/116613
* analyzer-language.cc (on_finish_translation_unit): Update for
m_printer becoming reference printer.
* engine.cc (run_checkers): Likewise.
* program-point.cc (function_point::print_source_line): Likewise.
gcc/c-family/ChangeLog:
PR other/116613
* c-format.cc (selftest::test_type_mismatch_range_labels): Update
for m_printer becoming reference printer.
(selftest::test_type_mismatch_range_labels): Likewise.
gcc/c/ChangeLog:
PR other/116613
* c-objc-common.cc: Include "make-unique.h".
(c_initialize_diagnostics): Use unique_ptr for pretty_printer.
Use context->set_format_decoder.
gcc/cp/ChangeLog:
PR other/116613
* error.cc (cxx_initialize_diagnostics): Use unique_ptr for
pretty_printer. Use context->set_format_decoder.
* module.cc (noisy_p): Update for global_dc's m_printer becoming
reference printer.
gcc/d/ChangeLog:
PR other/116613
* d-diagnostic.cc (d_diagnostic_report_diagnostic): Update for
m_printer becoming reference printer.
gcc/fortran/ChangeLog:
PR other/116613
* error.cc (gfc_diagnostic_build_kind_prefix): Update for
global_dc's m_printer becoming reference printer.
(gfc_diagnostics_init): Replace usage of diagnostic_format_decoder
with global_dc->set_format_decoder.
gcc/jit/ChangeLog:
PR other/116613
* dummy-frontend.cc: Include "make-unique.h".
(class jit_diagnostic_listener): New.
(jit_begin_diagnostic): Update comment.
(jit_end_diagnostic): Drop call to add_diagnostic.
(jit_langhook_init): Set the output format to a new
jit_diagnostic_listener.
* jit-playback.cc (playback::context::add_diagnostic): Add "text"
param and use that rather than trying to get the text from a
pretty_printer.
* jit-playback.h (playback::context::add_diagnostic): Add "text"
param.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/analyzer_cpython_plugin.c (dump_refcnt_info):
Update for global_dc's m_printer becoming reference printer.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2.2.c: Replace usage
of -fdiagnostics-format=sarif-file-2.2-prerelease with
-fdiagnostics-set-output=sarif:version=2.2-prerelease.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: Update for
global_dc's m_printer becoming reference printer.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Update for
changes to output formats.
* gcc.dg/plugin/expensive_selftests_plugin.c: Update for
global_dc's m_printer becoming reference printer.
* gcc.dg/sarif-output/add-output-sarif-defaults.c: New test.
* gcc.dg/sarif-output/bad-binary-op.c: New test.
* gcc.dg/sarif-output/bad-binary-op.py: New support script.
* gcc.dg/sarif-output/multiple-outputs.c: New test.
* gcc.dg/sarif-output/multiple-outputs.py: New support script.
* lib/scansarif.exp (verify-sarif-file): Add an optional second
argument specifying the expected filename of the .sarif file.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Previously, various places in the analyzer generated message strings
by cloning the diagnostic_context's pretty_printer, printing to that
pretty_printer's buffer, and then returning a copy of the buffer
contents.
This implicit use of a particular pretty printer doesn't work well for
the "multiple diagnostic output formats" case (PR other/116613), such as
differences in colorization, or in how phase 3 of formatting works.
Hence as enabling work towards that, the following patch reworks the
various functions returning a label_text string in favor of functions
that print to a specific pretty_printer, such as diagnotic_event's
"get_desc" vfunc, which becomes "print_desc". This makes the particular
pretty_printer in use explicit in each case.
Previously, the various pending_diagnostic::describe_* vfuncs returned a
label_text, with the return of an empty string signifying that no
description could be generated. With this patch, these vfuncs gain a
"pretty_printer &" param and a bool return value and now either print to
the pretty_printer and return true, or return false to signify the
"no description available" case.
No functional change intended.
gcc/analyzer/ChangeLog:
PR other/116613
* bounds-checking.cc
(concrete_buffer_overflow::describe_final_event): Convert return
type from label_text to bool. Add "pp" param and either print to
it and return true, or return false.
(concrete_buffer_overflow::describe_final_event_as_bytes): Convert
to print to a pp rather than returning a label_text.
(concrete_buffer_overflow::describe_final_event_as_bits):
Likewise.
(class concrete_buffer_over_read): Analogous changes to above.
(class concrete_buffer_underwrite): Likewise.
(class concrete_buffer_under_read): Likewise.
(class symbolic_buffer_overflow): Likewise.
(class symbolic_buffer_over_read): Likewise.
* call-details.cc (class overlapping_buffers): Likewise.
* call-info.cc (call_info::print): Reimplement.
(class call_info::add_events_to_path::call_event): Convert
"get_desc" vfunc to "print_desc", dropping return type, adding
"pp" param, and printing to it.
(class succeed_or_fail_call_info): Likewise.
* call-info.h (class call_info): Likewise.
(class succeed_or_fail_call_info): Likewise.
* checker-event.cc (checker_event::dump): Reimplement.
(checker_event::prepare_for_emission): Update for change from
get_desc to print_desc.
(debug_event::get_desc): Convert to...
(debug_event::print_desc): ...this.
(precanned_custom_event::get_desc): Convert to...
(precanned_custom_event::print_desc): ...this.
(statement_event::get_desc): Convert to...
(statement_event::print_desc): ...this.
(region_creation_event_memory_space::get_desc): Convert to...
(region_creation_event_memory_space::print_desc): ...this.
(region_creation_event_capacity::get_desc): Convert to...
(region_creation_event_capacity::print_desc): ...this.
(region_creation_event_allocation_size::get_desc): Convert to...
(region_creation_event_allocation_size::print_desc): ...this.
(region_creation_event_debug::get_desc): Convert to...
(region_creation_event_debug::print_desc): ...this.
(function_entry_event::get_desc): Convert to...
(function_entry_event::print_desc): ...this.
(state_change_event::get_desc): Convert to...
(state_change_event::print_desc): ...this.
(state_change_event::get_meaning): Update for change to
pending_diagnostic::get_meaning_for_state_change.
(superedge_event::should_filter_p): Convert from usage of get_desc
to print_desc.
(start_cfg_edge_event::get_desc): Convert to...
(start_cfg_edge_event::print_desc): ...this.
(call_event::get_desc): Convert to...
(call_event::print_desc): ...this.
(return_event::get_desc): Convert to...
(return_event::print_desc): ...this.
(start_consolidated_cfg_edges_event::get_desc): Convert to...
(start_consolidated_cfg_edges_event::print_desc): ...this.
(inlined_call_event::get_desc): Convert to...
(inlined_call_event::print_desc): ...this.
(setjmp_event::get_desc): Convert to...
(setjmp_event::print_desc): ...this.
(rewind_from_longjmp_event::get_desc): Convert to...
(rewind_from_longjmp_event::print_desc): ...this.
(rewind_to_setjmp_event::get_desc): Convert to...
(rewind_to_setjmp_event::print_desc): ...this.
(warning_event::get_desc): Convert to...
(warning_event::print_desc): ...this.
* checker-event.h: Convert the various "get_desc" vfunc decls to
"print_desc".
* checker-path.cc (checker_path::dump): Convert to usage of
checker_event::print_desc.
(checker_path::debug): Convert to debug form of
checker_event::get_desc.
* diagnostic-manager.cc
(diagnostic_manager::prune_interproc_events): Likewise.
(diagnostic_manager::prune_system_headers): Likewise.
* engine.cc (call_summary_edge_info::get_desc): Convert to...
(call_summary_edge_info::print_desc): ...this.
(stale_jmp_buf::describe_final_event): Update for change to
this vfunc.
(tainted_args_function_custom_event::get_desc): Convert to...
(tainted_args_function_custom_event::print_desc): ...this.
(tainted_args_field_custom_event::get_desc): Convert to...
(tainted_args_field_custom_event::print_desc): ...this.
(tainted_args_callback_custom_event::get_desc): Convert to...
(tainted_args_callback_custom_event::print_desc): ...this.
(jump_through_null::describe_final_event): Update for change to
this vfunc.
* infinite-loop.cc (perpetual_start_cfg_edge_event::get_desc):
Convert to...
(perpetual_start_cfg_edge_event::print_desc): ...this.
(looping_back_event::get_desc): Convert to...
(looping_back_event::print_desc): ...this.
(looping_back_event::describe_final_event): Update for change to
this vfunc.
* infinite-recursion.cc (class infinite_recursion_diagnostic):
Update for changes to pending_diagnostic.
* kf.cc (class putenv_of_auto_var): Likewise.
(kf_realloc::impl_call_post): Update for changes to call_info.
(kf_strchr::impl_call_post): Likewise.
(kf_strncpy::impl_call_post): Likewise.
(kf_strstr::impl_call_post): Likewise.
(class kf_strtok::undefined_behavior): Update for changes to
pending_diagnostic.
(class strtok_call_info): Update for changes to call_info.
* pending-diagnostic.cc (evdesc::event_desc::formatted_print):
Delete.
* pending-diagnostic.h (struct event_desc): Delete.
(struct state_change): Drop event_desc base class.
(struct call_with_state): Likewise.
(struct return_of_state): Likewise.
(struct final_event): Likewise.
(pending_event::describe_state_change): Convert return
type from label_text to bool. Add "pp" param and either print to
it and return true, or return false. Do the latter for the base
class implementation.
(pending_event::describe_call_with_state): Likewise.
(pending_event::describe_return_of_state): Likewise.
(pending_event::describe_final_event): Likewise.
* region-model.cc
(poisoned_value_diagnostic::describe_final_event): Update for
change to this vfunc.
(shift_count_negative_diagnostic::describe_final_event): Likewise.
(shift_count_overflow_diagnostic::describe_final_event): Likewise.
(ptrdiff_region_creation_event::get_desc): Convert to...
(ptrdiff_region_creation_event::print_desc): ...this.
(undefined_ptrdiff_diagnostic::describe_final_event): Update for
change to this vfunc.
(write_to_const_diagnostic::describe_final_event): Likewise.
(write_to_string_literal_diagnostic::describe_final_event):
Likewise.
(dubious_allocation_size::describe_final_event): Likewise.
(null_terminator_check_event::get_desc): Convert to...
(null_terminator_check_event::print_desc): ...this.
(float_as_size_arg::describe_final_event): Update for change to
this vfunc.
(exposure_through_uninit_copy::describe_final_event): Likewise.
* sm-fd.cc: Include "diagnostic-core.h". Update throughout for
changes to pending_diagnostic vfuncs.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* varargs.cc: Likewise.
gcc/ChangeLog:
PR other/116613
* diagnostic-format-json.cc (make_json_for_path): Add "ref_pp"
param and use when obtaining event descriptions.
(json_output_format::on_report_diagnostic): Pass this format's
printer as the above.
* diagnostic-format-sarif.cc
(sarif_builder::make_location_object): Clone this format's printer
and use it to obtain the text of the message.
* diagnostic-path.cc: Include "pretty-print-markup.h".
(diagnostic_event::get_desc): New.
(path_label::get_text): Update for changes to diagnostic_event.
(event_range::print): Likewise.
(class element_event_desc): New.
(diagnostic_text_output_format::print_path): Update for changes to
diagnostic_event.
* diagnostic-path.h (diagnostic_event::get_desc): Replace with...
(diagnostic_event::print_desc): ...this.
(diagnostic_event::get_desc): Add this back for debugging, without
the bool param.
* pretty-print.cc (pp_printf_n): New.
* pretty-print.h (pp_printf_n): New decl.
* selftest-diagnostic-path.h (test_diagnostic_event::get_desc):
Convert to...
(test_diagnostic_event::print_desc): ...this.
* simple-diagnostic-path.cc (simple_diagnostic_event::print_desc):
New.
(selftest::test_intraprocedural_path): Use debug form of get_desc.
* simple-diagnostic-path.h (simple_diagnostic_event::get_desc):
Convert to...
(simple_diagnostic_event::print_desc): ...this, moving
implementation to test_diagnostic_event.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/analyzer_cpython_plugin.c: Convert call outcomes
from "get_desc" to print_desc".
* gcc.dg/plugin/analyzer_gil_plugin.c: Update for changes to
pending_diagnostic vfuncs.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
My forthcoming patches for PR other/116613 make much more use of
cloning of pretty_printers than before, so it makes sense as a
preliminary patch for the result of pretty_printer::clone to be a
std::unique_ptr, rather than add more manual uses of "delete".
On doing so, I noticed various other places where naked new/delete is
used for run-time configuration of diagnostics:
* the output format (text vs SARIF)
* client data hooks
* the option manager
* the URLifier
Hence this patch also makes use of std::unique_ptr and ::make_unique for
managing such client policy classes, and also for diagnostic_buffer's
per-format implementations.
Unfortunately we can't directly include <memory> in our internal headers
but instead any of our TUs that make use of std::unique_ptr must #define
INCLUDE_MEMORY before including system.h.
Hence the bulk of this patch is taken up with adding a define of
INCLUDE_MEMORY to hundreds of source files: everything that includes
diagnostic.h or pretty-print.h (and thus anything transitively such as
includers of lto-wrapper.h, c-tree.h, cp-tree.h and rtl-ssa.h).
Thanks to Gaius Mulley for the parts of the patch that regenerated the
m2 files.
gcc/ada/ChangeLog:
PR other/116613
* gcc-interface/misc.cc: Add #define INCLUDE_MEMORY
* gcc-interface/trans.cc: Likewise.
* gcc-interface/utils.cc: Likewise.
gcc/analyzer/ChangeLog:
PR other/116613
* analyzer-logging.cc: Add #define INCLUDE_MEMORY
(logger::logger): Update for m_pp becoming a unique_ptr.
(logger::~logger): Likewise.
(logger::log_va_partial): Likewise.
(logger::end_log_line): Likewise.
* analyzer-logging.h (logger::get_printer): Likewise.
(logger::m_pp): Convert to a unique_ptr.
* analyzer.cc (make_label_text): Use
diagnostic_context::clone_printer and use unique_ptr.
(make_label_text_n): Likewise.
* bar-chart.cc: Add #define INCLUDE_MEMORY
* pending-diagnostic.cc (evdesc::event_desc::formatted_print):
Use diagnostic_context::clone_printer and use unique_ptr.
* sm-malloc.cc (sufficiently_similar_p): Likewise.
* supergraph.cc (supergraph::dump_dot_to_file): Likewise.
gcc/c-family/ChangeLog:
PR other/116613
* c-ada-spec.cc: Add #define INCLUDE_MEMORY.
* c-attribs.cc: Likewise.
* c-common.cc: Likewise.
* c-format.cc: Likewise.
* c-gimplify.cc: Likewise.
* c-indentation.cc: Likewise.
* c-opts.cc: Likewise.
* c-pch.cc: Likewise.
* c-pragma.cc: Likewise.
* c-pretty-print.cc: Likewise. Add #include "make-unique.h".
(c_pretty_printer::clone): Use std::unique_ptr and ::make_unique.
* c-pretty-print.h (c_pretty_printer::clone): Use std::unique_ptr.
* c-type-mismatch.cc: Add #define INCLUDE_MEMORY.
* c-warn.cc: Likewise.
gcc/c/ChangeLog:
PR other/116613
* c-aux-info.cc: Add #define INCLUDE_MEMORY.
* c-convert.cc: Likewise.
* c-errors.cc: Likewise.
* c-fold.cc: Likewise.
* c-lang.cc: Likewise.
* c-objc-common.cc: Likewise.
(pp_markup::element_quoted_type::print_type): Use unique_ptr.
* c-typeck.cc: Add #define INCLUDE_MEMORY.
* gimple-parser.cc: Likewise.
gcc/cp/ChangeLog:
PR other/116613
* call.cc: Add #define INCLUDE_MEMORY.
* class.cc: Likewise.
* constexpr.cc: Likewise.
* constraint.cc: Likewise.
* contracts.cc: Likewise.
* coroutines.cc: Likewise.
* cp-gimplify.cc: Likewise.
* cp-lang.cc: Likewise.
* cp-objcp-common.cc: Likewise.
* cp-ubsan.cc: Likewise.
* cvt.cc: Likewise.
* cxx-pretty-print.cc: Likewise. Add #include "cp-tree.h".
(cxx_pretty_printer::clone): Use std::unique_ptr and
::make_unique.
* cxx-pretty-print.h (cxx_pretty_printer::clone): Use
std::unique_ptr.
* decl2.cc: Add #define INCLUDE_MEMORY.
* dump.cc: Likewise.
* except.cc: Likewise.
* expr.cc: Likewise.
* friend.cc: Likewise.
* init.cc: Likewise.
* lambda.cc: Likewise.
* logic.cc: Likewise.
* mangle.cc: Likewise.
* method.cc: Likewise.
* optimize.cc: Likewise.
* pt.cc: Likewise.
* ptree.cc: Likewise.
* rtti.cc: Likewise.
* search.cc: Likewise.
* semantics.cc: Likewise.
* tree.cc: Likewise.
* typeck.cc: Likewise.
* typeck2.cc: Likewise.
* vtable-class-hierarchy.cc: Likewise.
gcc/d/ChangeLog:
PR other/116613
* d-attribs.cc: Add #define INCLUDE_MEMORY.
* d-builtins.cc: Likewise.
* d-codegen.cc: Likewise.
* d-convert.cc: Likewise.
* d-diagnostic.cc: Likewise.
* d-frontend.cc: Likewise.
* d-lang.cc: Likewise.
* d-longdouble.cc: Likewise.
* d-target.cc: Likewise.
* decl.cc: Likewise.
* expr.cc: Likewise.
* intrinsics.cc: Likewise.
* modules.cc: Likewise.
* toir.cc: Likewise.
* typeinfo.cc: Likewise.
* types.cc: Likewise.
gcc/fortran/ChangeLog:
PR other/116613
* arith.cc: Add #define INCLUDE_MEMORY.
* array.cc: Likewise.
* bbt.cc: Likewise.
* check.cc: Likewise.
* class.cc: Likewise.
* constructor.cc: Likewise.
* convert.cc: Likewise.
* cpp.cc: Likewise.
* data.cc: Likewise.
* decl.cc: Likewise.
* dependency.cc: Likewise.
* dump-parse-tree.cc: Likewise.
* error.cc: Likewise.
* expr.cc: Likewise.
* f95-lang.cc: Likewise.
* frontend-passes.cc: Likewise.
* interface.cc: Likewise.
* intrinsic.cc: Likewise.
* io.cc: Likewise.
* iresolve.cc: Likewise.
* match.cc: Likewise.
* matchexp.cc: Likewise.
* misc.cc: Likewise.
* module.cc: Likewise.
* openmp.cc: Likewise.
* options.cc: Likewise.
* parse.cc: Likewise.
* primary.cc: Likewise.
* resolve.cc: Likewise.
* scanner.cc: Likewise.
* simplify.cc: Likewise.
* st.cc: Likewise.
* symbol.cc: Likewise.
* target-memory.cc: Likewise.
* trans-array.cc: Likewise.
* trans-common.cc: Likewise.
* trans-const.cc: Likewise.
* trans-decl.cc: Likewise.
* trans-expr.cc: Likewise.
* trans-intrinsic.cc: Likewise.
* trans-io.cc: Likewise.
* trans-openmp.cc: Likewise.
* trans-stmt.cc: Likewise.
* trans-types.cc: Likewise.
* trans.cc: Likewise.
gcc/go/ChangeLog:
PR other/116613
* go-backend.cc: Add #define INCLUDE_MEMORY.
* go-lang.cc: Likewise.
gcc/jit/ChangeLog:
PR other/116613
* dummy-frontend.cc: Add #define INCLUDE_MEMORY.
* jit-playback.cc: Likewise.
* jit-recording.cc: Likewise.
gcc/lto/ChangeLog:
PR other/116613
* lto-common.cc: Add #define INCLUDE_MEMORY.
* lto-dump.cc: Likewise.
* lto-partition.cc: Likewise.
* lto-symtab.cc: Likewise.
* lto.cc: Likewise.
gcc/m2/ChangeLog:
PR other/116613
* gm2-gcc/gcc-consolidation.h: Add #define INCLUDE_MEMORY.
* gm2-gcc/m2configure.cc: Likewise.
* mc-boot/GASCII.cc: Regenerate.
* mc-boot/GASCII.h: Ditto.
* mc-boot/GArgs.cc: Ditto.
* mc-boot/GArgs.h: Ditto.
* mc-boot/GAssertion.cc: Ditto.
* mc-boot/GAssertion.h: Ditto.
* mc-boot/GBreak.cc: Ditto.
* mc-boot/GBreak.h: Ditto.
* mc-boot/GCOROUTINES.h: Ditto.
* mc-boot/GCmdArgs.cc: Ditto.
* mc-boot/GCmdArgs.h: Ditto.
* mc-boot/GDebug.cc: Ditto.
* mc-boot/GDebug.h: Ditto.
* mc-boot/GDynamicStrings.cc: Ditto.
* mc-boot/GDynamicStrings.h: Ditto.
* mc-boot/GEnvironment.cc: Ditto.
* mc-boot/GEnvironment.h: Ditto.
* mc-boot/GFIO.cc: Ditto.
* mc-boot/GFIO.h: Ditto.
* mc-boot/GFormatStrings.cc: Ditto.
* mc-boot/GFormatStrings.h: Ditto.
* mc-boot/GFpuIO.cc: Ditto.
* mc-boot/GFpuIO.h: Ditto.
* mc-boot/GIO.cc: Ditto.
* mc-boot/GIO.h: Ditto.
* mc-boot/GIndexing.cc: Ditto.
* mc-boot/GIndexing.h: Ditto.
* mc-boot/GM2Dependent.cc: Ditto.
* mc-boot/GM2Dependent.h: Ditto.
* mc-boot/GM2EXCEPTION.cc: Ditto.
* mc-boot/GM2EXCEPTION.h: Ditto.
* mc-boot/GM2RTS.cc: Ditto.
* mc-boot/GM2RTS.h: Ditto.
* mc-boot/GMemUtils.cc: Ditto.
* mc-boot/GMemUtils.h: Ditto.
* mc-boot/GNumberIO.cc: Ditto.
* mc-boot/GNumberIO.h: Ditto.
* mc-boot/GPushBackInput.cc: Ditto.
* mc-boot/GPushBackInput.h: Ditto.
* mc-boot/GRTExceptions.cc: Ditto.
* mc-boot/GRTExceptions.h: Ditto.
* mc-boot/GRTco.h: Ditto.
* mc-boot/GRTentity.h: Ditto.
* mc-boot/GRTint.cc: Ditto.
* mc-boot/GRTint.h: Ditto.
* mc-boot/GSArgs.cc: Ditto.
* mc-boot/GSArgs.h: Ditto.
* mc-boot/GSFIO.cc: Ditto.
* mc-boot/GSFIO.h: Ditto.
* mc-boot/GSYSTEM.h: Ditto.
* mc-boot/GSelective.h: Ditto.
* mc-boot/GStdIO.cc: Ditto.
* mc-boot/GStdIO.h: Ditto.
* mc-boot/GStorage.cc: Ditto.
* mc-boot/GStorage.h: Ditto.
* mc-boot/GStrCase.cc: Ditto.
* mc-boot/GStrCase.h: Ditto.
* mc-boot/GStrIO.cc: Ditto.
* mc-boot/GStrIO.h: Ditto.
* mc-boot/GStrLib.cc: Ditto.
* mc-boot/GStrLib.h: Ditto.
* mc-boot/GStringConvert.cc: Ditto.
* mc-boot/GStringConvert.h: Ditto.
* mc-boot/GSysExceptions.h: Ditto.
* mc-boot/GSysStorage.cc: Ditto.
* mc-boot/GSysStorage.h: Ditto.
* mc-boot/GTimeString.cc: Ditto.
* mc-boot/GTimeString.h: Ditto.
* mc-boot/GUnixArgs.h: Ditto.
* mc-boot/Galists.cc: Ditto.
* mc-boot/Galists.h: Ditto.
* mc-boot/Gdecl.cc: Ditto.
* mc-boot/Gdecl.h: Ditto.
* mc-boot/Gdtoa.h: Ditto.
* mc-boot/Gerrno.h: Ditto.
* mc-boot/Gkeyc.cc: Ditto.
* mc-boot/Gkeyc.h: Ditto.
* mc-boot/Gldtoa.h: Ditto.
* mc-boot/Glibc.h: Ditto.
* mc-boot/Glibm.h: Ditto.
* mc-boot/Glists.cc: Ditto.
* mc-boot/Glists.h: Ditto.
* mc-boot/GmcComment.cc: Ditto.
* mc-boot/GmcComment.h: Ditto.
* mc-boot/GmcComp.cc: Ditto.
* mc-boot/GmcComp.h: Ditto.
* mc-boot/GmcDebug.cc: Ditto.
* mc-boot/GmcDebug.h: Ditto.
* mc-boot/GmcError.cc: Ditto.
* mc-boot/GmcError.h: Ditto.
* mc-boot/GmcFileName.cc: Ditto.
* mc-boot/GmcFileName.h: Ditto.
* mc-boot/GmcLexBuf.cc: Ditto.
* mc-boot/GmcLexBuf.h: Ditto.
* mc-boot/GmcMetaError.cc: Ditto.
* mc-boot/GmcMetaError.h: Ditto.
* mc-boot/GmcOptions.cc: Ditto.
* mc-boot/GmcOptions.h: Ditto.
* mc-boot/GmcPreprocess.cc: Ditto.
* mc-boot/GmcPreprocess.h: Ditto.
* mc-boot/GmcPretty.cc: Ditto.
* mc-boot/GmcPretty.h: Ditto.
* mc-boot/GmcPrintf.cc: Ditto.
* mc-boot/GmcPrintf.h: Ditto.
* mc-boot/GmcQuiet.cc: Ditto.
* mc-boot/GmcQuiet.h: Ditto.
* mc-boot/GmcReserved.cc: Ditto.
* mc-boot/GmcReserved.h: Ditto.
* mc-boot/GmcSearch.cc: Ditto.
* mc-boot/GmcSearch.h: Ditto.
* mc-boot/GmcStack.cc: Ditto.
* mc-boot/GmcStack.h: Ditto.
* mc-boot/GmcStream.cc: Ditto.
* mc-boot/GmcStream.h: Ditto.
* mc-boot/Gmcflex.h: Ditto.
* mc-boot/Gmcp1.cc: Ditto.
* mc-boot/Gmcp1.h: Ditto.
* mc-boot/Gmcp2.cc: Ditto.
* mc-boot/Gmcp2.h: Ditto.
* mc-boot/Gmcp3.cc: Ditto.
* mc-boot/Gmcp3.h: Ditto.
* mc-boot/Gmcp4.cc: Ditto.
* mc-boot/Gmcp4.h: Ditto.
* mc-boot/Gmcp5.cc: Ditto.
* mc-boot/Gmcp5.h: Ditto.
* mc-boot/GnameKey.cc: Ditto.
* mc-boot/GnameKey.h: Ditto.
* mc-boot/GsymbolKey.cc: Ditto.
* mc-boot/GsymbolKey.h: Ditto.
* mc-boot/Gtermios.h: Ditto.
* mc-boot/Gtop.cc: Ditto.
* mc-boot/Gvarargs.cc: Ditto.
* mc-boot/Gvarargs.h: Ditto.
* mc-boot/Gwlists.cc: Ditto.
* mc-boot/Gwlists.h: Ditto.
* mc-boot/Gwrapc.h: Ditto.
* mc/keyc.mod (checkGccConfigSystem): Add
#define INCLUDE_MEMORY.
* pge-boot/GASCII.cc: Regenerate.
* pge-boot/GASCII.h: Ditto.
* pge-boot/GArgs.cc: Ditto.
* pge-boot/GArgs.h: Ditto.
* pge-boot/GAssertion.cc: Ditto.
* pge-boot/GAssertion.h: Ditto.
* pge-boot/GBreak.h: Ditto.
* pge-boot/GCmdArgs.h: Ditto.
* pge-boot/GDebug.cc: Ditto.
* pge-boot/GDebug.h: Ditto.
* pge-boot/GDynamicStrings.cc: Ditto.
* pge-boot/GDynamicStrings.h: Ditto.
* pge-boot/GEnvironment.h: Ditto.
* pge-boot/GFIO.cc: Ditto.
* pge-boot/GFIO.h: Ditto.
* pge-boot/GFormatStrings.h: Ditto.
* pge-boot/GFpuIO.h: Ditto.
* pge-boot/GIO.cc: Ditto.
* pge-boot/GIO.h: Ditto.
* pge-boot/GIndexing.cc: Ditto.
* pge-boot/GIndexing.h: Ditto.
* pge-boot/GLists.cc: Ditto.
* pge-boot/GLists.h: Ditto.
* pge-boot/GM2Dependent.cc: Ditto.
* pge-boot/GM2Dependent.h: Ditto.
* pge-boot/GM2EXCEPTION.cc: Ditto.
* pge-boot/GM2EXCEPTION.h: Ditto.
* pge-boot/GM2RTS.cc: Ditto.
* pge-boot/GM2RTS.h: Ditto.
* pge-boot/GNameKey.cc: Ditto.
* pge-boot/GNameKey.h: Ditto.
* pge-boot/GNumberIO.cc: Ditto.
* pge-boot/GNumberIO.h: Ditto.
* pge-boot/GOutput.cc: Ditto.
* pge-boot/GOutput.h: Ditto.
* pge-boot/GPushBackInput.cc: Ditto.
* pge-boot/GPushBackInput.h: Ditto.
* pge-boot/GRTExceptions.cc: Ditto.
* pge-boot/GRTExceptions.h: Ditto.
* pge-boot/GSArgs.h: Ditto.
* pge-boot/GSEnvironment.h: Ditto.
* pge-boot/GSFIO.cc: Ditto.
* pge-boot/GSFIO.h: Ditto.
* pge-boot/GSYSTEM.h: Ditto.
* pge-boot/GScan.h: Ditto.
* pge-boot/GStdIO.cc: Ditto.
* pge-boot/GStdIO.h: Ditto.
* pge-boot/GStorage.cc: Ditto.
* pge-boot/GStorage.h: Ditto.
* pge-boot/GStrCase.cc: Ditto.
* pge-boot/GStrCase.h: Ditto.
* pge-boot/GStrIO.cc: Ditto.
* pge-boot/GStrIO.h: Ditto.
* pge-boot/GStrLib.cc: Ditto.
* pge-boot/GStrLib.h: Ditto.
* pge-boot/GStringConvert.h: Ditto.
* pge-boot/GSymbolKey.cc: Ditto.
* pge-boot/GSymbolKey.h: Ditto.
* pge-boot/GSysExceptions.h: Ditto.
* pge-boot/GSysStorage.cc: Ditto.
* pge-boot/GSysStorage.h: Ditto.
* pge-boot/GTimeString.h: Ditto.
* pge-boot/GUnixArgs.h: Ditto.
* pge-boot/Gbnflex.cc: Ditto.
* pge-boot/Gbnflex.h: Ditto.
* pge-boot/Gdtoa.h: Ditto.
* pge-boot/Gerrno.h: Ditto.
* pge-boot/Gldtoa.h: Ditto.
* pge-boot/Glibc.h: Ditto.
* pge-boot/Glibm.h: Ditto.
* pge-boot/Gpge.cc: Ditto.
* pge-boot/Gtermios.h: Ditto.
* pge-boot/Gwrapc.h: Ditto.
gcc/objc/ChangeLog:
PR other/116613
* objc-act.cc: Add #define INCLUDE_MEMORY.
* objc-encoding.cc: Likewise.
* objc-gnu-runtime-abi-01.cc: Likewise.
* objc-lang.cc: Likewise.
* objc-next-runtime-abi-01.cc: Likewise.
* objc-next-runtime-abi-02.cc: Likewise.
* objc-runtime-shared-support.cc: Likewise.
gcc/objcp/ChangeLog:: Add #define INCLUDE_MEMORY.
PR other/116613
* objcp-decl.cc
* objcp-lang.cc: Likewise.
gcc/rust/ChangeLog:
PR other/116613
* resolve/rust-ast-resolve-expr.cc: Add #define INCLUDE_MEMORY.
* rust-attribs.cc: Likewise.
* rust-system.h: Likewise.
gcc/ChangeLog:
PR other/116613
* asan.cc: Add #define INCLUDE_MEMORY.
* attribs.cc: Likewise.
(attr_access::array_as_string): Use
diagnostic_context::clone_printer and use unique_ptr.
* auto-profile.cc: Add #define INCLUDE_MEMORY.
* calls.cc: Likewise.
* cfganal.cc: Likewise.
* cfgexpand.cc: Likewise.
* cfghooks.cc: Likewise.
* cfgloop.cc: Likewise.
* cgraph.cc: Likewise.
* cgraphclones.cc: Likewise.
* cgraphunit.cc: Likewise.
* collect-utils.cc: Likewise.
* collect2.cc: Likewise.
* common/config/aarch64/aarch64-common.cc: Likewise.
* common/config/arm/arm-common.cc: Likewise.
* common/config/avr/avr-common.cc: Likewise.
* config/aarch64/aarch64-cc-fusion.cc: Likewise.
* config/aarch64/aarch64-early-ra.cc: Likewise.
* config/aarch64/aarch64-sve-builtins.cc: Likewise.
* config/arc/arc.cc: Likewise.
* config/arm/aarch-common.cc: Likewise.
* config/arm/arm-mve-builtins.cc: Likewise.
* config/avr/avr-devices.cc: Likewise.
* config/avr/driver-avr.cc: Likewise.
* config/bpf/bpf.cc: Likewise.
* config/bpf/btfext-out.cc: Likewise.
* config/bpf/core-builtins.cc: Likewise.
* config/darwin.cc: Likewise.
* config/i386/driver-i386.cc: Likewise.
* config/i386/i386-builtins.cc: Likewise.
* config/i386/i386-expand.cc: Likewise.
* config/i386/i386-features.cc: Likewise.
* config/i386/i386-options.cc: Likewise.
* config/loongarch/loongarch-builtins.cc: Likewise.
* config/mingw/winnt-cxx.cc: Likewise.
* config/mingw/winnt.cc: Likewise.
* config/mips/mips.cc: Likewise.
* config/msp430/driver-msp430.cc: Likewise.
* config/nvptx/mkoffload.cc: Likewise.
* config/nvptx/nvptx.cc: Likewise.
* config/riscv/riscv-avlprop.cc: Likewise.
* config/riscv/riscv-vector-builtins.cc: Likewise.
* config/riscv/riscv-vsetvl.cc: Likewise.
* config/rs6000/driver-rs6000.cc: Likewise.
* config/rs6000/host-darwin.cc: Likewise.
* config/rs6000/rs6000-c.cc: Likewise.
* config/s390/s390-c.cc: Likewise.
* config/s390/s390.cc: Likewise.
* config/sol2-cxx.cc: Likewise.
* config/vms/vms-c.cc: Likewise.
* config/xtensa/xtensa-dynconfig.cc: Likewise.
* coroutine-passes.cc: Likewise.
* coverage.cc: Likewise.
* data-streamer-in.cc: Likewise.
* data-streamer-out.cc: Likewise.
* data-streamer.cc: Likewise.
* diagnostic-buffer.h (diagnostic_buffer::~diagnostic_buffer):
Delete.
(diagnostic_buffer::m_per_format_buffer): Use std::unique_ptr.
* diagnostic-client-data-hooks.h (make_compiler_data_hooks): Use
std::unique_ptr for return type.
* diagnostic-format-json.cc
(json_output_format::make_per_format_buffer): Likewise.
(diagnostic_output_format_init_json): Update for usage of
std::unique_ptr in set_output_format.
* diagnostic-format-sarif.cc
(sarif_output_format::make_per_format_buffer): Use std::unique_ptr
for return type.
(diagnostic_output_format_init_sarif): Update for usage of
std::unique_ptr.
(test_message_with_embedded_link): Likewise for set_urlifier.
* diagnostic-format-text.cc: Add #define INCLUDE_MEMORY. Include
"make-unique.h".
(diagnostic_text_output_format::set_buffer): Use std::unique_ptr.
* diagnostic-format-text.h
(diagnostic_text_output_format::set_buffer): Likewise.
* diagnostic-format.h
(diagnostic_output_format::make_per_format_buffer): Likewise.
* diagnostic-global-context.cc:
* diagnostic-macro-unwinding.cc: Likewise.
* diagnostic-show-locus.cc: Likewise.
* diagnostic-spec.cc: Likewise.
* diagnostic.cc (diagnostic_context::set_output_format): Use
std::unique_ptr for input.
(diagnostic_context::set_client_data_hooks): Likewise.
(diagnostic_context::set_option_manager): Likewise.
(diagnostic_context::set_urlifier): Likewise.
(diagnostic_context::set_diagnostic_buffer): Update for use of
std::unique_ptr.
(diagnostic_buffer::diagnostic_buffer): Likewise.
(diagnostic_buffer::~diagnostic_buffer): Delete.
* diagnostic.h: Complain if INCLUDE_MEMORY was not defined.
(diagnostic_context::set_output_format): Use std::unique_ptr for
input.
(diagnostic_context::set_client_data_hooks): Likewise.
(diagnostic_context::set_option_manager): Likewise.
(diagnostic_context::set_urlifier): Likewise.
(diagnostic_context::clone_printer): New.
(diagnostic_context::m_printer): Update comment.
(diagnostic_context::m_option_mgr): Likewise.
(diagnostic_context::m_urlifier): Likewise.
(diagnostic_context::m_edit_context_ptr): Likewise.
(diagnostic_context::m_output_format): Likewise.
(diagnostic_context::m_client_data_hooks): Likewise.
(diagnostic_context::m_theme): Likewise.
* digraph.cc: Add #define INCLUDE_MEMORY.
* dwarf2out.cc: Likewise.
* edit-context.cc: Likewise.
* except.cc: Likewise.
* expr.cc: Likewise.
* file-prefix-map.cc: Likewise.
* final.cc: Likewise.
* fwprop.cc: Likewise.
* gcc-plugin.h: Likewise.
* gcc-rich-location.cc: Likewise.
* gcc-urlifier.cc: Likewise. Add #include "make-unique.h".
(make_gcc_urlifier): Use std::unique_ptr and ::make_unique.
* gcc-urlifier.h (make_gcc_urlifier): Use std::unique_ptr.
* gcc.cc: Add #define INCLUDE_MEMORY. Include
"pretty-print-urlifier.h".
* gcov-dump.cc: Add #define INCLUDE_MEMORY.
* gcov-tool.cc: Likewise.
* gengtype.cc (open_base_files): Likewise to output.
* genmatch.cc: Likewise.
* gimple-fold.cc: Likewise.
* gimple-harden-conditionals.cc: Likewise.
* gimple-harden-control-flow.cc: Likewise.
* gimple-if-to-switch.cc: Likewise.
* gimple-lower-bitint.cc: Likewise.
* gimple-predicate-analysis.cc: Likewise.
* gimple-pretty-print.cc: Likewise.
* gimple-range-cache.cc: Likewise.
* gimple-range-edge.cc: Likewise.
* gimple-range-fold.cc: Likewise.
* gimple-range-gori.cc: Likewise.
* gimple-range-infer.cc: Likewise.
* gimple-range-op.cc: Likewise.
* gimple-range-path.cc: Likewise.
* gimple-range-phi.cc: Likewise.
* gimple-range-trace.cc: Likewise.
* gimple-range.cc: Likewise.
* gimple-ssa-backprop.cc: Likewise.
* gimple-ssa-sprintf.cc: Likewise.
* gimple-ssa-store-merging.cc: Likewise.
* gimple-ssa-strength-reduction.cc: Likewise.
* gimple-ssa-warn-access.cc: Likewise.
* gimple-ssa-warn-alloca.cc: Likewise.
* gimple-ssa-warn-restrict.cc: Likewise.
* gimple-streamer-in.cc: Likewise.
* gimple-streamer-out.cc: Likewise.
* gimple.cc: Likewise.
* gimplify.cc: Likewise.
* graph.cc: Likewise.
* graphviz.cc: Likewise.
* input.cc: Likewise.
* ipa-cp.cc: Likewise.
* ipa-devirt.cc: Likewise.
* ipa-fnsummary.cc: Likewise.
* ipa-free-lang-data.cc: Likewise.
* ipa-icf-gimple.cc: Likewise.
* ipa-icf.cc: Likewise.
* ipa-inline-analysis.cc: Likewise.
* ipa-inline.cc: Likewise.
* ipa-modref-tree.cc: Likewise.
* ipa-modref.cc: Likewise.
* ipa-param-manipulation.cc: Likewise.
* ipa-polymorphic-call.cc: Likewise.
* ipa-predicate.cc: Likewise.
* ipa-profile.cc: Likewise.
* ipa-prop.cc: Likewise.
* ipa-pure-const.cc: Likewise.
* ipa-reference.cc: Likewise.
* ipa-split.cc: Likewise.
* ipa-sra.cc: Likewise.
* ipa-strub.cc: Likewise.
* ipa-utils.cc: Likewise.
* langhooks.cc: Likewise.
* late-combine.cc: Likewise.
* lto-cgraph.cc: Likewise.
* lto-compress.cc: Likewise.
* lto-opts.cc: Likewise.
* lto-section-in.cc: Likewise.
* lto-section-out.cc: Likewise.
* lto-streamer-in.cc: Likewise.
* lto-streamer-out.cc: Likewise.
* lto-streamer.cc: Likewise.
* lto-wrapper.cc: Likewise. Include "make-unique.h".
(main): Use ::make_unique when creating option manager.
* multiple_target.cc: Likewise.
* omp-expand.cc: Likewise.
* omp-general.cc: Likewise.
* omp-low.cc: Likewise.
* omp-oacc-neuter-broadcast.cc: Likewise.
* omp-offload.cc: Likewise.
* omp-simd-clone.cc: Likewise.
* optc-gen.awk: Likewise in output.
* optc-save-gen.awk: Likewise in output.
* options-urls-cc-gen.awk: Likewise in output.
* opts-common.cc: Likewise.
* opts-global.cc: Likewise.
* opts.cc: Likewise.
* pair-fusion.cc: Likewise.
* passes.cc: Likewise.
* pointer-query.cc: Likewise.
* predict.cc: Likewise.
* pretty-print.cc (pretty_printer::clone): Use std::unique_ptr and
::make_unique.
* pretty-print.h: Complain if INCLUDE_MEMORY is not defined.
(pretty_printer::clone): Use std::unique_ptr.
* print-rtl.cc: Add #define INCLUDE_MEMORY.
* print-tree.cc: Likewise.
* profile-count.cc: Likewise.
* range-op-float.cc: Likewise.
* range-op-ptr.cc: Likewise.
* range-op.cc: Likewise.
* range.cc: Likewise.
* read-rtl-function.cc: Likewise.
* rtl-error.cc: Likewise.
* rtl-ssa/accesses.cc: Likewise.
* rtl-ssa/blocks.cc: Likewise.
* rtl-ssa/changes.cc: Likewise.
* rtl-ssa/functions.cc: Likewise.
* rtl-ssa/insns.cc: Likewise.
* rtl-ssa/movement.cc: Likewise.
* rtl-tests.cc: Likewise.
* sanopt.cc: Likewise.
* sched-rgn.cc: Likewise.
* selftest-diagnostic-path.cc: Likewise.
* selftest-diagnostic.cc: Likewise.
* splay-tree-utils.cc: Likewise.
* sreal.cc: Likewise.
* stmt.cc: Likewise.
* substring-locations.cc: Likewise.
* symtab-clones.cc: Likewise.
* symtab-thunks.cc: Likewise.
* symtab.cc: Likewise.
* text-art/box-drawing.cc: Likewise.
* text-art/canvas.cc: Likewise.
* text-art/ruler.cc: Likewise.
* text-art/selftests.cc: Likewise.
* text-art/theme.cc: Likewise.
* toplev.cc: Likewise. Include "make-unique.h".
(general_init): Use ::make_unique when setting option_manager.
* trans-mem.cc: Add #define INCLUDE_MEMORY.
* tree-affine.cc: Likewise.
* tree-call-cdce.cc: Likewise.
* tree-cfg.cc: Likewise.
* tree-chrec.cc: Likewise.
* tree-dfa.cc: Likewise.
* tree-diagnostic-client-data-hooks.cc: Include "make-unique.h".
(make_compiler_data_hooks): Use std::unique_ptr and ::make_unique.
* tree-diagnostic.cc: Add #define INCLUDE_MEMORY.
* tree-dump.cc: Likewise.
* tree-inline.cc: Likewise.
* tree-into-ssa.cc: Likewise.
* tree-logical-location.cc: Likewise.
* tree-nested.cc: Likewise.
* tree-nrv.cc: Likewise.
* tree-object-size.cc: Likewise.
* tree-outof-ssa.cc: Likewise.
* tree-pretty-print.cc: Likewise.
* tree-profile.cc: Likewise.
* tree-scalar-evolution.cc: Likewise.
* tree-sra.cc: Likewise.
* tree-ssa-address.cc: Likewise.
* tree-ssa-alias.cc: Likewise.
* tree-ssa-ccp.cc: Likewise.
* tree-ssa-coalesce.cc: Likewise.
* tree-ssa-copy.cc: Likewise.
* tree-ssa-dce.cc: Likewise.
* tree-ssa-dom.cc: Likewise.
* tree-ssa-forwprop.cc: Likewise.
* tree-ssa-ifcombine.cc: Likewise.
* tree-ssa-loop-ch.cc: Likewise.
* tree-ssa-loop-im.cc: Likewise.
* tree-ssa-loop-manip.cc: Likewise.
* tree-ssa-loop-niter.cc: Likewise.
* tree-ssa-loop-split.cc: Likewise.
* tree-ssa-math-opts.cc: Likewise.
* tree-ssa-operands.cc: Likewise.
* tree-ssa-phiprop.cc: Likewise.
* tree-ssa-pre.cc: Likewise.
* tree-ssa-propagate.cc: Likewise.
* tree-ssa-reassoc.cc: Likewise.
* tree-ssa-sccvn.cc: Likewise.
* tree-ssa-scopedtables.cc: Likewise.
* tree-ssa-sink.cc: Likewise.
* tree-ssa-strlen.cc: Likewise.
* tree-ssa-structalias.cc: Likewise.
* tree-ssa-ter.cc: Likewise.
* tree-ssa-uninit.cc: Likewise.
* tree-ssa.cc: Likewise.
* tree-ssanames.cc: Likewise.
* tree-stdarg.cc: Likewise.
* tree-streamer-in.cc: Likewise.
* tree-streamer-out.cc: Likewise.
* tree-streamer.cc: Likewise.
* tree-switch-conversion.cc: Likewise.
* tree-tailcall.cc: Likewise.
* tree-vrp.cc: Likewise.
* tree.cc: Likewise.
* ubsan.cc: Likewise.
* value-pointer-equiv.cc: Likewise.
* value-prof.cc: Likewise.
* value-query.cc: Likewise.
* value-range-pretty-print.cc: Likewise.
* value-range-storage.cc: Likewise.
* value-range.cc: Likewise.
* value-relation.cc: Likewise.
* var-tracking.cc: Likewise.
* varpool.cc: Likewise.
* vr-values.cc: Likewise.
* wide-int-print.cc: Likewise.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_group_plugin.c: Update for use of
std::unique_ptr.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Likewise.
* gcc.dg/plugin/ggcplug.c: Likewise.
libgcc/ChangeLog:
PR other/116613
* libgcov-util.c: Add #define INCLUDE_MEMORY.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Co-authored-by: Gaius Mulley <gaiusmod2@gmail.com>
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
PR fortran/105916 reports stray diagnostics appearing in JSON and SARIF
output from gfortran.
In order to handle various awkard parsing issues, the Fortran frontend
implements buffering of diagnostics, so that diagnostics reported to
global_dc can be either:
(a) immediately issued, or
(b) speculatively reported to global_dc, and stored in a buffer, to
either be issued later or discarded.
This buffering code in gcc/fortran/error.cc directly manipulates
implementation details of the diagnostic_context such as the
pretty_printer's buffer, and the counts of how many diagnostics have
been issued. The issue is that this manipulation of pretty_printer's
buffer doesn't work for formats such as JSON and SARIF where diagnostics
are handled in a different way (such as by accumulating json::object
instances in an array).
This patch moves responsibility for such buffering of diagnostics from
fortran's error.cc to the diagnostic subsystem. It introduces a new
class diagnostic_buffer representing a particular buffer of diagnostics
that have been reported but not yet issued. Each diagnostic output
format implements buffering in a different way, and so there is a
new class hierarchy, diagnostic_per_format_buffer, representing the
various format-specific ways that buffering is to be implemented. This
is hidden as an implementation detail of diagnostic_buffer.
The patch also updates how diagnostics of each kind (e.g. warnings vs
errors) are counted, so that if buffering is enabled, the count is
incremented within the buffer, and the counts in the diagnostic_context
are only updated if and when the buffer is flushed; checking for
max_errors is similarly updated to support both buffered and unbuffered
cases.
For ease of debugging, the patch extends the "dump" functions within the
diagnostics subsystem, so that e.g. global_dc->dump () now prints the
buffering status, e.g.:
(gdb) call global_dc->dump()
diagnostic_context:
counts:
(none)
output format:
sarif_output_format
printer:
m_show_color: false
m_url_format: bel
m_buffer:
m_formatted_obstack current object: length 0:
m_chunk_obstack current object: length 0:
diagnostic buffer:
m_per_format_buffer:
counts:
error: 1
diagnostic_sarif_format_buffer:
result[0]:
{"ruleId": "error",
"level": "error",
"message": {"text": "Function ‘program’ requires an argument list at (1)"},
"locations": [{"physicalLocation": {"artifactLocation": {"uri": "../../src/gcc/testsuite/gfortran.dg/pr105954.f90",
"uriBaseId": "PWD"},
"region": {"startLine": 6,
"startColumn": 8,
"endColumn": 9},
"contextRegion": {"startLine": 6,
"snippet": {"text": "program p\n"}}}}]}
which shows that no diagnostics have been issued yet, but the active
diagnostic_buffer has a single error buffered within it, in SARIF form.
Similarly, it's possible to use "dump" on a diagnostic_buffer to directly
query its contents; here's the same example, this time with the text
output format:
(gdb) call error_buffer.buffer.dump()
m_per_format_buffer:
counts:
error: 1
diagnostic_text_format_buffer:
m_formatted_obstack current object: length 232:
00000000: 1b 5b 30 31 6d 1b 5b 4b 2e 2e 2f 2e 2e 2f 73 72 | .[01m.[K../../sr
00000010: 63 2f 67 63 63 2f 74 65 73 74 73 75 69 74 65 2f | c/gcc/testsuite/
00000020: 67 66 6f 72 74 72 61 6e 2e 64 67 2f 70 72 31 30 | gfortran.dg/pr10
00000030: 35 39 35 34 2e 66 39 30 3a 36 3a 38 3a 1b 5b 6d | 5954.f90:6:8:.[m
00000040: 1b 5b 4b 0a 0a 20 20 20 20 36 20 7c 20 70 72 6f | .[K.. 6 | pro
00000050: 67 72 61 6d 20 70 0a 20 20 20 20 20 20 7c 20 20 | gram p. |
00000060: 20 20 20 20 20 20 1b 5b 30 31 3b 33 31 6d 1b 5b | .[01;31m.[
00000070: 4b 31 1b 5b 6d 1b 5b 4b 0a 1b 5b 30 31 3b 33 31 | K1.[m.[K..[01;31
00000080: 6d 1b 5b 4b 45 72 72 6f 72 3a 1b 5b 6d 1b 5b 4b | m.[KError:.[m.[K
00000090: 20 46 75 6e 63 74 69 6f 6e 20 e2 80 98 1b 5b 30 | Function ....[0
000000a0: 31 6d 1b 5b 4b 70 72 6f 67 72 61 6d 1b 5b 6d 1b | 1m.[Kprogram.[m.
000000b0: 5b 4b e2 80 99 20 72 65 71 75 69 72 65 73 20 61 | [K... requires a
000000c0: 6e 20 61 72 67 75 6d 65 6e 74 20 6c 69 73 74 20 | n argument list
000000d0: 61 74 20 1b 5b 30 31 3b 33 31 6d 1b 5b 4b 28 31 | at .[01;31m.[K(1
000000e0: 29 1b 5b 6d 1b 5b 4b 0a | ).[m.[K.
m_chunk_obstack current object: length 0:
showing that we have an error in error_buffer, with colorized text.
gcc/ChangeLog:
PR fortran/105916
* diagnostic-buffer.h: New file.
* diagnostic-format-json.cc: Define INCLUDE_VECTOR. Include
"diagnostic-buffer.h".
(class diagnostic_json_format_buffer): New subclass.
(class json_output_format): Add friend class
diagnostic_json_format_buffer.
(json_output_format::make_per_format_buffer): New vfunc
implementation.
(json_output_format::set_buffer): New vfunc implementation.
(json_output_format::json_output_format): Initialize m_buffer.
(json_output_format::m_buffer): New field.
(diagnostic_json_format_buffer::dump): New.
(diagnostic_json_format_buffer::empty_p): New.
(diagnostic_json_format_buffer::move_to): New.
(diagnostic_json_format_buffer::clear): New.
(diagnostic_json_format_buffer::flush): New.
(json_output_format::on_report_diagnostic): Implement optional
buffering.
* diagnostic-format-sarif.cc: Include "diagnostic-buffer.h".
(class diagnostic_sarif_format_buffer): New subclass.
(class sarif_builder): Add friend
class diagnostic_sarif_format_buffer.
(sarif_builder::num_results): New accessor.
(sarif_builder::get_result): New accessor.
(sarif_builder::on_report_diagnostic): Add param "buffer"; use it
to implement optional buffering.
(diagnostic_sarif_format_buffer::dump): New.
(diagnostic_sarif_format_buffer::empty_p): New.
(diagnostic_sarif_format_buffer::move_to): New.
(diagnostic_sarif_format_buffer::clear): New.
(diagnostic_sarif_format_buffer::flush): New.
(sarif_output_format::make_per_format_buffer): New vfunc
implementation.
(sarif_output_format::set_buffer): New vfunc implementation.
(sarif_output_format::on_report_diagnostic): Pass m_buffer to
sarif_builder::on_report_diagnostic.
(sarif_output_format::num_results): New accessor.
(sarif_output_format::get_result): New accessor.
(diagnostic_output_format::diagnostic_output_format): Initialize
m_buffer.
(diagnostic_output_format::m_buffer): New field.
(diagnostic_output_format::num_results): Get accessor.
(diagnostic_output_format::get_result): Get accessor.
(selftest::get_message_from_result): New.
(selftest::test_buffering): New.
(selftest::diagnostic_format_sarif_cc_tests): Call it.
* diagnostic-format-text.cc: Include
"diagnostic-client-data-hooks.h".
(class diagnostic_text_format_buffer): New subclass.
(diagnostic_text_format_buffer::diagnostic_text_format_buffer):
New.
(diagnostic_text_format_buffer::dump): New.
(diagnostic_text_format_buffer::empty_p): New.
(diagnostic_text_format_buffer::move_to): New.
(diagnostic_text_format_buffer::clear): New.
(diagnostic_text_format_buffer::flush): New.
(diagnostic_text_output_format::dump): Dump m_saved_output_buffer.
(diagnostic_text_output_format::set_buffer): New.
(diagnostic_text_output_format::make_per_format_buffer): New.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Initialize m_saved_output_buffer.
(diagnostic_text_output_format::set_buffer): New decl.
(diagnostic_text_output_format::make_per_format_buffer): New decl.
(diagnostic_text_output_format::m_saved_output_buffer): New field.
* diagnostic-format.h (class diagnostic_per_format_buffer): New
forward decl.
(diagnostic_output_format::make_per_format_buffer): New vfunc.
(diagnostic_output_format::set_buffer): New vfunc.
* diagnostic.cc: Include "diagnostic-buffer.h".
(diagnostic_context::initialize): Replace memset with call to
"clear" on m_diagnostic_counters. Initializer
m_diagnostic_buffer.
(diagnostic_context::finish): Call set_diagnostic_buffer with
nullptr.
(diagnostic_context::dump): Update for encapsulation of counts
into m_diagnostic_counters. Dump m_diagnostic_buffer.
(diagnostic_context::execution_failed_p): Update for encapsulation of
counts into m_diagnostic_counters.
(diagnostic_context::check_max_errors): Likewise.
(diagnostic_context::report_diagnostic): Likewise. Eliminate
diagnostic_check_max_errors in favor of check_max_errors.
Update increment of counter to support buffering. Eliminate
diagnostic_action_after_output in favor of action_after_output.
Only add fixits to m_edit_context_ptr if buffering is disabled.
Only call diagnostic_output_format::after_diagnostic if buffering
is disabled.
(diagnostic_context::error_recursion): Eliminate
diagnostic_action_after_output in favor of action_after_output.
(diagnostic_context::set_diagnostic_buffer): New.
(diagnostic_context::clear_diagnostic_buffer): New.
(diagnostic_context::flush_diagnostic_buffer): New.
(diagnostic_counters::diagnostic_counters): New.
(diagnostic_counters::dump): New.
(diagnostic_counters::move_to): New.
(diagnostic_counters::clear): New.
(diagnostic_buffer::diagnostic_buffer): New.
(diagnostic_buffer::~diagnostic_buffer): New.
(diagnostic_buffer::dump): New.
(diagnostic_buffer::empty_p): New.
(diagnostic_buffer::move_to): New.
(diagnostic_buffer::ensure_per_format_buffer): New.
(c_diagnostic_cc_tests): Remove stray newline.
* diagnostic.h (class diagnostic_buffer): New forward decl.
(struct diagnostic_counters): New.
(diagnostic_context::check_max_errors): Make private.
(diagnostic_context::action_after_output): Make private.
(diagnostic_context::get_output_format): Make non-const.
(diagnostic_context::diagnostic_count): Update for change
to m_diagnostic_counters.
(diagnostic_context::set_diagnostic_buffer): New decl.
(diagnostic_context::get_diagnostic_buffer): New decl.
(diagnostic_context::clear_diagnostic_buffer): New decl.
(diagnostic_context::flush_diagnostic_buffer): New decl.
(diagnostic_context::m_diagnostic_count): Replace array with...
(diagnostic_context::m_diagnostic_counters): ...this.
(diagnostic_context::m_diagnostic_buffer): New field.
(diagnostic_action_after_output): Delete.
(diagnostic_check_max_errors): Delete.
gcc/fortran/ChangeLog:
PR fortran/105916
* error.cc (pp_error_buffer, pp_warning_buffer): Convert from
output_buffer * to diagnostic_buffer *.
(warningcount_buffered, werrorcount_buffered): Eliminate.
(gfc_error_buffer::gfc_error_buffer): Move constructor definition
here, and initialize "buffer" using *global_dc.
(gfc_output_buffer_empty_p): Delete in favor of
diagnostic_buffer::empty_p.
(gfc_clear_pp_buffer): Replace with...
(gfc_clear_diagnostic_buffer): ...this, moving implementation
details to diagnostic_context::clear_diagnostic_buffer.
(gfc_warning): Replace buffering implementation with calls
to global_dc->get_diagnostic_buffer and
global_dc->set_diagnostic_buffer.
(gfc_clear_warning): Update for renaming of gfc_clear_pp_buffer
and elimination of warningcount_buffered and werrorcount_buffered.
(gfc_warning_check): Replace buffering implementation with calls
to pp_warning_buffer->empty_p and
global_dc->flush_diagnostic_buffer.
(gfc_error_opt): Replace buffering implementation with calls to
global_dc->get_diagnostic_buffer and set_diagnostic_buffer.
(gfc_clear_error): Update for renaming of gfc_clear_pp_buffer.
(gfc_error_flag_test): Replace call to gfc_output_buffer_empty_p
with call to diagnostic_buffer::empty_p.
(gfc_error_check): Replace buffering implementation with calls
to pp_error_buffer->empty_p and global_dc->flush_diagnostic_buffer.
(gfc_move_error_buffer_from_to): Replace buffering implementation
with usage of diagnostic_buffer.
(gfc_free_error): Update for renaming of gfc_clear_pp_buffer.
(gfc_diagnostics_init): Use "new" directly when creating
pp_warning_buffer. Remove setting of m_flush_p on the two
buffers, as this is handled by diagnostic_buffer and by
diagnostic_text_format_buffer's constructor.
* gfortran.h: Replace #include "pretty-print.h" for output_buffer
with #include "diagnostic-buffer.h" for diagnostic_buffer.
(struct gfc_error_buffer): Change type of field "buffer" from
output_buffer to diagnostic_buffer. Move definition of constructor
into error.cc so that it can use global_dc.
gcc/testsuite/ChangeLog:
PR fortran/105916
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Include
"diagnostic-buffer.h".
(class diagnostic_xhtml_format_buffer): New subclass.
(class xhtml_builder): Add friend
class diagnostic_xhtml_format_buffer.
(diagnostic_xhtml_format_buffer::dump): New.
(diagnostic_xhtml_format_buffer::empty_p): New.
(diagnostic_xhtml_format_buffer::move_to): New.
(diagnostic_xhtml_format_buffer::clear): New.
(diagnostic_xhtml_format_buffer::flush): New.
(xhtml_builder::on_report_diagnostic): Add "buffer" param, and use
it.
(xhtml_output_format::dump): Fix typo.
(xhtml_output_format::make_per_format_buffer): New.
(xhtml_output_format::set_buffer): New.
(xhtml_output_format::on_report_diagnostic): Fix whitespace. Pass
m_buffer to xhtml_builder::on_report_diagnostic.
(xhtml_output_format::xhtml_output_format): Initialize m_buffer.
(xhtml_output_format::m_buffer): New field.
* gfortran.dg/diagnostic-format-json-pr105916.F90: New test.
* gfortran.dg/diagnostic-format-sarif-1.F90: New test.
* gfortran.dg/diagnostic-format-sarif-1.py: New support script.
* gfortran.dg/diagnostic-format-sarif-pr105916.f90: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This commit expands on r15-3973-g4c7a58ac2617e2, which added
debug "dump" member functiosn to pretty_printer and output_buffer.
This followup adds "dump" member functions to diagnostic_context and
diagnostic_format, extends the existing dump functions and adds
indentation to make it much easier to see the various relationships
between context, format, printer, etc.
Hence you can now do:
(gdb) call global_dc->dump ()
and get a useful summary of what the diagnostic subsystem is doing;
for example:
(gdb) call global_dc->dump()
diagnostic_context:
counts:
output format:
sarif_output_format
printer:
m_show_color: false
m_url_format: bel
m_buffer:
m_formatted_obstack current object: length 0:
m_chunk_obstack current object: length 0:
pp_formatted_chunks: depth 0
0: TEXT("Function ")]
1: BEGIN_QUOTE, TEXT("program"), END_QUOTE]
2: TEXT(" requires an argument list at ")]
3: TEXT("(1)")]
showing the counts of all diagnostic kind that are non-zero (none yet),
that we have a sarif output format, and the printer is part-way through
formatting a string.
gcc/ChangeLog:
* diagnostic-format-json.cc (json_output_format::dump): New.
* diagnostic-format-sarif.cc (sarif_output_format::dump): New.
(sarif_file_output_format::dump): New.
* diagnostic-format-text.cc (diagnostic_text_output_format::dump):
New.
* diagnostic-format-text.h (diagnostic_text_output_format::dump):
New decl.
* diagnostic-format.h (diagnostic_output_format::dump): New decls.
* diagnostic.cc (diagnostic_context::dump): New.
(diagnostic_output_format::dump): New.
* diagnostic.h (diagnostic_context::dump): New decls.
* pretty-print-format-impl.h (pp_formatted_chunks::dump): Add
"indent" param.
* pretty-print.cc (bytes_per_hexdump_line): New constant.
(print_hexdump_line): New.
(print_hexdump): New.
(output_buffer::dump): Add "indent" param and use it. Add
hexdump of current object in m_formatted_obstack and
m_chunk_obstack.
(pp_formatted_chunks::dump): Add "indent" param and use it.
(pretty_printer::dump): Likewise. Add dumping of m_show_color
and m_url_format.
* pretty-print.h (output_buffer::dump): Add "indent" param.
(pretty_printer::dump): Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c
(xhtml_output_format::dump): New.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch makes the SARIF output's crash handler attempt to capture
a backtrace in JSON form within the notification's property bag. The
precise format of the property is subject to change, but, for example,
in one of the test cases I got output like this:
"properties": {"gcc/backtrace": {"frames": [{"pc": "0x7f39c610a32d",
"function": "pass_crash_test::execute(function*)",
"filename": "/home/david/gcc-newgit/src/gcc/testsuite/gcc.dg/plugin/crash_test_plugin.c",
"lineno": 98}]}}}],
The backtrace code is based on that in diagnostic.cc.
gcc/ChangeLog:
PR other/116602
* diagnostic-format-sarif.cc: Include "demangle.h" and
"backtrace.h".
(sarif_invocation::add_notification_for_ice): Add "backtrace"
param and pass it to ctor.
(sarif_ice_notification::sarif_ice_notification): Add "backtrace"
param and add it to property bag.
(bt_stop): New, taken from diagnostic.cc.
(struct bt_closure): New.
(bt_callback): New, adapted from diagnostic.cc.
(sarif_builder::make_stack_from_backtrace): New.
(sarif_builder::on_report_diagnostic): Attempt to get backtrace
and pass it to add_notification_for_ice.
gcc/testsuite/ChangeLog:
PR other/116602
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_1.py: Add check
for backtrace.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_2.py: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
No functional change intended.
gcc/ChangeLog:
PR other/116613
* diagnostic-format-sarif.cc
(sarif_builder::on_report_diagnostic): Move the fnotice here from
sarif_ice_handler.
(sarif_ice_handler): Delete.
(diagnostic_output_format_init_sarif): Drop setting of ice handler
callback.
* diagnostic.cc (diagnostic_context::initialize): Likewise.
(diagnostic_context::action_after_output): Rather than call
m_ice_handler_cb, instead call finish on this context.
* diagnostic.h (ice_handler_callback_t): Delete typedef.
(diagnostic_context::set_ice_handler_callback): Delete.
(diagnostic_context::m_ice_handler_cb): Delete.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Update for
removal of ICE callback.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Now that C23 support is essentially feature-complete, I'd like to
switch the default language version for C compilation to -std=gnu23.
This requires updating a large number of testcases that fail with the
new language version if left unchanged. In this patch, update most of
the tests for which there is a safe change that works both before and
after the update to default language version - typically adding the
option -std=gnu17 or -Wno-old-style-definition to the tests. (There
are also a few tests where I'd like to investigate further why they
fail with -std=gnu23, or where I think such failures show an actual
bug to fix before changing the default language version, or where it
seems more appropriate to make a testcase change that would result in
failures in the absence of the language version change rather than
just adding an option that does nothing with the gnu17 default.)
The libffi test fixes have also been submitted upstream:
<https://github.com/libffi/libffi/pull/861>.
Most of the failures requiring such changes are for one of two
reasons:
* Unprototyped function declarations with () (meaning the same as
(void) in C23 mode) for a function then called with arguments.
* Old-style function definitions, which warn by default in C23 mode,
so resulting in test failures for the unexpected warnings.
Other reasons for failures include:
* Tests with their own definitions of bool, true and false.
* Tests of diagnostics (often with -pedantic) in cases where C23 has
changed semantics, such as:
- tag compatibility for structs;
- enum values out of range of int;
- handing of qualified array types;
- decimal floating types formerly needing -pedantic diagnostics, but
being standard in C23.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc/testsuite/
* c-c++-common/Wcast-function-type.c: Add -std=gnu17 for C.
* c-c++-common/Wformat-pr84258.c: Add -std=gnu17 for C.
* c-c++-common/Wvarargs.c: Add -std=gnu17 for C.
* c-c++-common/analyzer/data-model-12.c: Add -std=gnu17 for C.
* c-c++-common/builtins.c: Add -std=gnu17 for C.
* c-c++-common/pointer-to-fn1.c: Add -std=gnu17 for C.
* c-c++-common/pragma-diag-17.c: Add -std=gnu17 for C.
* c-c++-common/sizeof-array-argument.c: Add
-Wno-old-style-definition for C.
* g++.dg/lto/pr54625-1_0.c: Add -std=gnu17.
* g++.dg/lto/pr54625-2_0.c: Add -std=gnu17.
* gcc.c-torture/compile/20040214-2.c: Add -std=gnu17.
* gcc.c-torture/compile/921011-2.c: Add -std=gnu17.
* gcc.c-torture/compile/931102-1.c: Add -std=gnu17.
* gcc.c-torture/compile/990801-1.c: Add -std=gnu17.
* gcc.c-torture/compile/nested-1.c: Add -std=gnu17.
* gcc.c-torture/compile/pr100241-1.c: Add -std=gnu17.
* gcc.c-torture/compile/pr106101.c: Add -std=gnu17.
* gcc.c-torture/compile/pr113616.c: Add -std=gnu17.
* gcc.c-torture/compile/pr47967.c: Add -std=gnu17.
* gcc.c-torture/compile/pr51694.c: Add -std=gnu17.
* gcc.c-torture/compile/pr71109.c: Add -std=gnu17.
* gcc.c-torture/compile/pr83051-2.c: Add -std=gnu17.
* gcc.c-torture/compile/pr89663-1.c: Add -std=gnu17.
* gcc.c-torture/compile/pr94238.c: Add -std=gnu17.
* gcc.c-torture/compile/pr96796.c: Add -std=gnu17.
* gcc.c-torture/compile/pr97576.c: Add -std=gnu17.
* gcc.c-torture/compile/udivmod4.c: Add -std=gnu17.
* gcc.c-torture/execute/20010605-2.c: Add -std=gnu17.
* gcc.c-torture/execute/20020404-1.c: Add -std=gnu17.
* gcc.c-torture/execute/20030714-1.c: Add -std=gnu17.
* gcc.c-torture/execute/20051012-1.c: Add -std=gnu17.
* gcc.c-torture/execute/20190820-1.c: Add -std=gnu17.
* gcc.c-torture/execute/920612-1.c: Add -Wno-old-style-definition.
* gcc.c-torture/execute/930608-1.c: Add -std=gnu17.
* gcc.c-torture/execute/comp-goto-1.c: Add -std=gnu17.
* gcc.c-torture/execute/ieee/fp-cmp-1.x: Add -std=gnu17.
* gcc.c-torture/execute/ieee/fp-cmp-2.x: Add -std=gnu17.
* gcc.c-torture/execute/ieee/fp-cmp-3.x: Add -std=gnu17.
* gcc.c-torture/execute/ieee/fp-cmp-4.x: New file.
* gcc.c-torture/execute/ieee/fp-cmp-4f.x: New file.
* gcc.c-torture/execute/ieee/fp-cmp-4l.x: New file.
* gcc.c-torture/execute/loop-9.c: Add -std=gnu17.
* gcc.c-torture/execute/pr103209.c: Add -std=gnu17.
* gcc.c-torture/execute/pr28289.c: Add -std=gnu17.
* gcc.c-torture/execute/pr34982.c: Add -std=gnu17.
* gcc.c-torture/execute/pr67037.c: Add -std=gnu17.
* gcc.c-torture/execute/va-arg-2.c: Add -std=gnu17.
* gcc.dg/20010202-1.c: Add -std=gnu17.
* gcc.dg/20020430-1.c: Add -std=gnu17.
* gcc.dg/20031218-3.c: Add -std=gnu17.
* gcc.dg/20040127-1.c: Add -std=gnu17.
* gcc.dg/20041014-1.c: Add -Wno-old-style-definition.
* gcc.dg/20041122-1.c: Add -std=gnu17.
* gcc.dg/20050309-1.c: Add -std=gnu17.
* gcc.dg/20061026.c: Add -std=gnu17.
* gcc.dg/20101010-1.c: Add -std=gnu17.
* gcc.dg/Warray-parameter-10.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch-2.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch-3.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch-4.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch-5.c: Add -std=gnu17.
* gcc.dg/Wbuiltin-declaration-mismatch.c: Add -std=gnu17.
* gcc.dg/Wcxx-compat-2.c: Add -std=gnu17.
* gcc.dg/Wdouble-promotion.c: Add -std=gnu17.
* gcc.dg/Wfree-nonheap-object-7.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-1.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-1a.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-2.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-3.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-4.c: Add -std=gnu17.
* gcc.dg/Wimplicit-int-4a.c: Add -std=gnu17.
* gcc.dg/Wincompatible-pointer-types-1.c: Add -std=gnu17.
* gcc.dg/Wrestrict-19.c: Add -std=gnu17.
* gcc.dg/Wrestrict-4.c: Add -std=gnu17.
* gcc.dg/Wrestrict-5.c: Add -std=gnu17.
* gcc.dg/Wstrict-overflow-20.c: Add -std=gnu17.
* gcc.dg/Wstringop-overflow-13.c: Add -std=gnu17.
* gcc.dg/analyzer/doom-d_main-IdentifyVersion.c: Add -std=gnu17.
* gcc.dg/analyzer/doom-s_sound-pr108867.c: Add -std=gnu17.
* gcc.dg/analyzer/pr93032-mztools-signed-char.c: Add
-Wno-old-style-definition.
* gcc.dg/analyzer/pr93032-mztools-unsigned-char.c: Add
-Wno-old-style-definition.
* gcc.dg/analyzer/pr93355-localealias.c: Add
-Wno-old-style-definition.
* gcc.dg/analyzer/pr93375.c: Add -std=gnu17.
* gcc.dg/analyzer/pr94688.c: Add -std=gnu17.
* gcc.dg/analyzer/sensitive-1.c: Add -std=gnu17.
* gcc.dg/analyzer/torture/asm-x86-linux-wfx_get_ps_timeout-full.c:
Add -std=gnu17.
* gcc.dg/analyzer/torture/pr104863.c: Add -std=gnu17.
* gcc.dg/analyzer/torture/pr93379.c: Add -std=gnu17.
* gcc.dg/array-quals-2.c: Add -std=gnu17.
* gcc.dg/attr-invalid.c: Add -Wno-old-style-definition.
* gcc.dg/auto-init-uninit-A.c: Add -Wno-old-style-definition.
* gcc.dg/builtin-choose-expr.c: Declare exit with (int) prototype.
* gcc.dg/builtin-tgmath-err-1.c: Add -std=gnu17.
* gcc.dg/builtins-30.c: Add -std=gnu17.
* gcc.dg/cast-function-1.c: Add -std=gnu17.
* gcc.dg/cleanup-1.c: Add -std=gnu17.
* gcc.dg/compat/struct-complex-1_x.c: Add -std=gnu17.
* gcc.dg/compat/struct-complex-2_x.c: Add -std=gnu17.
* gcc.dg/compat/union-m128-1_x.c: Add -std=gnu17.
* gcc.dg/debug/dwarf2/pr66482.c: Add -std=gnu17.
* gcc.dg/dfp/composite-type-2.c: Add -std=gnu17.
* gcc.dg/dfp/composite-type.c: Add -std=gnu17.
* gcc.dg/dfp/keywords-pedantic.c: Add -std=gnu17.
* gcc.dg/dremf-type-compat-1.c: Add -std=gnu17.
* gcc.dg/dremf-type-compat-2.c: Add -std=gnu17.
* gcc.dg/dremf-type-compat-3.c: Add -std=gnu17.
* gcc.dg/dremf-type-compat-4.c: Add -std=gnu17.
* gcc.dg/enum-compat-1.c: Add -std=gnu17.
* gcc.dg/enum-compat-2.c: Add -std=gnu17.
* gcc.dg/floatn-errs.c: Add -std=gnu17.
* gcc.dg/fltconst-pedantic-dfp.c: Add -std=gnu17.
* gcc.dg/format/proto.c: Add -std=gnu17.
* gcc.dg/format/sentinel-1.c: Add -std=gnu17.
* gcc.dg/gomp/declare-simd-1.c: Add -Wno-old-style-definition.
* gcc.dg/ifelse-1.c: Add -Wno-old-style-definition.
* gcc.dg/inline-33.c: Add -std=gnu17.
* gcc.dg/ipa/inline-5.c: Add -std=gnu17.
* gcc.dg/ipa/ipa-sra-21.c: Add -std=gnu17.
* gcc.dg/ipa/pr102714.c: Add -std=gnu17.
* gcc.dg/ipa/pr104813.c: Add -std=gnu17.
* gcc.dg/ipa/pr108679.c: Add -std=gnu17.
* gcc.dg/ipa/pr42706.c: Add -std=gnu17.
* gcc.dg/ipa/pr88214.c: Add -Wno-old-style-definition.
* gcc.dg/ipa/pr91853.c: Add -Wno-old-style-definition.
* gcc.dg/ipa/pr93763.c: Add -std=gnu17.
* gcc.dg/ipa/pr96482-2.c: Add -std=gnu17.
* gcc.dg/lto/20091013-1_2.c: Add -std=gnu17.
* gcc.dg/lto/20091015-1_2.c: Add -std=gnu17.
* gcc.dg/lto/pr113197_1.c: Add -std=gnu17.
* gcc.dg/lto/pr54702_1.c: Add -std=gnu17.
* gcc.dg/lto/pr99849_0.c: Add -std=gnu17.
* gcc.dg/noncompile/920923-1.c: Add -std=gnu17.
* gcc.dg/noncompile/old-style-parm-1.c: Add
-Wno-old-style-definition.
* gcc.dg/noncompile/old-style-parm-3.c: Add
-Wno-old-style-definition.
* gcc.dg/noncompile/pr30552-2.c: Add -Wno-old-style-definition.
* gcc.dg/noncompile/pr30552-3.c: Add -std=gnu17.
* gcc.dg/noncompile/pr71265.c: Add -Wno-old-style-definition.
* gcc.dg/noncompile/pr79758-2.c: Add -Wno-old-style-definition.
* gcc.dg/noncompile/pr79758.c: Add -Wno-old-style-definition.
* gcc.dg/noncompile/va-arg-1.c: Add -std=gnu17.
* gcc.dg/old-style-prom-1.c: Add -std=gnu17.
* gcc.dg/old-style-prom-2.c: Add -std=gnu17.
* gcc.dg/old-style-prom-3.c: Add -std=gnu17.
* gcc.dg/old-style-then-proto-1.c: Add -std=gnu17.
* gcc.dg/parm-incomplete-1.c: Add -std=gnu17.
* gcc.dg/parm-mismatch-1.c: Add -std=gnu17.
* gcc.dg/permerror-default.c: Add -std=gnu17.
* gcc.dg/permerror-fpermissive-nowarning.c: Add -std=gnu17.
* gcc.dg/permerror-fpermissive.c: Add -std=gnu17.
* gcc.dg/permerror-noerror.c: Add -std=gnu17.
* gcc.dg/permerror-nowarning.c: Add -std=gnu17.
* gcc.dg/permerror-pedantic.c: Add -std=gnu17.
* gcc.dg/plugin/infoleak-net-ethtool-ioctl.c: Add -std=gnu17.
* gcc.dg/pointer-array-quals-1.c: Add -std=gnu17.
* gcc.dg/pointer-array-quals-2.c: Add -std=gnu17.
* gcc.dg/pr100791.c: Add -std=gnu17.
* gcc.dg/pr100843.c: Add -std=gnu17.
* gcc.dg/pr102273.c: Add -std=gnu17.
* gcc.dg/pr102385.c: Add -std=gnu17.
* gcc.dg/pr103222.c: Add -std=gnu17.
* gcc.dg/pr105140.c: Add -std=gnu17.
* gcc.dg/pr105150.c: Add -std=gnu17.
* gcc.dg/pr105250.c: Add -std=gnu17.
* gcc.dg/pr105972.c: Add -Wno-old-style-definition.
* gcc.dg/pr111039.c: Add -std=gnu17.
* gcc.dg/pr111407.c: Add -std=gnu17.
* gcc.dg/pr111922.c: Add -Wno-old-style-definition.
* gcc.dg/pr15236.c: Add -std=gnu17.
* gcc.dg/pr17188-1.c: Add -std=gnu17.
* gcc.dg/pr20368-1.c: Add -std=gnu17.
* gcc.dg/pr20368-2.c: Add -std=gnu17.
* gcc.dg/pr20368-3.c: Add -std=gnu17.
* gcc.dg/pr27331.c: Add -Wno-old-style-definition.
* gcc.dg/pr27861-1.c: Add -std=gnu17.
* gcc.dg/pr28121.c: Add -std=gnu17.
* gcc.dg/pr28243.c: Add -std=gnu17.
* gcc.dg/pr28888.c: Add -std=gnu17.
* gcc.dg/pr29254.c: Add -std=gnu17.
* gcc.dg/pr34457-1.c: Add -std=gnu17.
* gcc.dg/pr36015.c: Add -std=gnu17.
* gcc.dg/pr38245-3.c: Add -std=gnu17.
* gcc.dg/pr38245-4.c: Add -std=gnu17.
* gcc.dg/pr41241.c: Add -std=gnu17.
* gcc.dg/pr43058.c: Add -std=gnu17.
* gcc.dg/pr44539.c: Add -std=gnu17.
* gcc.dg/pr45055.c: Add -std=gnu17.
* gcc.dg/pr50908.c: Add -Wno-old-style-definition.
* gcc.dg/pr60647-1.c: Add -Wno-old-style-definition.
* gcc.dg/pr63762.c: Add -std=gnu17.
* gcc.dg/pr63804.c: Add -std=gnu17.
* gcc.dg/pr68306-3.c: Add -std=gnu17.
* gcc.dg/pr68533.c: Add -std=gnu17.
* gcc.dg/pr69156.c: Add -std=gnu17.
* gcc.dg/pr7356-2.c: Add -Wno-old-style-definition.
* gcc.dg/pr79983.c: Add -std=gnu17.
* gcc.dg/pr83463.c: Add -std=gnu17.
* gcc.dg/pr87347.c: Add -std=gnu17.
* gcc.dg/pr89521-1.c: Add -std=gnu17.
* gcc.dg/pr89521-2.c: Add -std=gnu17.
* gcc.dg/pr90648.c: Add -std=gnu17.
* gcc.dg/pr93573-1.c: Add -std=gnu17.
* gcc.dg/pr94167.c: Add -std=gnu17.
* gcc.dg/pr94705.c: Add -std=gnu17.
* gcc.dg/pr95118.c: Add -std=gnu17.
* gcc.dg/pr96335.c: Add -std=gnu17.
* gcc.dg/pr97830.c: Add -std=gnu17.
* gcc.dg/pr97882.c: Add -std=gnu17.
* gcc.dg/pr99122-2.c: Add -std=gnu17.
* gcc.dg/pr99122-3.c: Add -std=gnu17.
* gcc.dg/qual-component-1.c: Add -std=gnu17.
* gcc.dg/sibcall-6.c: Add -Wno-old-style-definition.
* gcc.dg/sms-2.c: Add -Wno-old-style-definition.
* gcc.dg/tm/20091221.c: Add -std=gnu17.
* gcc.dg/torture/bfloat16-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float128-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float128x-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float16-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float32-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float32x-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float64-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/float64x-basic.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr102762.c: Add -std=gnu17.
* gcc.dg/torture/pr103987.c: Add -std=gnu17.
* gcc.dg/torture/pr104825.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr105166.c: Add -std=gnu17.
* gcc.dg/torture/pr105185.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr109652.c: Add -std=gnu17.
* gcc.dg/torture/pr112444.c: Add -std=gnu17.
* gcc.dg/torture/pr113895-3.c: Add -std=gnu17.
* gcc.dg/torture/pr24626-2.c: Add -std=gnu17.
* gcc.dg/torture/pr25183.c: Add -std=gnu17.
* gcc.dg/torture/pr38948.c: Add -std=gnu17.
* gcc.dg/torture/pr44807.c: Add -std=gnu17.
* gcc.dg/torture/pr47281.c: Add -std=gnu17.
* gcc.dg/torture/pr47958-1.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr48063.c: Add -std=gnu17.
* gcc.dg/torture/pr57036-1.c: Add -std=gnu17.
* gcc.dg/torture/pr57330.c: Add -std=gnu17.
* gcc.dg/torture/pr57584.c: Add -std=gnu17.
* gcc.dg/torture/pr67741.c: Add -std=gnu17.
* gcc.dg/torture/pr68104.c: Add -std=gnu17.
* gcc.dg/torture/pr69242.c: Add -std=gnu17.
* gcc.dg/torture/pr70457.c: Add -std=gnu17.
* gcc.dg/torture/pr70985.c: Add -std=gnu17.
* gcc.dg/torture/pr71606.c: Add -std=gnu17.
* gcc.dg/torture/pr71816.c: Add -std=gnu17.
* gcc.dg/torture/pr77286.c: Add -std=gnu17.
* gcc.dg/torture/pr77646.c: Add -std=gnu17.
* gcc.dg/torture/pr77677-2.c: Add -std=gnu17.
* gcc.dg/torture/pr78365.c: Add -Wno-old-style-definition.
* gcc.dg/torture/pr79732.c: Add -std=gnu17.
* gcc.dg/torture/pr80612.c: Add -std=gnu17.
* gcc.dg/torture/pr80764.c: Add -std=gnu17.
* gcc.dg/torture/pr80842.c: Add -std=gnu17.
* gcc.dg/torture/pr81900.c: Add -std=gnu17.
* gcc.dg/torture/pr82276.c: Add -std=gnu17.
* gcc.dg/torture/pr84803.c: Add -std=gnu17.
* gcc.dg/torture/pr93124.c: Add -std=gnu17.
* gcc.dg/torture/pr97330-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-prof/comp-goto-1.c: Add -std=gnu17.
* gcc.dg/tree-ssa/20030703-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030708-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030709-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030709-3.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030710-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030711-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030711-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030711-3.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030714-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030714-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030728-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-10.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-11.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-3.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-6.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030807-7.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030814-4.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030814-5.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030814-6.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20030918-1.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/20040514-2.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/loadpre7.c: Add -Wno-old-style-definition.
* gcc.dg/tree-ssa/pr111003.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr115128.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr115191.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr24840.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr69666.c: Add -std=gnu17.
* gcc.dg/tree-ssa/pr70232.c: Add -std=gnu17.
* gcc.dg/ubsan/pr79757-1.c: Add -Wno-old-style-definition.
* gcc.dg/ubsan/pr79757-2.c: Add -Wno-old-style-definition.
* gcc.dg/ubsan/pr79757-3.c: Add -Wno-old-style-definition.
* gcc.dg/ubsan/pr81223.c: Add -std=gnu17.
* gcc.dg/uninit-10-O0.c: Add -Wno-old-style-definition.
* gcc.dg/uninit-10.c: Add -Wno-old-style-definition.
* gcc.dg/uninit-32.c: Add -std=gnu17.
* gcc.dg/uninit-41.c: Add -std=gnu17.
* gcc.dg/uninit-A-O0.c: Add -Wno-old-style-definition.
* gcc.dg/uninit-A.c: Add -Wno-old-style-definition.
* gcc.dg/unused-1.c: Add -Wno-old-style-definition.
* gcc.dg/vect/bb-slp-pr114249.c: Add -std=gnu17.
* gcc.dg/vect/bb-slp-pr97486.c: Add -std=gnu17.
* gcc.dg/vect/bb-slp-subgroups-1.c: Add -std=gnu17.
* gcc.dg/vect/bb-slp-subgroups-2.c: Add -std=gnu17.
* gcc.dg/vect/bb-slp-subgroups-3.c: Add -std=gnu17.
* gcc.dg/vect/vect-early-break_111-pr113731.c: Add -std=gnu17.
* gcc.dg/vect/vect-early-break_122-pr114239.c: Add -std=gnu17.
* gcc.dg/vect/vect-multi-peel-gaps.c: Add -std=gnu17.
* gcc.dg/vla-stexp-2.c: Add -std=gnu17.
* gcc.dg/warn-1.c: Add -Wno-old-style-definition.
* gcc.dg/winline-10.c: Add -Wno-old-style-definition.
* gcc.dg/wtr-label-1.c: Add -Wno-old-style-definition.
* gcc.dg/wtr-switch-1.c: Add -Wno-old-style-definition.
* gcc.target/i386/excess-precision-3.c: Add
-Wno-old-style-definition.
* gcc.target/i386/fma4-256-nmsubXX.c: Add -std=gnu17.
* gcc.target/i386/fma4-nmsubXX.c: Add -std=gnu17.
* gcc.target/i386/nop-mcount.c: Add -Wno-old-style-definition.
* gcc.target/i386/pr102627.c: Add -std=gnu17.
* gcc.target/i386/pr106994.c: Add -std=gnu17.
* gcc.target/i386/pr68349.c: Add -std=gnu17.
* gcc.target/i386/pr97313.c: Add -std=gnu17.
* gcc.target/i386/pr99454.c: Add -std=gnu17.
* gcc.target/i386/record-mcount.c: Add -Wno-old-style-definition.
libffi/
* testsuite/libffi.call/va_struct2.c (test_fn): Cast n to void.
* testsuite/libffi.call/va_struct3.c (test_fn): Likewise.
Backported from <https://github.com/libffi/libffi/pull/861>.
|
|
No functional change intended.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.c: Use success_call_info
in a couple of places to avoid reimplementing get_desc.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
GCC currently supports outputting SARIF v2.1.0
Version 2.2 of the SARIF spec is not yet official, but the draft has
already gained features we might might want to use.
This patch extends the SARIF output code to accept a enum sarif_version
parameter internally, representing 2.1.0 or a prerelease of 2.2
The patch updates the SARIF output selftests so that they are run for
all such versions.
I hope to expose this "properly" via the mechanism described
in comment #13 of PR116613. In the meantime, the patch adds a new
-fdiagnostics-format=sarif-file-2.2-prerelease
for use by the DejaGnu testsuite, deliberately left undocumented for
now.
The copy of the 2.2 draft schema in the testsuite was downloaded from
https://raw.githubusercontent.com/oasis-tcs/sarif-spec/refs/tags/2.2-prerelease-2024-08-08/sarif-2.2/schema/sarif-2-2.schema.json
The patch adds support for capturing related locations within an ICE
notification for SARIF 2.2 onwards, thus capturing "include chain"
information for SARIF-based reports of ICEs that occur within a
header; see https://github.com/oasis-tcs/sarif-spec/issues/540
The patch does *not* add support for the "scannedFile" role, leaving it
to followup work; see https://github.com/oasis-tcs/sarif-spec/issues/459
gcc/ChangeLog:
PR other/116301
* common.opt (sarif-file-2.2-prerelease): New value for
-fdiagnostics-format=.
* diagnostic-format-sarif.cc
(sarif_location_manager::sarif_location_manager): Move
initialization of m_related_locations_arr here from sarif_result's
ctor.
(sarif_location_manager::add_related_location): Implement for
base class, taking sarif_result's implementation. Add "builder"
param.
(sarif_location_manager::m_related_locations_arr): Move here from
class sarif_result.
(class sarif_result): Move m_related_locations_arr field and
add_related_location vfunc to class sarif_location_manager.
(sarif_builder::get_version): New accessor.
(sarif_builder::m_version): New field.
(sarif_invocation::add_notification_for_ice): Call
process_worklist on the notification for SARIF 2.2 and later.
(sarif_location_manager::process_worklist_item): Pass builder to
calls to add_related_location.
(sarif_result::on_nested_diagnostic): Likewise.
(sarif_result::on_diagram): Likewise.
(sarif_ice_notification::add_related_location): Add builder param.
For SARIF 2.2 and later chain up to base class impl so that
notifications get related locations.
(sarif_builder::sarif_builder): Add "version" param.
(SARIF_SCHEMA): Delete in favor of...
(sarif_version_to_url): New function.
(SARIF_VERSION): Delete in favor of...
(sarif_version_to_property): New function.
(make_top_level_object): Update to use m_version for "$schema" and
"version".
(sarif_output_format::sarif_output_format): Add "version" param.
(sarif_stream_output_format::sarif_stream_output_format):
Likewise.
(sarif_file_output_format::sarif_file_output_format): Likewise.
(diagnostic_output_format_init_sarif_stderr): Likewise.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
(selftest::test_sarif_diagnostic_context): Likewise.
(selftest::test_make_location_object): Likewise.
(selftest::test_simple_log): Likewise. Update schema and version
tests accordingly.
(selftest::test_simple_log_2): Add "version" param.
(selftest::test_message_with_embedded_link): Likewise.
(selftest::run_tests_per_version): New, based on the
for_each_line_table_case calls in...
(selftest::diagnostic_format_sarif_cc_tests): Add loop over sarif
versions. Replace for_each_line_table_case calls with one
call to run_tests_per_version.
* diagnostic-format-sarif.h: Include "diagnostic-format.h".
(enum class sarif_version): New.
(diagnostic_output_format_init_sarif_stderr): Move to here from
diagnostic-format.h. Add "version" param.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
* diagnostic-format.h: Include "diagnostic.h".
(diagnostic_output_format_init_sarif_stderr): Move from here to
diagnostic-format-sarif.h.
* diagnostic.cc: Define INCLUDE_MEMORY.
Include "diagnostic-format-sarif.h".
(diagnostic_output_format_init): Pass sarif_version::v2_1_0 to
existing SARIF options.
Add case DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE.
* diagnostic.h (enum diagnostics_output_format): Add
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE_2_2_PRERELEASE.
gcc/testsuite/ChangeLog:
PR other/116301
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2.1.c: New test.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2.2.c: New test.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_1.py: Support
script for new test.
* gcc.dg/plugin/crash-test-ice-in-header-sarif-2_2.py: Likewise.
* gcc.dg/plugin/crash-test-ice-in-header.h: New header.
* gcc.dg/plugin/plugin.exp: Add the new tests.
* lib/sarif-schema-2.2-prerelease-2024-08-08.json: New schema
file.
* lib/scansarif.exp (verify-sarif-file): Add optional argument for
specifying which version of the schema to validate against,
supporting "2.1" and "2.2", defaulting to the former.
Update the test name to capture the version of the schema tested
against.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
the printer [PR116613]
As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), update diagnostic_show_locus
so that the pretty_printer must always be explicitly passed in.
No functional change intended.
gcc/c-family/ChangeLog:
PR other/116613
* c-format.cc (selftest::test_type_mismatch_range_labels):
Explicitly pass in dc.m_printer to diagnostic_show_locus.
gcc/ChangeLog:
PR other/116613
* diagnostic-show-locus.cc (diagnostic_context::maybe_show_locus):
Convert param "pp" from * to &. Drop logic for using the
context's m_printer when the param is null.
* diagnostic.h (diagnostic_context::maybe_show_locus): Convert
param "pp" from * to &.
(diagnostic_show_locus): Drop default "nullptr" value for pp
param. Assert that it and context are nonnull. Pass pp by
reference to maybe_show_locus.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/expensive_selftests_plugin.c (test_richloc):
Explicitly pass in dc.m_printer to diagnostic_show_locus.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), avoid passing around
diagnostic_context to the various printing routines, so that we
can be more explicit about which pretty_printer is in use.
Introduce a set of "policy" classes that capture the parts of
diagnostic_context that are needed, and use these rather than
diagnostic_context *. Pass around pretty_printer & rather than
taking value from context. Split out the pretty_printer-using code
from class layout into a new class layout_printer, separating the
responsibilities of determining layout when quoting source versus
actually printing the source.
No functional change intended.
gcc/analyzer/ChangeLog:
PR other/116613
* program-point.cc (function_point::print_source_line): Replace
call to diagnostic_show_locus with a call to
diagnostic_source_print_policy::print.
gcc/ChangeLog:
PR other/116613
* diagnostic-format-json.cc (json_from_expanded_location): Replace
call to diagnostic_context::converted_column with call to
diagnostic_column_policy::converted_column.
* diagnostic-format-sarif.cc
(sarif_builder::make_location_object): Replace call to
diagnostic_show_locus with call to
diagnostic_source_print_policy::print.
* diagnostic-format-text.cc (get_location_text): Replace call to
diagnostic_context::get_location_text with call to
diagnostic_column_policy::get_location_text.
(diagnostic_text_output_format::report_current_module): Replace call
to diagnostic_context::converted_column with call to
diagnostic_column_policy::converted_column.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_output_format):
Initialize m_column_policy.
(diagnostic_text_output_format::get_column_policy): New.
(diagnostic_text_output_format::m_column_policy): New.
* diagnostic-path.cc (class path_print_policy): New.
(event_range::maybe_add_event): Replace diagnostic_context param
with path_print_policy.
(event_range::print): Convert "pp" from * to &. Convert first
param of start_span callback from diagnostic_context to
diagnostic_location_print_policy.
(path_summary::path_summary): Convert first param from
diagnostic_text_output_format to path_print_policy. Add
colorize param. Update for changes to
event_range::maybe_add_event.
(thread_event_printer::print_swimlane_for_event_range): Assert
that pp is non-null. Update for change to event_range::print.
(diagnostic_text_output_format::print_path): Pass
path_print_policy to path_summary's ctor.
(selftest::test_empty_path): Likewise.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(selftest::assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
* diagnostic-show-locus.cc (colorizer::set_range): Update for
change to m_pp.
(colorizer::m_pp): Convert from * to &.
(class layout): Add friend class layout_printer and move various
decls to it.
(layout::m_pp): Drop field.
(layout::m_policy): Rename to...
(layout::m_char_policy): ...this.
(layout::m_colorizer): Move field to class layout_printer.
(layout::m_diagnostic_path_p): Drop field.
(class layout_printer): New class, by refactoring class layout.
(colorizer::colorizer): Convert "pp" param from * to &.
(colorizer::set_named_color): Update for above change.
(colorizer::begin_state): Likewise.
(colorizer::finish_state): Likewise.
(make_policy): Rename to...
(make_char_policy): ...this, and update param from
diagnostic_context to diagnostic_source_print_policy.
(layout::layout): Update param from diagnostic_context to
diagnostic_source_print_policy. Drop params "diagnostic_kind" and
"pp", moving these and other material to class layout_printer.
(layout::maybe_add_location_range): Update for renamed field.
(layout::print_gap_in_line_numbering): Convert to...
(layout_printer::print_gap_in_line_numbering): ...this.
(layout::calculate_x_offset_display): Update for renamed field.
(layout::print_source_line): Convert to...
(layout_printer::print_source_line): ...this.
(layout::print_leftmost_column): Convert to...
(layout_printer::print_leftmost_column): ...this.
(layout::start_annotation_line): Convert to...
(layout_printer::start_annotation_line): ...this.
(layout::print_annotation_line): Convert to...
(layout_printer::print_annotation_line): ...this.
(layout::print_any_labels): Convert to...
(layout_printer::print_any_labels): ...this.
(layout::print_leading_fixits): Convert to...
(layout_printer::print_leading_fixits): ...this.
(layout::print_trailing_fixits): Convert to...
(layout_printer::print_trailing_fixits): ...this.
(layout::print_newline): Convert to...
(layout_printer::print_newline): ...this.
(layout::get_state_at_point): Make const.
(layout::get_x_bound_for_row): Make const.
(layout::move_to_column): Convert to...
(layout_printer::move_to_column): ...this.
(layout::show_ruler): Convert to...
(layout_printer::show_ruler): ...this.
(layout::print_line): Convert to...
(layout_printer::print_line): ...this.
(layout::print_any_right_to_left_edge_lines): Convert to...
(layout_printer::print_any_right_to_left_edge_lines): ...this.
(layout::print_any_right_to_left_edge_lines): Likewise.
(layout_printer::layout_printer): New.
(layout::update_any_effects): Delete, moving logic to
layout_printer::print.
(gcc_rich_location::add_location_if_nearby): Update param from
diagnostic_context to diagnostic_source_print_policy. Add
overload taking a diagnostic_context.
(diagnostic_context::maybe_show_locus): Move handling of null
pretty_printer here, from layout ctor. Convert call to
diagnostic_context::show_locus to
diagnostic_source_print_policy::print.
(diagnostic_source_print_policy::diagnostic_source_print_policy):
New.
(diagnostic_context::show_locus): Convert to...
(diagnostic_source_print_policy::print): ...this. Convert pp
from * to &.
(layout_printer::print): New, based on material in
diagnostic_context::show_locus.
(selftest::make_char_policy): New.
(selftest::test_display_widths): Update for above changes.
(selftest::test_offset_impl): Likewise.
(selftest::test_layout_x_offset_display_utf8): Likewise.
(selftest::test_layout_x_offset_display_tab): Likewise.
(selftest::test_diagnostic_show_locus_unknown_location): Use
test_diagnostic_context::test_show_locus rather than
diagnostic_show_locus.
(selftest::test_one_liner_no_column): Likewise.
(selftest::test_one_liner_caret_and_range): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges): Likewise.
(selftest::test_one_liner_fixit_insert_before): Likewise.
(selftest::test_one_liner_fixit_insert_after): Likewise.
(selftest::test_one_liner_fixit_remove): Likewise.
(selftest::test_one_liner_fixit_replace): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations):
Likewise.
(selftest::test_one_liner_many_fixits_1): Likewise.
(selftest::test_one_liner_many_fixits_2): Likewise.
(selftest::test_one_liner_labels): Likewise.
(selftest::test_one_liner_simple_caret_utf8): Likewise.
(selftest::test_one_liner_caret_and_range_utf8): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges_utf8):
Likewise.
(selftest::test_one_liner_fixit_insert_before_utf8): Likewise.
(selftest::test_one_liner_fixit_insert_after_utf8): Likewise.
(selftest::test_one_liner_fixit_remove_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations_utf8):
Likewise.
(selftest::test_one_liner_many_fixits_1_utf8): Likewise.
(selftest::test_one_liner_many_fixits_2_utf8): Likewise.
(selftest::test_one_liner_labels_utf8): Likewise.
(selftest::test_one_liner_colorized_utf8): Likewise.
(selftest::test_add_location_if_nearby): Likewise.
(selftest::test_diagnostic_show_locus_fixit_lines): Likewise.
(selftest::test_overlapped_fixit_printing): Likewise.
(selftest::test_overlapped_fixit_printing_utf8): Likewise.
(selftest::test_overlapped_fixit_printing_2): Likewise.
(selftest::test_fixit_insert_containing_newline): Likewise.
(selftest::test_fixit_insert_containing_newline_2): Likewise.
(selftest::test_fixit_replace_containing_newline): Likewise.
(selftest::test_fixit_deletion_affecting_newline): Likewise.
(selftest::test_tab_expansion): Likewise.
(selftest::test_escaping_bytes_1): Likewise.
(selftest::test_escaping_bytes_2): Likewise.
(selftest::test_line_numbers_multiline_range): Likewise.
* diagnostic.cc
(diagnostic_column_policy::diagnostic_column_policy): New.
(diagnostic_context::converted_column): Convert to...
(diagnostic_column_policy::converted_column): ...this.
(diagnostic_context::get_location_text): Convert to...
(diagnostic_column_policy::get_location_text): ...this, adding
"show_column" param.
(diagnostic_location_print_policy::diagnostic_location_print_policy):
New ctors.
(default_diagnostic_start_span_fn): Convert param from
diagnostic_context * to const diagnostic_location_print_policy &.
Add "pp" param.
(selftest::assert_location_text): Update for above changes.
(selftest::test_diagnostic_get_location_text): Rename to...
(selftest::test_get_location_text): ...this.
(selftest::c_diagnostic_cc_tests): Update for renaming.
* diagnostic.h (class diagnostic_location_print_policy): New
forward decl.
(class diagnostic_source_print_policy): New forward decl.
(diagnostic_start_span_fn): Convert first param from
diagnostic_context * to const diagnostic_location_print_policy &
and add pretty_printer * param.
(class diagnostic_column_policy): New.
(class diagnostic_location_print_policy): New.
(class diagnostic_source_print_policy): New.
(class diagnostic_context): Add friend class
diagnostic_source_print_policy.
(diagnostic_context::converted_column): Drop decl in favor of
diagnostic_column_policy::converted_column.
(diagnostic_context::get_location_text): Drop decl in favor of
diagnostic_column_policy::get_location_text.
(diagnostic_context::show_locus): Drop decl in favor of
diagnostic_source_print_policy::print.
(default_diagnostic_start_span_fn): Update for change to
diagnostic_start_span_fn.
* gcc-rich-location.h (class diagnostic_source_print_policy): New
forward decl.
(gcc_rich_location::add_location_if_nearby): Convert first param
from diagnostic_context to diagnostic_source_print_policy. Add
overload taking diagnostic_context.
* selftest-diagnostic.cc
(selftest::test_diagnostic_context::test_diagnostic_context): Turn
off colorization.
(selftest::test_diagnostic_context::start_span_cb): Update for
change to callback type.
(test_diagnostic_context::test_show_locus): New.
* selftest-diagnostic.h
(selftest::test_diagnostic_context::start_span_cb): Update for
change to callback type.
(test_diagnostic_context::test_show_locus): New decl.
gcc/fortran/ChangeLog:
PR other/116613
* error.cc (gfc_diagnostic_build_locus_prefix): Convert first
param from diagnostic_context * to
const diagnostic_location_print_policy &. Add colorize param.
Likewise for the "two expanded_locations" overload.
(gfc_diagnostic_text_starter): Update for above changes.
(gfc_diagnostic_start_span): Update for change to callback type.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_diagnostic_start_span_fn): Update for change to callback
type.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
As work towards supporting multiple diagnostic outputs (where each
output has its own pretty_printer), avoid using diagnostic_context's
m_printer field. Instead, use the output format's printer. Currently
this *is* the dc's printer, but eventually it might not be.
No functional change intended.
gcc/ChangeLog:
PR other/116613
* diagnostic-format-json.cc (diagnostic_output_format_init_json):
Pass in the format. Use the format's printer when disabling
colorization. Move the call to set_output_format into here.
(diagnostic_output_format_init_json_stderr): Update for above
change.
(diagnostic_output_format_init_json_file): Likewise.
* diagnostic-format-sarif.cc
(diagnostic_output_format_init_sarif): Use the format's printer
when disabling colorization.
* diagnostic-path.cc (selftest::test_empty_path): Use the
text_output's printer.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(selftest::assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_output_format::on_begin_group): Use get_printer () rather
than accessing m_context.m_printer.
(test_output_format::on_end_group): Likewise.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c
(xhtml_builder::m_printer): New field.
(xhtml_builder::xhtml_builder): Add "pp" param and use it to
initialize m_printer.
(xhtml_builder::on_report_diagnostic): Drop "context" param.
(xhtml_builder::make_element_for_diagnostic): Likewise. Use
this->m_printer rather than the context's m_printer. Pass
m_printer to call to diagnostic_show_locus.
(xhtml_builder::emit_diagram): Drop "context" param.
(xhtml_output_format::on_report_diagnostic): Drop context param
from call to m_builder.
(xhtml_output_format::on_diagram): Likewise.
(xhtml_output_format::xhtml_output_format): Pass result of
get_printer as printer for builder.
(diagnostic_output_format_init_xhtml): Use the fmt's printer
rather than the context's.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Fix stray
reference to JSON.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
This patch adds an experimental diagnostics output format that
writes HTML. It isn't ready yet for end-users, but seems worth
keeping in the tree as I refactor the diagnostics subsystem, to
ensure that this code still builds, and to verify that it's possible to
implement new diagnostic output formats via GCC plugins. Hence
this patch merely adds it to the testsuite as an example of a GCC
plugin, rather than exposing it as a feature for end-users.
gcc/testsuite/ChangeLog:
PR other/116792
* gcc.dg/plugin/diagnostic-test-xhtml-1.c: New test.
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: New test plugin.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
The diagnostic_starter and diagnostic_finalizer callbacks and most of
their support subroutines are only used by the "text" output format.
Emphasize this and reduce the binding with diagnostic_context
by renaming the callbacks to add "_text" in their names, and converting
the first param from diagnostic_context * to
diagnostic_text_output_output &. Update the various subroutines used
by diagnostic starter/finalizer callbacks to also take a
diagnostic_text_output_output & rather than a diagnostic_context *.
Move m_includes and m_last_seen from the context to the text output.
Use the text_output's get_printer () rather than the context's
m_printer, which should ease the transition to multiple output sinks.
No functional change intended.
gcc/c-family/ChangeLog:
PR other/116613
* c-opts.cc: Include "diagnostic-format-text.h".
(c_diagnostic_finalizer): Rename to...
(c_diagnostic_text_finalizer): ...this. Convert first param
from diagnostic_context * to diagnostic_text_output_format & and
update accordingly.
(c_common_diagnostics_set_defaults): Update for renamings.
gcc/ChangeLog:
PR other/116613
* coretypes.h (class diagnostic_text_output_format): Add forward
decl.
* diagnostic-format-json.cc
(json_output_format::after_diagnostic): New.
* diagnostic-format-sarif.cc
(sarif_output_format::after_diagnostic): New.
* diagnostic-format-text.cc: Use pragmas to ignore -Wformat-diag.
(diagnostic_text_output_format::~diagnostic_text_output_format):
Use get_printer. Clean up m_includes_seen here, rather than
in ~diagnostic_context.
(diagnostic_text_output_format::on_report_diagnostic): Use
get_printer. Update for callback renamings and pass *this
to them, rather than &m_context.
(diagnostic_text_output_format::after_diagnostic): New.
(diagnostic_text_output_format::includes_seen_p): Move here
from diagnostic_context/diagnostic.cc.
(diagnostic_text_output_format::get_location_text): New.
(maybe_line_and_column): Move here from diagnostic.cc and make
non-static.
(diagnostic_text_output_format::report_current_module): Move
here from diagnostic_context/diagnostic.cc.
(default_diagnostic_text_starter): Move here from diagnostic.cc,
renaming from default_diagnostic_starter.
(default_diagnostic_text_finalizer): Likewise, renaming from
default_diagnostic_finalizer.
* diagnostic-format-text.h
(diagnostic_text_output_format::diagnostic_text_output_format):
Initialize m_last_module and m_includes_seen.
(diagnostic_text_output_format::after_diagnostic): New decl.
(diagnostic_text_output_format::build_prefix): New decl.
(diagnostic_text_output_format::report_current_module): New decl.
(diagnostic_text_output_format::append_note): New decl.
(diagnostic_text_output_format::file_name_as_prefix): New decl.
(diagnostic_text_output_format::print_path): New decl.
(diagnostic_text_output_format::show_column_p): New decl.
(diagnostic_text_output_format::get_location_text): New decl.
(diagnostic_text_output_format::includes_seen_p): New decl.
(diagnostic_text_output_format::show_any_path): New decl.
(diagnostic_text_output_format::m_last_module): New field.
(diagnostic_text_output_format::m_includes_seen): New field.
* diagnostic-format.h
(diagnostic_output_format::after_diagnostic): New vfunc.
(diagnostic_output_format::get_context): New.
(diagnostic_output_format::get_diagram_theme): New.
* diagnostic-macro-unwinding.cc: Include
"diagnostic-format-text.h".
(maybe_unwind_expanded_macro_loc): Convert first param from
diagnostic_context * to diagnostic_text_output_format & and update
accordingly.
(virt_loc_aware_diagnostic_finalizer): Likewise.
* diagnostic-macro-unwinding.h
(virt_loc_aware_diagnostic_finalizer): Likewise.
(maybe_unwind_expanded_macro_loc): Likewise.
* diagnostic-path.cc: Include "diagnostic-format-text.h".
(path_label::path_label): Drop "ctxt" param and add "colorize"
and "allow_emojis" params. Update initializations.
(path_label::get_text): Use m_colorize rather than querying
m_ctxt.m_printer. Use m_allow_emojis rather than querying
m_ctxt's diagram theme.
(path_label::m_ctxt): Drop field.
(path_label::m_colorize): Drop field.
(path_label::m_allow_emojis): Drop field.
(event_range::event_range): Drop param "ctxt". Add params
"colorize_labels" and "allow_emojis".
(event_range::print): Convert first param from
diagnostic_context & to diagnostic_text_output_format & and update
accordingly.
(path_summary::path_summary): Likewise.
(path_summary::print_swimlane_for_event_range): Likewise.
(print_path_summary_as_text): Likewise for 3rd param.
(diagnostic_context::print_path): Convert to...
(diagnostic_text_output_format::print_path): ...this.
(selftest::test_empty_path): Update to use a
diagnostic_text_output_format.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(selftest::assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
* diagnostic.cc (file_name_as_prefix): Convert to...
(diagnostic_text_output_format::file_name_as_prefix): ...this.
(diagnostic_context::initialize): Update for renamings.
Move m_last_module and m_includes_seen into text output.
(diagnostic_context::finish): Likewise.
(diagnostic_context::get_location_text): Add "colorize" param.
(diagnostic_build_prefix): Convert to...
(diagnostic_text_output_format::build_prefix): ...this.
(diagnostic_context::includes_seen_p): Move from here to
diagnostic_text_output_format/diagnostic-format-text.cc.
(diagnostic_context::report_current_module): Likewise.
(diagnostic_context::show_any_path): Convert to...
(diagnostic_text_output_format::show_any_path): ...this.
(default_diagnostic_starter): Rename and move to
diagnostic-format-text.cc.
(default_diagnostic_start_span_fn): Pass colorize bool
to get_location_text.
(default_diagnostic_finalizer): Rename and move to
diagnostic-format-text.cc.
(diagnostic_context::report_diagnostic): Replace call to
show_any_path with call to new output format "after_diagnostic"
vfunc, moving show_any_path call to the text output format.
(diagnostic_append_note): Convert to...
(diagnostic_text_output_format::append_note): ...this.
(selftest::assert_location_text): Pass in false for colorization.
* diagnostic.h (diagnostic_starter_fn): Rename to...
(diagnostic_text_starter_fn): ...this. Convert first param from
diagnostic_context * to diagnostic_text_output_format &.
(diagnostic_finalizer_fn, diagnostic_text_finalizer_fn): Likewise.
(diagnostic_context): Update friends for renamings.
(diagnostic_context::report_current_module): Move to text output
format.
(diagnostic_context::get_location_text): Add "colorize" bool.
(diagnostic_context::includes_seen_p): Move to text output format.
(diagnostic_context::show_any_path): Likewise.
(diagnostic_context::print_path): Likewise.
(diagnostic_context::m_text_callbacks): Update for renamings.
(diagnostic_context::m_last_module): Move to text output format.
(diagnostic_context::m_includes_seen): Likewise.
(diagnostic_starter): Rename to...
(diagnostic_text_starter): ...this and update return type.
(diagnostic_finalizer): Rename to...
(diagnostic_text_finalizer): ...this and update return type.
(diagnostic_report_current_module): Drop decl in favor of a member
function of diagnostic_text_output_format.
(diagnostic_append_note): Likewise.
(default_diagnostic_starter): Rename to...
(default_diagnostic_text_starter): ...this, updating type.
(default_diagnostic_finalizer): Rename to...
(default_diagnostic_text_finalizer): ...this, updating type.
(file_name_as_prefix): Drop decl.
* langhooks-def.h (lhd_print_error_function): Convert first param
from diagnostic_context * to diagnostic_text_output_format &.
* langhooks.cc: Include "diagnostic-format-text.h".
(lhd_print_error_function): Likewise. Update accordingly
* langhooks.h (lang_hooks::print_error_function): Convert first
param from diagnostic_context * to
diagnostic_text_output_format &.
* tree-diagnostic.cc: Include "diagnostic-format-text.h".
(diagnostic_report_current_function): Convert first param from
diagnostic_context * to diagnostic_text_output_format & and update
accordingly.
(default_tree_diagnostic_starter): Rename to...
(default_tree_diagnostic_text_starter): ...this. Convert first
param from diagnostic_context * to diagnostic_text_output_format &
and update accordingly.
(tree_diagnostics_defaults): Update for renamings.
gcc/cp/ChangeLog:
PR other/116613
* cp-tree.h (cxx_print_error_function): Convert first param
from diagnostic_context * to diagnostic_text_output_format &.
* error.cc: Include "diagnostic-format-text.h".
(cxx_initialize_diagnostics): Update for renamings.
(cxx_print_error_function): Convert first param from
diagnostic_context * to diagnostic_text_output_format & and update
accordingly
(cp_diagnostic_starter): Rename to...
(cp_diagnostic_text_starter): ...this. Convert first
param from diagnostic_context * to diagnostic_text_output_format &
and update accordingly.
(cp_print_error_function): Likewise.
(print_instantiation_full_context): Likewise.
(print_instantiation_partial_context_line): Likewise.
(print_instantiation_partial_context): Likewise.
(maybe_print_instantiation_context): Likewise.
(maybe_print_constexpr_context): Likewise.
(print_location): Likewise.
(print_constrained_decl_info): Likewise.
(print_concept_check_info): Likewise.
(print_constraint_context_head): Likewise.
(print_requires_expression_info): Likewise.
(maybe_print_single_constraint_context): Likewise.
gcc/fortran/ChangeLog:
PR other/116613
* error.cc: Include "diagnostic-format-text.h".
(gfc_diagnostic_starter): Rename to...
(gfc_diagnostic_text_starter): ...this. Convert first
param from diagnostic_context * to diagnostic_text_output_format &
and update accordingly.
(gfc_diagnostic_finalizer, gfc_diagnostic_text_finalizer):
Likewise.
(gfc_diagnostics_init): Update for renamings.
(gfc_diagnostics_finish): Likewise.
gcc/jit/ChangeLog:
PR other/116613
* dummy-frontend.cc: Include "diagnostic-format-text.h".
(jit_begin_diagnostic): Convert first param from
diagnostic_context * to diagnostic_text_output_format &
(jit_end_diagnostic): Likewise. Update accordingly.
(jit_langhook_init): Update for renamings.
gcc/rust/ChangeLog:
PR other/116613
* resolve/rust-ast-resolve-expr.cc
(funny_ice_finalizer): : Convert first param from
diagnostic_context * to diagnostic_text_output_format &.
(ResolveExpr::visit): Update for renaming.
gcc/testsuite/ChangeLog:
PR other/116613
* g++.dg/plugin/show_template_tree_color_plugin.c
(noop_starter_fn): Rename to...
(noop_text_starter_fn): ...this. Update first param from dc to
text_output.
(plugin_init): Update for renamings.
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_diagnostic_starter): Rename to...
(test_diagnostic_text_starter): ...this. Update first param from
dc to text_output.
(plugin_init): Update for renaming.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Include
"diagnostic-format-text.h".
(custom_diagnostic_finalizer): Rename to...
(custom_diagnostic_text_finalizer): ...this. Update first param
from dc to text_output.
(test_show_locus): Update for renamings.
* gcc.dg/plugin/location_overflow_plugin.c: Include
"diagnostic-format-text.h".
(original_finalizer): Rename to...
(original_text_finalizer): ...this and update type.
(verify_unpacked_ranges): Update first param from dc to
text_output. Update for this and for renamings.
(verify_no_columns): Likewise.
(plugin_init): Update for renamings.
libcc1/ChangeLog:
PR other/116613
* context.cc: Include "diagnostic-format-text.h".
(plugin_print_error_function): Update first param from
diagnostic_context * to diagnostic_text_output_format &.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Rename diagnostic_context's "printer" field to "m_printer",
for consistency with other fields, and to highlight places
where we currently use this, to help assess feasibility
of supporting multiple output sinks (PR other/116613).
No functional change intended.
gcc/ChangeLog:
PR other/116613
* attribs.cc (decls_mismatched_attributes): Rename
diagnostic_context's "printer" field to "m_printer".
(attr_access::array_as_string): Likewise.
* diagnostic-format-json.cc
(json_output_format::on_report_diagnostic): Likewise.
(diagnostic_output_format_init_json): Likewise.
* diagnostic-format-sarif.cc
(sarif_result::on_nested_diagnostic): Likewise.
(sarif_ice_notification): Likewise.
(sarif_builder::on_report_diagnostic): Likewise.
(sarif_builder::make_result_object): Likewise.
(sarif_builder::make_location_object): Likewise.
(sarif_builder::make_message_object_for_diagram): Likewise.
(diagnostic_output_format_init_sarif): Likewise.
* diagnostic-format-text.cc
(diagnostic_text_output_format::~diagnostic_text_output_format):
Likewise.
(diagnostic_text_output_format::on_report_diagnostic): Likewise.
(diagnostic_text_output_format::on_diagram): Likewise.
(diagnostic_text_output_format::print_any_cwe): Likewise.
(diagnostic_text_output_format::print_any_rules): Likewise.
(diagnostic_text_output_format::print_option_information):
Likewise.
* diagnostic-format.h (diagnostic_output_format::get_printer):
New.
* diagnostic-global-context.cc (verbatim): Rename
diagnostic_context's "printer" field to "m_printer".
* diagnostic-path.cc (path_label::get_text): Likewise.
(print_path_summary_as_text): Likewise.
(diagnostic_context::print_path): Likewise.
(selftest::test_empty_path): Likewise.
(selftest::test_intraprocedural_path): Likewise.
(selftest::test_interprocedural_path_1): Likewise.
(selftest::test_interprocedural_path_2): Likewise.
(selftest::test_recursion): Likewise.
(selftest::test_control_flow_1): Likewise.
(selftest::test_control_flow_2): Likewise.
(selftest::test_control_flow_3): Likewise.
(assert_cfg_edge_path_streq): Likewise.
(selftest::test_control_flow_5): Likewise.
(selftest::test_control_flow_6): Likewise.
* diagnostic-show-locus.cc (layout::layout): Likewise.
(selftest::test_layout_x_offset_display_utf8): Likewise.
(selftest::test_layout_x_offset_display_tab): Likewise.
(selftest::test_diagnostic_show_locus_unknown_location): Likewise.
(selftest::test_one_liner_simple_caret): Likewise.
(selftest::test_one_liner_no_column): Likewise.
(selftest::test_one_liner_caret_and_range): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges): Likewise.
(selftest::test_one_liner_fixit_insert_before): Likewise.
(selftest::test_one_liner_fixit_insert_after): Likewise.
(selftest::test_one_liner_fixit_remove): Likewise.
(selftest::test_one_liner_fixit_replace): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations):
Likewise.
(selftest::test_one_liner_many_fixits_1): Likewise.
(selftest::test_one_liner_many_fixits_2): Likewise.
(selftest::test_one_liner_labels): Likewise.
(selftest::test_one_liner_simple_caret_utf8): Likewise.
(selftest::test_one_liner_caret_and_range_utf8): Likewise.
(selftest::test_one_liner_multiple_carets_and_ranges_utf8):
Likewise.
(selftest::test_one_liner_fixit_insert_before_utf8): Likewise.
(selftest::test_one_liner_fixit_insert_after_utf8): Likewise.
(selftest::test_one_liner_fixit_remove_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_utf8): Likewise.
(selftest::test_one_liner_fixit_replace_non_equal_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_replace_equal_secondary_range_utf8):
Likewise.
(selftest::test_one_liner_fixit_validation_adhoc_locations_utf8):
Likewise.
(selftest::test_one_liner_many_fixits_1_utf8): Likewise.
(selftest::test_one_liner_many_fixits_2_utf8): Likewise.
(selftest::test_one_liner_labels_utf8): Likewise.
(selftest::test_one_liner_colorized_utf8): Likewise.
(selftest::test_add_location_if_nearby): Likewise.
(selftest::test_diagnostic_show_locus_fixit_lines): Likewise.
(selftest::test_overlapped_fixit_printing): Likewise.
(selftest::test_overlapped_fixit_printing_utf8): Likewise.
(selftest::test_overlapped_fixit_printing_2): Likewise.
(selftest::test_fixit_insert_containing_newline): Likewise.
(selftest::test_fixit_insert_containing_newline_2): Likewise.
(selftest::test_fixit_replace_containing_newline): Likewise.
(selftest::test_fixit_deletion_affecting_newline): Likewise.
(selftest::test_tab_expansion): Likewise.
(selftest::test_escaping_bytes_1): Likewise.
(selftest::test_escaping_bytes_2): Likewise.
(selftest::test_line_numbers_multiline_range): Likewise.
* diagnostic.cc (file_name_as_prefix): Likewise.
(diagnostic_set_caret_max_width): Likewise.
(diagnostic_context::initialize): Likewise.
(diagnostic_context::color_init): Likewise.
(diagnostic_context::urls_init): Likewise.
(diagnostic_context::finish): Likewise.
(diagnostic_context::get_location_text): Likewise.
(diagnostic_build_prefix): Likewise.
(diagnostic_context::report_current_module): Likewise.
(default_diagnostic_starter): Likewise.
(default_diagnostic_start_span_fn): Likewise.
(default_diagnostic_finalizer): Likewise.
(diagnostic_context::report_diagnostic): Likewise.
(diagnostic_append_note): Likewise.
(diagnostic_context::error_recursion): Likewise.
(fancy_abort): Likewise.
* diagnostic.h (diagnostic_context::set_show_highlight_colors):
Likewise.
(diagnostic_context::printer): Rename to...
(diagnostic_context::m_printer): ...this.
(diagnostic_format_decoder): Rename diagnostic_context's "printer"
field to "m_printer".
(diagnostic_prefixing_rule): Likewise.
(diagnostic_ready_p): Likewise.
* gimple-ssa-warn-access.cc (pass_waccess::maybe_warn_memmodel):
Likewise.
* langhooks.cc (lhd_print_error_function): Likewise.
* lto-wrapper.cc (print_lto_docs_link): Likewise.
* opts-global.cc (init_options_once): Likewise.
* opts.cc (common_handle_option): Likewise.
* simple-diagnostic-path.cc (simple_diagnostic_path_cc_tests):
Likewise.
* text-art/dump.h (dump_to_file<T>): Likewise.
* toplev.cc (announce_function): Likewise.
(toplev::main): Likewise.
* tree-diagnostic.cc (default_tree_diagnostic_starter): Likewise.
* tree.cc (escaped_string::escape): Likewise.
(selftest::test_escaped_strings): Likewise.
gcc/ada/ChangeLog:
PR other/116613
* gcc-interface/misc.cc (internal_error_function): Rename
diagnostic_context's "printer" field to "m_printer".
gcc/analyzer/ChangeLog:
PR other/116613
* access-diagram.cc (access_range::dump): Rename
diagnostic_context's "printer" field to "m_printer".
* analyzer-language.cc (on_finish_translation_unit): Likewise.
* analyzer.cc (make_label_text): Likewise.
(make_label_text_n): Likewise.
* call-details.cc (call_details::dump): Likewise.
* call-summary.cc (call_summary::dump): Likewise.
(call_summary_replay::dump): Likewise.
* checker-event.cc (checker_event::debug): Likewise.
* constraint-manager.cc (range::dump): Likewise.
(bounded_range::dump): Likewise.
(bounded_ranges::dump): Likewise.
(constraint_manager::dump): Likewise.
* diagnostic-manager.cc
(diagnostic_manager::emit_saved_diagnostic): Likewise.
* engine.cc (exploded_node::dump): Likewise.
(exploded_path::dump): Likewise.
(run_checkers): Likewise.
* kf-analyzer.cc (kf_analyzer_dump_escaped::impl_call_pre):
Likewise.
* pending-diagnostic.cc (evdesc::event_desc::formatted_print):
Likewise.
* program-point.cc (function_point::print_source_line): Likewise.
(program_point::dump): Likewise.
* program-state.cc (extrinsic_state::dump_to_file): Likewise.
(sm_state_map::dump): Likewise.
(program_state::dump_to_file): Likewise.
* ranges.cc (symbolic_byte_offset::dump): Likewise.
(symbolic_byte_range::dump): Likewise.
* region-model-reachability.cc (reachable_regions::dump): Likewise.
* region-model.cc (region_to_value_map::dump): Likewise.
(region_model::dump): Likewise.
(model_merger::dump): Likewise.
* region.cc (region_offset::dump): Likewise.
(region::dump): Likewise.
* sm-malloc.cc (deallocator_set::dump): Likewise.
(sufficiently_similar_p): Likewise.
* store.cc (uncertainty_t::dump): Likewise.
(binding_key::dump): Likewise.
(binding_map::dump): Likewise.
(binding_cluster::dump): Likewise.
(store::dump): Likewise.
* supergraph.cc (supergraph::dump_dot_to_file): Likewise.
(superedge::dump): Likewise.
* svalue.cc (svalue::dump): Likewise.
gcc/c-family/ChangeLog:
PR other/116613
* c-format.cc (selftest::test_type_mismatch_range_labels): Rename
diagnostic_context's "printer" field to "m_printer".
(selftest::test_type_mismatch_range_labels): Likewise.
* c-opts.cc (c_diagnostic_finalizer): Likewise.
gcc/c/ChangeLog:
PR other/116613
* c-objc-common.cc (c_initialize_diagnostics): Rename
diagnostic_context's "printer" field to "m_printer".
gcc/cp/ChangeLog:
PR other/116613
* error.cc (cxx_initialize_diagnostics): Rename
diagnostic_context's "printer" field to "m_printer".
(cxx_print_error_function): Likewise.
(cp_diagnostic_starter): Likewise.
(cp_print_error_function): Likewise.
(print_instantiation_full_context): Likewise.
(print_instantiation_partial_context_line): Likewise.
(maybe_print_constexpr_context): Likewise.
(print_location): Likewise.
(print_constrained_decl_info): Likewise.
(print_concept_check_info): Likewise.
(print_constraint_context_head): Likewise.
(print_requires_expression_info): Likewise.
* module.cc (noisy_p): Likewise.
gcc/d/ChangeLog:
PR other/116613
* d-diagnostic.cc (d_diagnostic_report_diagnostic): Rename
diagnostic_context's "printer" field to "m_printer".
gcc/fortran/ChangeLog:
PR other/116613
* error.cc (gfc_clear_pp_buffer): Rename diagnostic_context's
"printer" field to "m_printer".
(gfc_warning): Likewise.
(gfc_diagnostic_build_kind_prefix): Likewise.
(gfc_diagnostic_build_locus_prefix): Likewise.
(gfc_diagnostic_starter): Likewise.
(gfc_diagnostic_starter): Likewise.
(gfc_diagnostic_start_span): Likewise.
(gfc_diagnostic_finalizer): Likewise.
(gfc_warning_check): Likewise.
(gfc_error_opt): Likewise.
(gfc_error_check): Likewise.
gcc/jit/ChangeLog:
PR other/116613
* jit-playback.cc (add_diagnostic): Rename diagnostic_context's
"printer" field to "m_printer".
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/analyzer_cpython_plugin.c (dump_refcnt_info):
Update for renaming of field "printer" to "m_printer".
* gcc.dg/plugin/diagnostic_group_plugin.c
(test_diagnostic_starter): Likewise.
(test_diagnostic_start_span_fn): Likewise.
(test_output_format::on_begin_group): Likewise.
(test_output_format::on_end_group): Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(custom_diagnostic_finalizer): Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
We were using
https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json
as the URL for the SARIF 2.1 schema, but this is now a 404.
Update it to the URL listed in the spec (§3.13.3 "$schema property"),
which is:
https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json
and update the copy in
gcc/testsuite/lib/sarif-schema-2.1.0.json
used by the "verify-sarif-file" DejaGnu directive to the version found at
that latter URL; the sha256 sum changes
from: 2b19d2358baef0251d7d24e208d05ffabf1b2a3ab5e1b3a816066fc57fd4a7e8
to: c3b4bb2d6093897483348925aaa73af03b3e3f4bd4ca38cef26dcb4212a2682e
Doing so added a validation error on
c-c++-common/diagnostic-format-sarif-file-pr111700.c
for which we emit this textual output:
this-file-does-not-exist.c: warning: #warning message [-Wcpp]
with no line number, and these invalid SARIF regions within the
physical location of the warning:
"region": {"startColumn": 2,
"endColumn": 9},
"contextRegion": {}
This is due to this directive:
# 0 "this-file-does-not-exist.c"
with line number 0.
The patch fixes this by not creating regions that have startLine <= 0.
gcc/ChangeLog:
PR other/116603
* diagnostic-format-sarif.cc (SARIF_SCHEMA): Update URL.
(sarif_builder::maybe_make_region_object): Don't create regions
with startLine <= 0.
(sarif_builder::maybe_make_region_object_for_context): Likewise.
gcc/testsuite/ChangeLog:
PR other/116603
* gcc.dg/plugin/diagnostic-test-metadata-sarif.py (test_basics):
Update expected schema URL.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py:
Likewise.
* gcc.dg/sarif-output/test-include-chain-1.py: Likewise.
* gcc.dg/sarif-output/test-include-chain-2.py: Likewise.
* gcc.dg/sarif-output/test-missing-semicolon.py: Likewise.
* gcc.dg/sarif-output/test-no-diagnostics.py: Likewise.
* gcc.dg/sarif-output/test-werror.py: Likewise.
* lib/sarif-schema-2.1.0.json: Update with copy downloaded from
https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
As preliminary work towards an overhaul of how optinfo_items
interact with dump_pretty_printer, replace uses of optinfo_item * with
std::unique_ptr<optinfo_item> to make ownership clearer.
No functional change intended.
gcc/ChangeLog:
* config/aarch64/aarch64.cc: Define INCLUDE_MEMORY.
* config/arm/arm.cc: Likewise.
* config/i386/i386.cc: Likewise.
* config/loongarch/loongarch.cc: Likewise.
* config/riscv/riscv-vector-costs.cc: Likewise.
* config/riscv/riscv.cc: Likewise.
* config/rs6000/rs6000.cc: Likewise.
* dump-context.h (dump_context::emit_item): Convert "item" param
from * to const &.
(dump_pretty_printer::stash_item): Convert "item" param from
optinfo_ * to std::unique_ptr<optinfo_item>.
(dump_pretty_printer::emit_item): Likewise.
* dumpfile.cc: Include "make-unique.h".
(make_item_for_dump_gimple_stmt): Replace uses of optinfo_item *
with std::unique_ptr<optinfo_item>.
(dump_context::dump_gimple_stmt): Likewise.
(make_item_for_dump_gimple_expr): Likewise.
(dump_context::dump_gimple_expr): Likewise.
(make_item_for_dump_generic_expr): Likewise.
(dump_context::dump_generic_expr): Likewise.
(make_item_for_dump_symtab_node): Likewise.
(dump_pretty_printer::emit_items): Likewise.
(dump_pretty_printer::emit_any_pending_textual_chunks): Likewise.
(dump_pretty_printer::emit_item): Likewise.
(dump_pretty_printer::stash_item): Likewise.
(dump_pretty_printer::decode_format): Likewise.
(dump_context::dump_printf_va): Fix overlong line.
(make_item_for_dump_dec): Replace uses of optinfo_item * with
std::unique_ptr<optinfo_item>.
(dump_context::dump_dec): Likewise.
(dump_context::dump_symtab_node): Likewise.
(dump_context::begin_scope): Likewise.
(dump_context::emit_item): Likewise.
* gimple-loop-interchange.cc: Define INCLUDE_MEMORY.
* gimple-loop-jam.cc: Likewise.
* gimple-loop-versioning.cc: Likewise.
* graphite-dependences.cc: Likewise.
* graphite-isl-ast-to-gimple.cc: Likewise.
* graphite-optimize-isl.cc: Likewise.
* graphite-poly.cc: Likewise.
* graphite-scop-detection.cc: Likewise.
* graphite-sese-to-poly.cc: Likewise.
* graphite.cc: Likewise.
* opt-problem.cc: Likewise.
* optinfo.cc (optinfo::add_item): Convert "item" param from
optinfo_ * to std::unique_ptr<optinfo_item>.
(optinfo::emit_for_opt_problem): Update for change to
dump_context::emit_item.
* optinfo.h: Add #error to fail immediately if INCLUDE_MEMORY
wasn't defined, rather than fail to find std::unique_ptr.
(optinfo::add_item): Convert "item" param from optinfo_ * to
std::unique_ptr<optinfo_item>.
* sese.cc: Define INCLUDE_MEMORY.
* targhooks.cc: Likewise.
* tree-data-ref.cc: Likewise.
* tree-if-conv.cc: Likewise.
* tree-loop-distribution.cc: Likewise.
* tree-parloops.cc: Likewise.
* tree-predcom.cc: Likewise.
* tree-ssa-live.cc: Likewise.
* tree-ssa-loop-ivcanon.cc: Likewise.
* tree-ssa-loop-ivopts.cc: Likewise.
* tree-ssa-loop-prefetch.cc: Likewise.
* tree-ssa-loop-unswitch.cc: Likewise.
* tree-ssa-phiopt.cc: Likewise.
* tree-ssa-threadbackward.cc: Likewise.
* tree-ssa-threadupdate.cc: Likewise.
* tree-vect-data-refs.cc: Likewise.
* tree-vect-generic.cc: Likewise.
* tree-vect-loop-manip.cc: Likewise.
* tree-vect-loop.cc: Likewise.
* tree-vect-patterns.cc: Likewise.
* tree-vect-slp-patterns.cc: Likewise.
* tree-vect-slp.cc: Likewise.
* tree-vect-stmts.cc: Likewise.
* tree-vectorizer.cc: Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/dump_plugin.c: Define INCLUDE_MEMORY.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
In particular, move the classic text output code to a
diagnostic-text.cc (analogous to -json.cc and -sarif.cc).
No functional change intended.
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add diagnostic-format-text.o.
* diagnostic-format-json.cc: Include "diagnostic-format.h".
* diagnostic-format-sarif.cc: Likewise.
* diagnostic-format-text.cc: New file, using material from
diagnostics.cc.
* diagnostic-global-context.cc: Include
"diagnostic-format.h".
* diagnostic-format-text.h: New file, using material from
diagnostics.h.
* diagnostic-format.h: New file, using material from
diagnostics.h.
* diagnostic.cc: Include "diagnostic-format.h" and
"diagnostic-format-text.h".
(diagnostic_text_output_format::~diagnostic_text_output_format):
Move to diagnostic-format-text.cc.
(diagnostic_text_output_format::on_report_diagnostic): Likewise.
(diagnostic_text_output_format::on_diagram): Likewise.
(diagnostic_text_output_format::print_any_cwe): Likewise.
(diagnostic_text_output_format::print_any_rules): Likewise.
(diagnostic_text_output_format::print_option_information):
Likewise.
* diagnostic.h (class diagnostic_output_format): Move to
diagnostic-format.h.
(class diagnostic_text_output_format): Move to
diagnostic-format-text.h.
(diagnostic_output_format_init): Move to
diagnostic-format.h.
(diagnostic_output_format_init_json_stderr): Likewise.
(diagnostic_output_format_init_json_file): Likewise.
(diagnostic_output_format_init_sarif_stderr): Likewise.
(diagnostic_output_format_init_sarif_file): Likewise.
(diagnostic_output_format_init_sarif_stream): Likewise.
* gcc.cc: Include "diagnostic-format.h".
* opts.cc: Include "diagnostic-format.h".
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic_group_plugin.c: Include
"diagnostic-format-text.h".
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Add test coverage of "%@" in event messages in a multithreaded
execution path.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-inline-events.c:
Update expected output.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py:
Likewise.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-separate-events.c:
Likewise.
* gcc.dg/plugin/diagnostic_plugin_test_paths.c
(test_diagnostic_path::add_event_2): Return the id of the added
event.
(test_diagnostic_path::add_event_2_with_event_id): New.
(example_4): Add event IDs to the deadlock messages indicating
where the locks where acquired.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
In r15-2354-g4d1f71d49e396c I added the ability to use Python to write
tests of SARIF output via a new "run-sarif-pytest" based
on "run-gcov-pytest", with a sarif.py support script in
testsuite/gcc.dg/sarif-output.
This followup patch:
(a) removes the limitation of such tests needing to be in
testsuite/gcc.dg/sarif-output by moving sarif.py to testsuite/lib
and adding logic to add that directory to PYTHONPATH when invoking
pytest.
(b) uses this to replace fragile regexp-based tests in
gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.c with
Python logic that verifies the structure within the generated JSON,
and to add test coverage for SARIF output relating to GCC plugins.
gcc/ChangeLog:
* diagnostic-format-sarif.cc: Add comments noting that we don't
yet capture any diagnostic_metadata::rules associated with a
diagnostic.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-metadata-sarif.c: New test,
based on diagnostic-test-metadata.c.
* gcc.dg/plugin/diagnostic-test-metadata-sarif.py: New script.
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.c:
Replace scan-sarif-file directives with run-sarif-pytest, to
run...
* gcc.dg/plugin/diagnostic-test-paths-multithreaded-sarif.py:
...this new test.
* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
diagnostic-test-metadata-sarif.c.
* gcc.dg/sarif-output/sarif.py: Move to...
* lib/sarif.py: ...here.
* lib/scansarif.exp (run-sarif-pytest): Prepend "lib" to
PYTHONPATH before running python scripts.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
(§3.3.4)
This patch adds support to our SARIF output for cases where
rich_loc.escape_on_output_p () is true, such as for -Wbidi-chars.
In such cases, the pertinent SARIF "location" object gains a property
bag with property "gcc/escapeNonAscii": true, and the "artifactContent"
within the location's physical location's snippet" gains a "rendered"
property (§3.3.4) that escapes non-ASCII text in the snippet, such as:
"rendered": {"text":
where "text" has a string value such as (for a "trojan source" attack):
"9 | /*<U+202E> } <U+2066>if (isAdmin)<U+2069> <U+2066> begin admins only */\n"
" | ~~~~~~~~ ~~~~~~~~ ^\n"
" | | | |\n"
" | | | end of bidirectional context\n"
" | U+202E (RIGHT-TO-LEFT OVERRIDE) U+2066 (LEFT-TO-RIGHT ISOLATE)\n"
where the escaping is affected by -fdiagnostics-escape-format=; with
-fdiagnostics-escape-format=bytes, the rendered text of the above is:
"9 | /*<e2><80><ae> } <e2><81><a6>if (isAdmin)<e2><81><a9> <e2><81><a6> begin admins only */\n"
" | ~~~~~~~~~~~~ ~~~~~~~~~~~~ ^\n"
" | | | |\n"
" | U+202E (RIGHT-TO-LEFT OVERRIDE) U+2066 (LEFT-TO-RIGHT ISOLATE) end of bidirectional context\n"
The patch also refactors/adds enough selftest machinery to be able to
test the snippet generation from within the selftest framework, rather
than just within DejaGnu (where the regex-based testing isn't
sophisticated enough to verify such properties as the above).
gcc/ChangeLog:
* Makefile.in (OBJS-libcommon): Add selftest-json.o.
* diagnostic-format-sarif.cc: Include "selftest.h",
"selftest-diagnostic.h", "selftest-diagnostic-show-locus.h",
"selftest-json.h", and "text-range-label.h".
(class content_renderer): New.
(sarif_builder::m_rules_arr): Convert to std::unique_ptr.
(sarif_builder::make_location_object): Add class
escape_nonascii_renderer. If rich_loc.escape_on_output_p (),
pass a nonnull escape_nonascii_renderer to
maybe_make_physical_location_object as its snippet_renderer, and
add a property bag property "gcc/escapeNonAscii" to the SARIF
location object. For other overloads of make_location_object,
pass nullptr for the snippet_renderer.
(sarif_builder::maybe_make_region_object_for_context): Add
"snippet_renderer" param and pass it to
maybe_make_artifact_content_object.
(sarif_builder::make_tool_object): Drop "const".
(sarif_builder::make_driver_tool_component_object): Likewise.
Use typesafe unique_ptr variant of object::set for setting "rules"
property on driver_obj.
(sarif_builder::maybe_make_artifact_content_object): Add param "r"
and use it to potentially set the "rendered" property (§3.3.4).
(selftest::test_make_location_object): New.
(selftest::diagnostic_format_sarif_cc_tests): New.
* diagnostic-show-locus.cc: Include "text-range-label.h" and
"selftest-diagnostic-show-locus.h".
(selftests::diagnostic_show_locus_fixture::diagnostic_show_locus_fixture):
New.
(selftests::test_layout_x_offset_display_utf8): Use
diagnostic_show_locus_fixture to simplify and consolidate setup
code.
(selftests::test_diagnostic_show_locus_one_liner): Likewise.
(selftests::test_one_liner_colorized_utf8): Likewise.
(selftests::test_diagnostic_show_locus_one_liner_utf8): Likewise.
* gcc-rich-location.h (class text_range_label): Move to new file
text-range-label.h.
* selftest-diagnostic-show-locus.h: New file, based on material in
diagnostic-show-locus.cc.
* selftest-json.cc: New file.
* selftest-json.h: New file.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::diagnostic_format_sarif_cc_tests.
* selftest.h (selftest::diagnostic_format_sarif_cc_tests): New decl.
gcc/testsuite/ChangeLog:
* c-c++-common/diagnostic-format-sarif-file-Wbidi-chars.c: Verify
that we have a property bag with property "gcc/escapeNonAscii": true.
Verify that we have a "rendered" property for a snippet.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Include
"text-range-label.h".
gcc/ChangeLog:
* text-range-label.h: New file, taking class text_range_label from
gcc-rich-location.h.
libcpp/ChangeLog:
* include/rich-location.h
(semi_embedded_vec::semi_embedded_vec): Add copy ctor.
(rich_location::rich_location): Remove "= delete" from decl of
copy ctor. Add deleted decl of move ctor.
(rich_location::operator=): Remove "= delete" from decl of
copy assignment. Add deleted decl of move assignment.
(fixit_hint::fixit_hint): Add copy ctor decl. Add deleted decl of
move.
(fixit_hint::operator=): Add copy assignment decl. Add deleted
decl of move assignment.
* line-map.cc (rich_location::rich_location): New copy ctor.
(fixit_hint::fixit_hint): New copy ctor.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
Since r6-4582-g8a64515099e645 (which added class rich_location), ranges
of quoted source code have been colorized using the following rules:
- the primary range used the same color of the kind of the diagnostic
i.e. "error" vs "warning" etc (defaulting to bold red and bold magenta
respectively)
- secondary ranges alternate between "range1" and "range2" (defaulting
to green and blue respectively)
This works for cases with large numbers of highlighted ranges, but is
suboptimal for common cases.
The following patch adds a pair of color names: "highlight-a" and
"highlight-b", and uses them whenever it makes sense to highlight and
contrast two different things in the source code (e.g. a type mismatch).
These are used by diagnostic-show-locus.cc for highlighting quoted
source. In addition the patch adds colorization to fragments within the
corresponding diagnostic messages themselves, using consistent
colorization between the message and the quoted source code for the two
different things being contrasted.
For example, consider:
demo.c: In function ‘test_bad_format_string_args’:
../../src/demo.c:25:18: warning: format ‘%i’ expects argument of
type ‘int’, but argument 2 has type ‘const char *’ [-Wformat=]
25 | printf("hello %i", msg);
| ~^ ~~~
| | |
| int const char *
| %s
Previously, the types within the message in quotes would be in bold but
not colorized, and the labelled ranges of quoted source code would use
bold magenta for the "int" and non-bold green for the "const char *".
With this patch:
- the "%i" and "int" in the message and the "int" in the quoted source
are all colored bold green
- the "const char *" in the message and in the quoted source are both
colored bold blue
so that the consistent use of contrasting color draws the reader's eyes
to the relationships between the diagnostic message and the source.
I've tried this with gnome-terminal with many themes, including a
variety of light versus dark backgrounds, solarized versus non-solarized
themes, etc, and it was readable in all.
My initial version of the patch used the existing %r and %R facilities
within pretty-print.cc for the messages, but this turned out to be very
uncomfortable, leading to error-prone format strings such as:
error_at (richloc,
"invalid operands to binary %s (have %<%r%T%R%> and %<%r%T%R%>)",
opname,
"highlight-a", type0,
"highlight-b", type1);
To avoid requiring monstrosities such as the above, the patch adds a new
"%e" format code to pretty-print.cc, which expects a pp_element *, where
pp_element is a new abstract base class (actually a pp_markup::element),
along with various useful subclasses. This lets the above be written
as:
pp_markup::element_quoted_type element_0 (type0, highlight_colors::lhs);
pp_markup::element_quoted_type element_1 (type1, highlight_colors::rhs);
error_at (richloc,
"invalid operands to binary %s (have %e and %e)",
opname, &element_0, &element_1);
which I feel is maintainable and clear to translators; the use of %e and
pp_element * captures the type-unsafe part of the variadic call, and the
subclasses allow for type-safety (so e.g. an element_quoted_type expects
a type and a highlighting color). This approach allows for some nice
simplifications within c-format.cc.
The patch also extends -Wformat to "teach" it about the new %e and
pp_element *. Doing so requires c-format.cc to be able to determine
if a T * is a pp_element * (i.e. if T is a subclass). To do so I added
a new comp_types callback for comparing types, where the C++ frontend
supplies a suitable implementation (and %e will always be wrong for C).
I've manually tested this on many diagnostics with both C and C++ and it
seems a subtle but significant improvement in readability.
I've added a new option -fno-diagnostics-show-highlight-colors in case
people prefer the old behavior.
gcc/c-family/ChangeLog:
* c-common.cc: Include "tree-pretty-print-markup.h".
(binary_op_error): Use pp_markup::element_quoted_type and %e.
(check_function_arguments): Add "comp_types" param and pass it to
check_function_format.
* c-common.h (check_function_arguments): Add "comp_types" param.
(check_function_format): Likewise.
* c-format.cc: Include "tree-pretty-print-markup.h".
(local_pp_element_ptr_node): New.
(PP_FORMAT_CHAR_TABLE): Add entry for %e.
(struct format_check_context): Add "m_comp_types" field.
(check_function_format): Add "comp_types" param and pass it to
check_format_info.
(check_format_info): Likewise, passing it to format_ctx's ctor.
(check_format_arg): Extract m_comp_types from format_ctx and
pass it to check_format_info_main.
(check_format_info_main): Add "comp_types" param and pass it to
arg_parser's ctor.
(class argument_parser): Add "m_comp_types" field.
(argument_parser::check_argument_type): Pass m_comp_types to
check_format_types.
(handle_subclass_of_pp_element_p): New.
(check_format_types): Add "comp_types" param, and use it to
call handle_subclass_of_pp_element_p.
(class element_format_substring): New.
(class element_expected_type_with_indirection): New.
(format_type_warning): Use element_expected_type_with_indirection
to unify the if (wanted_type_name) branches, reducing from four
emit_warning calls to two. Simplify these further using %e.
Doing so also gives suitable colorization of the text within the
diagnostics.
(init_dynamic_diag_info): Initialize local_pp_element_ptr_node.
(selftest::test_type_mismatch_range_labels): Add nullptr for new
param of gcc_rich_location label overload.
* c-format.h (T_PP_ELEMENT_PTR): New.
* c-type-mismatch.cc: Include "diagnostic-highlight-colors.h".
(binary_op_rich_location::binary_op_rich_location): Use
highlight_colors::lhs and highlight_colors::rhs for the ranges.
* c-type-mismatch.h (class binary_op_rich_location): Add comment
about highlight_colors.
gcc/c/ChangeLog:
* c-objc-common.cc: Include "tree-pretty-print-markup.h".
(print_type): Add optional "highlight_color" param and use it
to show highlight colors in "aka" text.
(pp_markup::element_quoted_type::print_type): New.
* c-typeck.cc: Include "tree-pretty-print-markup.h".
(comp_parm_types): New.
(build_function_call_vec): Pass it to check_function_arguments.
(inform_for_arg): Use %e and highlight colors to contrast actual
versus expected.
(convert_for_assignment): Use highlight_colors::actual for the
rhs_label.
(build_binary_op): Use highlight_colors::lhs and highlight_colors::rhs
for the ranges.
gcc/ChangeLog:
* common.opt (fdiagnostics-show-highlight-colors): New option.
* common.opt.urls: Regenerate.
* coretypes.h (pp_markup::element): New forward decl.
(pp_element): New typedef.
* diagnostic-color.cc (gcc_color_defaults): Add "highlight-a"
and "highlight-b".
* diagnostic-format-json.cc (diagnostic_output_format_init_json):
Disable highlight colors.
* diagnostic-format-sarif.cc (diagnostic_output_format_init_sarif):
Likewise.
* diagnostic-highlight-colors.h: New file.
* diagnostic-path.cc (struct event_range): Pass nullptr for
highlight color of m_rich_loc.
* diagnostic-show-locus.cc (colorizer::set_range): Handle ranges
with m_highlight_color.
(colorizer::STATE_NAMED_COLOR): New.
(colorizer::m_richloc): New field.
(colorizer::colorizer): Add richloc param for initializing
m_richloc.
(colorizer::set_named_color): New.
(colorizer::begin_state): Add case STATE_NAMED_COLOR.
(layout::layout): Pass richloc to m_colorizer's ctor.
(selftest::test_one_liner_labels): Pass nullptr for new param of
gcc_rich_location ctor for labels.
(selftest::test_one_liner_labels_utf8): Likewise.
* diagnostic.h (diagnostic_context::set_show_highlight_colors):
New.
* doc/invoke.texi: Add option -fdiagnostics-show-highlight-colors
and highlight-a and highlight-b color caps.
* doc/ux.texi
(Use color consistently when highlighting mismatches): New
subsection.
* gcc-rich-location.cc (gcc_rich_location::add_expr): Add
"highlight_color" param.
(gcc_rich_location::maybe_add_expr): Likewise.
* gcc-rich-location.h (gcc_rich_location::gcc_rich_location):
Split out into a pair of ctors, where if a range_label is supplied
the caller must also supply a highlight color.
(gcc_rich_location::add_expr): Add "highlight_color" param.
(gcc_rich_location::maybe_add_expr): Likewise.
* gcc.cc (driver_handle_option): Handle
OPT_fdiagnostics_show_highlight_colors.
* lto-wrapper.cc (merge_and_complain): Likewise.
(append_compiler_options): Likewise.
(append_diag_options): Likewise.
(run_gcc): Likewise.
* opts-common.cc (decode_cmdline_options_to_array): Add comment
about -fno-diagnostics-show-highlight-colors.
* opts-global.cc (init_options_once): Preserve
pp_show_highlight_colors in case the global_dc's printer is
recreated.
* opts.cc (common_handle_option): Handle
OPT_fdiagnostics_show_highlight_colors.
(gen_command_line_string): Likewise.
* pretty-print-markup.h: New file.
* pretty-print.cc: Include "pretty-print-markup.h" and
"diagnostic-highlight-colors.h".
(pretty_printer::format): Handle %e.
(pretty_printer::pretty_printer): Handle new field
m_show_highlight_colors.
(pp_string_n): New.
(pp_markup::context::begin_quote): New.
(pp_markup::context::end_quote): New.
(pp_markup::context::begin_color): New.
(pp_markup::context::end_color): New.
(highlight_colors::expected): New.
(highlight_colors::actual): New.
(highlight_colors::lhs): New.
(highlight_colors::rhs): New.
(class selftest::test_element): New.
(selftest::test_pp_format): Add tests of %e.
(selftest::test_urlification): Likewise.
* pretty-print.h (pp_markup::context): New forward decl.
(class chunk_info): Add friend class pp_markup::context.
(class pretty_printer): Add friend pp_show_highlight_colors.
(pretty_printer::m_show_highlight_colors): New field.
(pp_show_highlight_colors): New inline function.
(pp_string_n): New decl.
* substring-locations.cc: Include "diagnostic-highlight-colors.h".
(format_string_diagnostic_t::highlight_color_format_string): New.
(format_string_diagnostic_t::highlight_color_param): New.
(format_string_diagnostic_t::emit_warning_n_va): Use highlight
colors.
* substring-locations.h
(format_string_diagnostic_t::highlight_color_format_string): New.
(format_string_diagnostic_t::highlight_color_param): New.
* toplev.cc (general_init): Initialize global_dc's
show_highlight_colors.
* tree-pretty-print-markup.h: New file.
gcc/cp/ChangeLog:
* call.cc: Include "tree-pretty-print-markup.h".
(implicit_conversion_error): Use highlight_colors::percent_h for
the labelled range.
(op_error_string): Split out into...
(concat_op_error_string): ...this.
(binop_error_string): New.
(op_error): Use %e, binop_error_string, highlight_colors::lhs,
and highlight_colors::rhs.
(maybe_inform_about_fndecl_for_bogus_argument_init): Add
"highlight_color" param; use it for the richloc.
(convert_like_internal): Use highlight_colors::percent_h for the
labelled_range, and highlight_colors::percent_i for the call to
maybe_inform_about_fndecl_for_bogus_argument_init.
(build_over_call): Pass cp_comp_parm_types for new "comp_types"
param of check_function_arguments.
(complain_about_bad_argument): Use highlight_colors::percent_h for
the labelled_range, and highlight_colors::percent_i for the call
to maybe_inform_about_fndecl_for_bogus_argument_init.
* cp-tree.h (maybe_inform_about_fndecl_for_bogus_argument_init):
Add optional highlight_color param.
(cp_comp_parm_types): New decl.
(highlight_colors::const percent_h): New decl.
(highlight_colors::const percent_i): New decl.
* error.cc: Include "tree-pretty-print-markup.h".
(highlight_colors::const percent_h): New defn.
(highlight_colors::const percent_i): New defn.
(type_to_string): Add param "highlight_color" and use it.
(print_nonequal_arg): Likewise.
(print_template_differences): Add params "highlight_color_a" and
"highlight_color_b".
(type_to_string_with_compare): Add params "this_highlight_color"
and "peer_highlight_color".
(print_template_tree_comparison): Add params "highlight_color_a"
and "highlight_color_b".
(cxx_format_postprocessor::handle):
Use highlight_colors::percent_h and highlight_colors::percent_i.
(pp_markup::element_quoted_type::print_type): New.
(range_label_for_type_mismatch::get_text): Pass nullptr for new
params of type_to_string_with_compare.
* typeck.cc (cp_comp_parm_types): New.
(cp_build_function_call_vec): Pass it to check_function_arguments.
(convert_for_assignment): Use highlight_colors::percent_h for the
labelled_range.
gcc/testsuite/ChangeLog:
* g++.dg/diagnostic/bad-binary-ops-highlight-colors.C: New test.
* g++.dg/diagnostic/bad-binary-ops-no-highlight-colors.C: New test.
* g++.dg/plugin/plugin.exp (plugin_test_list): Add
show-template-tree-color-no-highlight-colors.C to
show_template_tree_color_plugin.c.
* g++.dg/plugin/show-template-tree-color-labels.C: Update expected
output to reflect use of highlight-a and highlight-b to contrast
mismatches.
* g++.dg/plugin/show-template-tree-color-no-elide-type.C:
Likewise.
* g++.dg/plugin/show-template-tree-color-no-highlight-colors.C:
New test.
* g++.dg/plugin/show-template-tree-color.C: Update expected output
to reflect use of highlight-a and highlight-b to contrast
mismatches.
* g++.dg/warn/Wformat-gcc_diag-1.C: New test.
* g++.dg/warn/Wformat-gcc_diag-2.C: New test.
* g++.dg/warn/Wformat-gcc_diag-3.C: New test.
* gcc.dg/bad-binary-ops-highlight-colors.c: New test.
* gcc.dg/format/colors.c: New test.
* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Pass
nullptr for new param of gcc_rich_location::add_expr.
libcpp/ChangeLog:
* include/rich-location.h (location_range::m_highlight_color): New
field.
(rich_location::rich_location): Add optional label_highlight_color
param.
(rich_location::set_highlight_color): New decl.
(rich_location::add_range): Add optional label_highlight_color
param.
(rich_location::set_range): Likewise.
* line-map.cc (rich_location::rich_location): Add
"label_highlight_color" param and pass it to add_range.
(rich_location::set_highlight_color): New.
(rich_location::add_range): Add "label_highlight_color" param.
(rich_location::set_range): Add "highlight_color" param.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
These are never nullptr and never change, so use a reference rather
than a pointer.
No functional change intended.
gcc/analyzer/ChangeLog:
* diagnostic-manager.cc
(diagnostic_manager::add_events_for_eedge): Pass sm_ctxt by
reference.
* engine.cc (impl_region_model_context::on_condition): Likewise.
(impl_region_model_context::on_bounded_ranges): Likewise.
(impl_region_model_context::on_phi): Likewise.
(exploded_node::on_stmt): Likewise.
* sm-fd.cc: Update all uses of sm_context * to sm_context &.
* sm-file.cc: Likewise.
* sm-malloc.cc: Likewise.
* sm-pattern-test.cc: Likewise.
* sm-sensitive.cc: Likewise.
* sm-signal.cc: Likewise.
* sm-taint.cc: Likewise.
* sm.h: Likewise.
* varargs.cc: Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_gil_plugin.c: Update all uses of
sm_context * to sm_context &.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
As work towards eliminating the dependency on "tree" from
path-printing, move these classes to a new simple-diagnostic-path.h/cc.
No functional change intended.
gcc/analyzer/ChangeLog:
* checker-path.h: Include "simple-diagnostic-path.h".
gcc/ChangeLog:
* Makefile.in (OBJS): Add simple-diagnostic-path.o.
* diagnostic-path.h (class simple_diagnostic_event): Move to
simple-diagnostic-path.h.
(class simple_diagnostic_thread): Likewise.
(class simple_diagnostic_path): Likewise.
* diagnostic.cc (simple_diagnostic_path::simple_diagnostic_path):
Move to simple-diagnostic-path.cc.
(simple_diagnostic_path::num_events): Likewise.
(simple_diagnostic_path::get_event): Likewise.
(simple_diagnostic_path::num_threads): Likewise.
(simple_diagnostic_path::get_thread): Likewise.
(simple_diagnostic_path::add_thread): Likewise.
(simple_diagnostic_path::add_event): Likewise.
(simple_diagnostic_path::add_thread_event): Likewise.
(simple_diagnostic_path::connect_to_next_event): Likewise.
(simple_diagnostic_event::simple_diagnostic_event): Likewise.
(simple_diagnostic_event::~simple_diagnostic_event): Likewise.
* selftest-run-tests.cc (selftest::run_tests): Call
selftest::simple_diagnostic_path_cc_tests.
* selftest.h (selftest::simple_diagnostic_path_cc_tests): New
decl.
* simple-diagnostic-path.cc: New file, from the above material.
* simple-diagnostic-path.h: New file, from the above material
from diagnostic-path.h.
* tree-diagnostic-path.cc: Include "simple-diagnostic-path.h".
gcc/testsuite/ChangeLog
* gcc.dg/plugin/diagnostic_plugin_test_paths.c: Include
"simple-diagnostic-path.h".
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|
|
No functional change intended.
gcc/analyzer/ChangeLog:
* access-diagram.cc (access_range::dump): Update for fields of
pretty_printer becoming private.
* call-details.cc (call_details::dump): Likewise.
* call-summary.cc (call_summary::dump): Likewise.
(call_summary_replay::dump): Likewise.
* checker-event.cc (checker_event::debug): Likewise.
* constraint-manager.cc (range::dump): Likewise.
(bounded_range::dump): Likewise.
(constraint_manager::dump): Likewise.
* engine.cc (exploded_node::dump): Likewise.
(exploded_path::dump): Likewise.
(exploded_path::dump_to_file): Likewise.
* feasible-graph.cc (feasible_graph::dump_feasible_path): Likewise.
* program-point.cc (program_point::dump): Likewise.
* program-state.cc (extrinsic_state::dump_to_file): Likewise.
(sm_state_map::dump): Likewise.
(program_state::dump_to_file): Likewise.
* ranges.cc (symbolic_byte_offset::dump): Likewise.
(symbolic_byte_range::dump): Likewise.
* record-layout.cc (record_layout::dump): Likewise.
* region-model-reachability.cc (reachable_regions::dump): Likewise.
* region-model.cc (region_to_value_map::dump): Likewise.
(region_model::dump): Likewise.
(model_merger::dump): Likewise.
* region-model.h (one_way_id_map<T>::dump): Likewise.
* region.cc (region_offset::dump): Likewise.
(region::dump): Likewise.
* sm-malloc.cc (deallocator_set::dump): Likewise.
* store.cc (uncertainty_t::dump): Likewise.
(binding_key::dump): Likewise.
(bit_range::dump): Likewise.
(byte_range::dump): Likewise.
(binding_map::dump): Likewise.
(binding_cluster::dump): Likewise.
(store::dump): Likewise.
* supergraph.cc (supergraph::dump_dot_to_file): Likewise.
(superedge::dump): Likewise.
* svalue.cc (svalue::dump): Likewise.
gcc/c-family/ChangeLog:
* c-ada-spec.cc (dump_ads): Update for fields of pretty_printer
becoming private.
* c-pretty-print.cc: Likewise throughout.
gcc/c/ChangeLog:
* c-objc-common.cc (print_type): Update for fields of
pretty_printer becoming private.
(c_tree_printer): Likewise.
gcc/cp/ChangeLog:
* cxx-pretty-print.cc: Update throughout for fields of
pretty_printer becoming private.
* error.cc: Likewise.
gcc/ChangeLog:
* diagnostic.cc (diagnostic_context::urls_init): Update for fields
of pretty_printer becoming private.
(diagnostic_context::print_any_cwe): Likewise.
(diagnostic_context::print_any_rules): Likewise.
(diagnostic_context::print_option_information): Likewise.
* diagnostic.h (diagnostic_format_decoder): Likewise.
(diagnostic_prefixing_rule): Likewise, fixing typo.
* digraph.cc (test_dump_to_dot): Likewise.
* digraph.h (digraph<GraphTraits>::dump_dot_to_file): Likewise.
* dumpfile.cc
(dump_pretty_printer::emit_any_pending_textual_chunks): Likewise.
* gimple-pretty-print.cc (print_gimple_stmt): Likewise.
(print_gimple_expr): Likewise.
(print_gimple_seq): Likewise.
(dump_ssaname_info_to_file): Likewise.
(gimple_dump_bb): Likewise.
* graph.cc (print_graph_cfg): Likewise.
(start_graph_dump): Likewise.
* langhooks.cc (lhd_print_error_function): Likewise.
* lto-wrapper.cc (print_lto_docs_link): Likewise.
* pretty-print.cc (pp_set_real_maximum_length): Convert to...
(pretty_printer::set_real_maximum_length): ...this.
(pp_clear_state): Convert to...
(pretty_printer::clear_state): ...this.
(pp_wrap_text): Update for pp_remaining_character_count_for_line
becoming a member function.
(urlify_quoted_string): Update for fields of pretty_printer becoming
private.
(pp_format): Convert to...
(pretty_printer::format): ...this. Reduce the scope of local
variables "old_line_length" and "old_wrapping_mode" and make
const. Reduce the scope of locals "args", "new_chunk_array",
"curarg", "any_unnumbered", and "any_numbered".
(pp_output_formatted_text): Update for fields of pretty_printer
becoming private.
(pp_flush): Likewise.
(pp_really_flush): Likewise.
(pp_set_line_maximum_length): Likewise.
(pp_set_prefix): Convert to...
(pretty_printer::set_prefix): ...this.
(pp_take_prefix): Update for fields of pretty_printer gaining
"m_" prefixes.
(pp_destroy_prefix): Likewise.
(pp_emit_prefix): Convert to...
(pretty_printer::emit_prefix): ...this.
(pretty_printer::pretty_printer): Update both ctors for fields
gaining "m_" prefixes.
(pretty_printer::~pretty_printer): Likewise for dtor.
(pp_append_text): Update for pp_emit_prefix becoming
pretty_printer::emit_prefix.
(pp_remaining_character_count_for_line): Convert to...
(pretty_printer::remaining_character_count_for_line): ...this.
(pp_character): Update for above change.
(pp_maybe_space): Convert to...
(pretty_printer::maybe_space): ...this.
(pp_begin_url): Convert to...
(pretty_printer::begin_url): ...this.
(get_end_url_string): Update for fields of pretty_printer
becoming private.
(pp_end_url): Convert to...
(pretty_printer::end_url): ...this.
(selftest::test_pretty_printer::test_pretty_printer): Update for
fields of pretty_printer becoming private.
(selftest::test_urls): Likewise.
(selftest::test_null_urls): Likewise.
(selftest::test_urlification): Likewise.
* pretty-print.h (pp_line_cutoff): Convert from macro to inline
function.
(pp_prefixing_rule): Likewise.
(pp_wrapping_mode): Likewise.
(pp_format_decoder): Likewise.
(pp_needs_newline): Likewise.
(pp_indentation): Likewise.
(pp_translate_identifiers): Likewise.
(pp_show_color): Likewise.
(pp_buffer): Likewise.
(pp_get_prefix): Add forward decl to allow friend decl.
(pp_take_prefix): Likewise.
(pp_destroy_prefix): Likewise.
(class pretty_printer): Fix typo in leading comment. Add
"friend" decls for the various new accessor functions that were
formerly macros and for pp_get_prefix, pp_take_prefix, and
pp_destroy_prefix. Make all fields private.
(pretty_printer::set_output_stream): New.
(pretty_printer::set_prefix): New decl.
(pretty_printer::emit_prefix): New decl.
(pretty_printer::format): New decl.
(pretty_printer::maybe_space): New decl.
(pretty_printer::supports_urls_p): New.
(pretty_printer::get_url_format): New.
(pretty_printer::set_url_format): New.
(pretty_printer::begin_url): New decl.
(pretty_printer::end_url): New decl.
(pretty_printer::set_verbatim_wrapping): New.
(pretty_printer::set_padding): New.
(pretty_printer::get_padding): New.
(pretty_printer::clear_state): New decl.
(pretty_printer::set_real_maximum_length): New decl.
(pretty_printer::remaining_character_count_for_line): New decl.
(pretty_printer::buffer): Rename to...
(pretty_printer::m_buffer): ...this.
(pretty_printer::prefix): Rename to...
(pretty_printer::m_prefix): ...this;
(pretty_printer::padding): Rename to...
(pretty_printer::m_padding): ...this;
(pretty_printer::maximum_length): Rename to...
(pretty_printer::m_maximum_length): ...this;
(pretty_printer::indent_skip): Rename to...
(pretty_printer::m_indent_skip): ...this;
(pretty_printer::wrapping): Rename to...
(pretty_printer::m_wrapping): ...this;
(pretty_printer::format_decoder): Rename to...
(pretty_printer::m_format_decoder): ...this;
(pretty_printer::emitted_prefix): Rename to...
(pretty_printer::m_emitted_prefix): ...this;
(pretty_printer::need_newline): Rename to...
(pretty_printer::m_need_newline): ...this;
(pretty_printer::translate_identifiers): Rename to...
(pretty_printer::m_translate_identifiers): ...this;
(pretty_printer::show_color): Rename to...
(pretty_printer::m_show_color): ...this;
(pretty_printer::url_format): Rename to...
(pretty_printer::m_url_format): ...this;
(pp_get_prefix): Reformat.
(pp_format_postprocessor): New inline function.
(pp_take_prefix): Move decl to before class pretty_printer.
(pp_destroy_prefix): Likewise.
(pp_set_prefix): Convert to inline function.
(pp_emit_prefix): Convert to inline function.
(pp_format): Convert to inline function.
(pp_maybe_space): Convert to inline function.
(pp_begin_url): Convert to inline function.
(pp_end_url): Convert to inline function.
(pp_set_verbatim_wrapping): Convert from macro to inline
function, renaming...
(pp_set_verbatim_wrapping_): ...this.
* print-rtl.cc (dump_value_slim): Update for fields of
pretty_printer becoming private.
(dump_insn_slim): Likewise.
(dump_rtl_slim): Likewise.
* print-tree.cc (print_node): Likewise.
* sched-rgn.cc (dump_rgn_dependencies_dot): Likewise.
* text-art/canvas.cc (canvas::print_to_pp): Likewise.
(canvas::debug): Likewise.
(selftest::test_canvas_urls): Likewise.
* text-art/dump.h (dump_to_file): Likewise.
* text-art/selftests.cc (selftest::assert_canvas_streq): Likewise.
* text-art/style.cc (style::print_changes): Likewise.
* text-art/styled-string.cc (styled_string::from_fmt_va):
Likewise.
* tree-diagnostic-path.cc (control_flow_tests): Update for
pp_show_color becoming an inline function.
* tree-loop-distribution.cc (dot_rdg_1): Update for fields of
pretty_printer becoming private.
* tree-pretty-print.cc (maybe_init_pretty_print): Likewise.
* value-range.cc (vrange::dump): Likewise.
(irange_bitmask::dump): Likewise.
gcc/fortran/ChangeLog:
* error.cc (gfc_clear_pp_buffer): Likewise.
(gfc_warning): Likewise.
(gfc_warning_check): Likewise.
(gfc_error_opt): Likewise.
(gfc_error_check): Likewise.
gcc/jit/ChangeLog:
* jit-recording.cc (recording::function::dump_to_dot): Update for
fields of pretty_printer becoming private.
gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_cpython_plugin.c (dump_refcnt_info):
Update for fields of pretty_printer becoming private.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
|