aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin
AgeCommit message (Collapse)AuthorFilesLines
5 daysdiagnostics: fix crash-handling inside nested diagnostics [PR121876]David Malcolm8-3/+271
PR diagnostics/121876 tracks an issue inside our crash-handling, where if an ICE happens when we're within a nested diagnostic, an assertion fails inside diagnostic::context::set_diagnostic_buffer, leading to a 2nd ICE. Happily, this does not infinitely recurse, but it obscures the original ICE and the useful part of the backtrace, and any SARIF or HTML sinks we were writing to are left as empty files. This patch tweaks the above so that the assertion doesn't fail, and adds test coverage (via a plugin) to ensure that such ICEs/crashes are gracefully handled and e.g. captured in SARIF/HTML output. gcc/ChangeLog: PR diagnostics/121876 * diagnostics/buffering.cc (context::set_diagnostic_buffer): Add early reject of the no-op case. gcc/testsuite/ChangeLog: PR diagnostics/121876 * gcc.dg/plugin/crash-test-nested-ice-html.py: New test. * gcc.dg/plugin/crash-test-nested-ice-sarif.py: New test. * gcc.dg/plugin/crash-test-nested-ice.c: New test. * gcc.dg/plugin/crash-test-nested-write-through-null-html.py: New test. * gcc.dg/plugin/crash-test-nested-write-through-null-sarif.py: New test. * gcc.dg/plugin/crash-test-nested-write-through-null.c: New test. * gcc.dg/plugin/crash_test_plugin.cc: Add "nested" argument, and when set, inject the problem within a nested diagnostic. * gcc.dg/plugin/plugin.exp: Add crash-test-nested-ice.c and crash-test-nested-write-through-null.c. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
5 daystestsuite: fix typo in name of plugin test fileDavid Malcolm3-4/+4
gcc/testsuite/ChangeLog: * gcc.dg/plugin/crash-test-write-though-null-sarif.c: Rename to... * gcc.dg/plugin/crash-test-write-through-null-sarif.c: ...this. * gcc.dg/plugin/crash-test-write-though-null-stderr.c: Rename to... * gcc.dg/plugin/crash-test-write-through-null-stderr.c: ...this. * gcc.dg/plugin/plugin.exp: Update for above renamings. Sort the test files for crash_test_plugin.cc alphabetically. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-08diagnostics: enable nested diagnostics by default [PR116253]David Malcolm6-3/+38
In GCC 15 I added an experimental nesting view in text sinks for hierarchical diagnostics, such as C++ template problems. This patch enables it for text sinks by default. The old behavior can be restored via -fno-diagnostics-show-nesting, which the patch also adds to -fdiagnostics-plain-output. The patch does not yet enable it for text sinks in sarif-replay. gcc/ChangeLog: PR diagnostics/116253 * common.opt (fdiagnostics-show-nesting): New option. (fdiagnostics-show-nesting-locations): New option. (fdiagnostics-show-nesting-levels): New option. * common.opt.urls: Regenerate. * diagnostics/context.cc (context::set_show_nesting): New. (context::set_show_nesting_locations): New. (context::set_show_nesting_levels): New. * diagnostics/context.h (context::set_show_nesting): New decl. (context::set_show_nesting_locations): New decl. (context::set_show_nesting_levels): New decl. * diagnostics/html-sink.cc: Tweak comment. * diagnostics/output-spec.cc (text_scheme_handler::make_sink): Rename "experimental-nesting" to "show-nesting" and enable by default. Rename "experimental-nesting-show-locations" to "show-nesting-locations". Rename "experimental-nesting-show-levels" to "show-nesting-levels". * diagnostics/sink.h (sink::dyn_cast_text_sink): New. * diagnostics/text-sink.h (text_sink::dyn_cast_text_sink): New. * doc/invoke.texi: Add -fdiagnostics-show-nesting, -fdiagnostics-show-nesting-locations, and -fdiagnostics-show-nesting-levels. Update for changes to output-spec.cc above. * lto-wrapper.cc (merge_and_complain): Ignore OPT_fdiagnostics_show_nesting, OPT_fdiagnostics_show_nesting_locations, and OPT_fdiagnostics_show_nesting_levels. (append_compiler_options): Likewise. (append_diag_options): Likewise. * opts-common.cc (decode_cmdline_options_to_array): Add "-fno-diagnostics-show-nesting" to -fdiagnostics-plain-output. * opts.cc (common_handle_option): Handle the new options. (gen_command_line_string): Ignore the new options. * toplev.cc (general_init): Call set_show_nesting, set_show_nesting_locations, and set_show_nesting_levels on global_dc. gcc/testsuite/ChangeLog: PR diagnostics/116253 * g++.dg/concepts/nested-diagnostics-1-truncated.C: Update for renamed keys to -fdiagnostics-set-output=text * g++.dg/concepts/nested-diagnostics-1.C: Likewise. * g++.dg/concepts/nested-diagnostics-2.C: Likewise. * gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c: New test. * gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c: New test. * gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c: Update for renamed keys to -fdiagnostics-set-output=text. * gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c: Likewise. * gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: Likewise. * gcc.dg/plugin/plugin.exp: Add the new tests. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04diagnostics: improve support for nesting levels [PR116253]David Malcolm3-0/+83
This patch adds support to sarif-replay for "nestingLevel" from "P3358R0 SARIF for Structured Diagnostics" https://wg21.link/P3358R0 Doing so revealed a bug where libgdiagnostics was always creating new location_t values (and thus also diagnostic_physical_location instances), rather than reusing existing location_t values, leading to excess source printing. The patch also fixes this bug, adding a new flag to libgdiagnostics for debugging physical locations, and exposing this in sarif-replay via a new "-fdebug-physical-locations" maintainer option. Finally, the patch adds test coverage for the HTML sink's output of nested diagnostics (both from a GCC plugin, and from sarif-replay). gcc/ChangeLog: PR diagnostics/116253 * diagnostics/context.cc (context::set_nesting_level): New. * diagnostics/context.h (context::set_nesting_level): New decl. * doc/libgdiagnostics/topics/compatibility.rst (LIBGDIAGNOSTICS_ABI_5): New. * doc/libgdiagnostics/topics/physical-locations.rst (diagnostic_manager_set_debug_physical_locations): New. * libgdiagnostics++.h (manager::set_debug_physical_locations): New. * libgdiagnostics-private.h (private_diagnostic_set_nesting_level): New decl. * libgdiagnostics.cc (diagnostic_manager::diagnostic_manager): Initialize m_debug_physical_locations. (diagnostic_manager::new_location_from_file_and_line): Add debug printing. (diagnostic_manager::new_location_from_file_line_column): Likewise. (diagnostic_manager::new_location_from_range): Likewise. (diagnostic_manager::set_debug_physical_locations): New. (diagnostic_manager::ensure_linemap_for_file_and_line): Avoid redundant calls to linemap_add. (diagnostic_manager::new_location): Add debug printing. (diagnostic_manager::m_debug_physical_locations): New field. (diagnostic::diagnostic): Initialize m_nesting_level. (diagnostic::get_nesting_level): New accessor. (diagnostic::set_nesting_level): New. (diagnostic::m_nesting_level): New field. (diagnostic_manager::emit_va): Set and reset the nesting level of the context from that of the diagnostic. (diagnostic_manager_set_debug_physical_locations): New. (private_diagnostic_set_nesting_level): New. * libgdiagnostics.h (diagnostic_manager_set_debug_physical_locations): New decl. * libgdiagnostics.map (LIBGDIAGNOSTICS_ABI_5): New. * libsarifreplay.cc (sarif_replayer::handle_result_obj): Support the "nestingLevel" property. * libsarifreplay.h (replay_options::m_debug_physical_locations): New field. * sarif-replay.cc: Add -fdebug-physical-locations. gcc/testsuite/ChangeLog: PR diagnostics/116253 * gcc.dg/plugin/diagnostic-test-nesting-html.c: New test. * gcc.dg/plugin/diagnostic-test-nesting-html.py: New test script. * gcc.dg/plugin/plugin.exp: Add it. * libgdiagnostics.dg/test-multiple-lines.c: Update expected output to show fix-it hint. * sarif-replay.dg/2.1.0-valid/nested-diagnostics-1.sarif: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-08-04diagnostics: avoid stray trailing space in html sink in sarif-replay [PR116792]David Malcolm1-1/+1
For the common case where a diagnostic has no metadata, sarif-replay's html output was adding a stray space followed by an empty <div> for the metadata. Fixed thusly. gcc/ChangeLog: PR diagnostics/116792 * diagnostics/html-sink.cc (html_builder::make_element_for_diagnostic): Don't add the metadata element if it's empty. (html_builder::make_element_for_metadata): Return null rather than an empty element. gcc/testsuite/ChangeLog: PR diagnostics/116792 * gcc.dg/plugin/diagnostic-test-graphs-html.py: Remove trailing space from expected text of message. * sarif-replay.dg/2.1.0-valid/embedded-links-check-html.py: Likewise. * sarif-replay.dg/2.1.0-valid/graphs-check-html.py: Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-29calls: Allow musttail calls to noreturn [PR121159]Jakub Jelinek1-1/+1
In the PR119483 r15-9003 change we've allowed musttail calls to noreturn functions, after all the decision not to normally tail call noreturn functions is not because it is not possible to tail call those, but because it screws up backtraces. As the following testcase shows, we've done that only for functions not declared [[noreturn]]/_Noreturn but later on discovered through IPA as noreturn. Functions explicitly declared [[noreturn]] have (for historical reasons) volatile FUNCTION_TYPE and the FUNCTION_DECLs are volatile as well, so in order to support those we shouldn't complain on ECF_NORETURN (we've stopped doing so for musttail in PR119483) but also shouldn't complain about TYPE_VOLATILE on their FUNCTION_TYPE (something that IPA doesn't change, I think it only sets TREE_THIS_VOLATILE on the FUNCTION_DECL). volatile on function type really means noreturn as well, it has no other meaning. 2025-07-29 Jakub Jelinek <jakub@redhat.com> PR middle-end/121159 * calls.cc (can_implement_as_sibling_call_p): Don't reject declared noreturn functions in musttail calls. * c-c++-common/pr121159.c: New test. * gcc.dg/plugin/must-tail-call-2.c (test_5): Don't expect an error.
2025-07-25Introduce lazily-created.hDavid Malcolm3-5/+7
No functional change intended. gcc/ChangeLog: * diagnostics/context.cc: Eliminate digraphs::lazy_digraph in favor of lazily_created template. * diagnostics/context.h: Likewise. * diagnostics/digraphs.cc: Likewise, also digraphs::lazy_digraphs. * diagnostics/digraphs.h: Likewise. * diagnostics/html-sink.cc: Likewise. * diagnostics/metadata.h: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/sink.h: Likewise. * diagnostics/text-sink.h: Likewise. * lazily-created.h: New file. * libgdiagnostics.cc: Eliminate digraphs::lazy_digraph in favor of lazily_created template. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_graphs.cc: Eliminate digraphs::lazy_digraph and digraphs::lazy_digraphs in favor of lazily_created template. * gcc.dg/plugin/diagnostic_plugin_test_metadata.cc: Define INCLUDE_VECTOR since diagnostics/metadata.h now requires it. * gcc.dg/plugin/diagnostic_plugin_test_paths.cc: Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: make context::m_source_printing privateDavid Malcolm7-19/+19
No functional change intended. gcc/ada/ChangeLog: * gcc-interface/misc.cc: Make diagnostics::context::m_source_printing private. gcc/analyzer/ChangeLog: * program-point.cc: Make diagnostics::context::m_source_printing private. gcc/c-family/ChangeLog: * c-common.cc: Make diagnostics::context::m_source_printing private. * c-format.cc: Likewise. * c-opts.cc: Likewise. gcc/ChangeLog: * diagnostic.h (diagnostic_set_caret_max_width): Drop forward decl. (diagnostic_same_line): Make diagnostics::context::m_source_printing private. * diagnostics/context.cc (diagnostic_set_caret_max_width): Convert to... (diagnostics::context::set_caret_max_width): ...this. * diagnostics/context.h (diagnostics::context::get_source_printing_options): New accessors. (diagnostics::context::m_source_printing): Make private. * diagnostics/html-sink.cc: Make diagnostics::context::m_source_printing private. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/selftest-context.cc: Likewise. * diagnostics/selftest-context.h (diagnostics::selftest::test_context::colorize_source): New. (diagnostics::selftest::test_context::show_labels): New. (diagnostics::selftest::test_context::show_line_numbers): New. (diagnostics::selftest::test_context::show_ruler): New. (diagnostics::selftest::test_context::show_event_links): New. (diagnostics::selftest::test_context::set_caret_char): New. * diagnostics/source-printing.cc: Make diagnostics::context::m_source_printing private. * diagnostics/text-sink.h: Likewise. * libgdiagnostics.cc: Likewise. * opts.cc: Likewise. * toplev.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Make diagnostics::context::m_source_printing private. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_show_trees.cc: Make diagnostics::context::m_source_printing private. * gcc.dg/plugin/diagnostic_plugin_test_inlining.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_paths.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/expensive_selftests_plugin.cc: Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: eliminate ::diagnostic_info typedefDavid Malcolm3-5/+5
No functional change intended. gcc/c-family/ChangeLog: * c-common.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * c-opts.cc: Likewise. gcc/c/ChangeLog: * c-errors.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". gcc/cp/ChangeLog: * constexpr.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * cp-tree.h: Likewise. * error.cc: Likewise. * module.cc: Likewise. gcc/d/ChangeLog: * d-diagnostic.cc: Likewise. gcc/ChangeLog: * diagnostic.h: Eliminate "diagnostic_info" typedef. * diagnostics/context.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * langhooks.cc: Likewise. * libgdiagnostics.cc: Likewise. * rtl-error.cc: Likewise. * substring-locations.cc: Likewise. * toplev.cc: Likewise. * tree-diagnostic.cc: Likewise. * tree-diagnostic.h: Likewise. gcc/fortran/ChangeLog: * cpp.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * error.cc: Likewise. gcc/jit/ChangeLog: * dummy-frontend.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". gcc/m2/ChangeLog: * gm2-gcc/m2linemap.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * gm2-gcc/rtegraph.cc: Likewise. gcc/rust/ChangeLog: * resolve/rust-ice-finalizer.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * resolve/rust-ice-finalizer.h: Likewise. gcc/testsuite/ChangeLog: * g++.dg/plugin/show_template_tree_color_plugin.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". * gcc.dg/plugin/diagnostic_group_plugin.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. libcc1/ChangeLog: * context.cc: Update usage of "diagnostic_info" to explicitly refer to "diagnostics::diagnostic_info". Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move file_cache from input.{cc,h} to diagnostics/file-cache.{cc,h}David Malcolm1-3/+5
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Add diagnostics/file-cache.o. * diagnostics/changes.cc: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. * diagnostics/context.cc: Likewise. * diagnostics/diagnostics-selftests.cc: Likewise. * diagnostics/diagnostics-selftests.h: Likewise. * diagnostics/file-cache.cc: New file, based on the file_cache and file_cache_slot material in input.cc. * diagnostics/file-cache.h: Likewise for input.h. * diagnostics/selftest-source-printing.h: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. * diagnostics/source-printing.cc: Likewise. * final.cc: Likewise. * gcc-rich-location.cc: Likewise. * input.cc (default_charset_callback): Move to diagnostics/file-cache.cc. (file_cache::initialize_input_context): Likewise. (class file_cache_slot): Likewise. (file_cache::tune): Likewise. (file_cache::lookup_file): Likewise. (file_cache::forcibly_evict_file): Likewise. (file_cache::missing_trailing_newline_p): Likewise. (file_cache::add_buffered_content): Likewise. (file_cache::evicted_cache_tab_entry): Likewise. (file_cache::add_file): Likewise. (file_cache::file_cache): Likewise. (file_cache::dump): Likewise. (file_cache::dump): Likewise. (file_cache::lookup_or_add_file): Likewise. (find_end_of_line): Likewise. (file_cache::get_source_line): Likewise. (check_line): Likewise. (test_replacement): Likewise. (test_reading_source_line): Likewise. (test_reading_source_buffer): Likewise. * input.h (class char_span): Move to diagnostics/file-cache.h and into the "diagnostics::" namespace. (class file_cache_slot): Likewise. (class file_cache): Likewise. * libgdiagnostics.cc: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. * selftest.cc: Likewise. * selftest.h: Likewise. * substring-locations.h: Likewise. * toplev.cc: Likewise. gcc/c-family/ChangeLog: * c-format.cc: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. * c-indentation.cc: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Update for file_cache and char_span moving from input.h to diagnostics/file-cache.h and into the "diagnostics::" namespace. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: convert diagnostic_t to enum class diagnostics::kindDavid Malcolm3-4/+5
No functional change intended. gcc/ChangeLog: * Makefile.in: Replace diagnostic.def with diagnostics/kinds.def. * config/aarch64/aarch64.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * config/i386/i386-options.cc: Likewise. * config/s390/s390.cc: Likewise. * diagnostic-core.h: Replace typedef diagnostic_t with enum class diagnostics::kind in diagnostics/kinds.h and include it. * diagnostic-global-context.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostics/buffering.cc: Likewise. * diagnostics/buffering.h: Likewise. * diagnostics/context.h: Likewise. * diagnostics/diagnostic-info.h: Likewise. * diagnostics/html-sink.cc: Likewise. * diagnostic.def: Move to... * diagnostics/kinds.def: ...here and update for diagnostic_t becoming enum class diagnostics::kind. * diagnostics/kinds.h: New file, based on material in diagnostic-core.h. * diagnostics/lazy-paths.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * diagnostics/option-classifier.cc: Likewise. * diagnostics/option-classifier.h: Likewise. * diagnostics/output-spec.h: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/selftest-context.cc: Likewise. * diagnostics/selftest-context.h: Likewise. * diagnostics/sink.h: Likewise. * diagnostics/source-printing.cc: Likewise. * diagnostics/text-sink.cc: Likewise. * diagnostics/text-sink.h: Likewise. * gcc.cc: Likewise. * libgdiagnostics.cc: Likewise. * lto-wrapper.cc: Likewise. * opts-common.cc: Likewise. * opts-diagnostic.h: Likewise. * opts.cc: Likewise. * rtl-error.cc: Likewise. * substring-locations.cc: Likewise. * toplev.cc: Likewise. gcc/ada/ChangeLog: * gcc-interface/trans.cc: Update for diagnostic_t becoming enum class diagnostics::kind. gcc/analyzer/ChangeLog: * pending-diagnostic.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * program-point.cc: Likewise. gcc/c-family/ChangeLog: * c-common.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * c-format.cc: Likewise. * c-lex.cc: Likewise. * c-opts.cc: Likewise. * c-pragma.cc: Likewise. * c-warn.cc: Likewise. gcc/c/ChangeLog: * c-errors.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * c-parser.cc: Likewise. * c-typeck.cc: Likewise. gcc/cobol/ChangeLog: * util.cc: Update for diagnostic_t becoming enum class diagnostics::kind. gcc/cp/ChangeLog: * call.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * constexpr.cc: Likewise. * cp-tree.h: Likewise. * decl.cc: Likewise. * error.cc: Likewise. * init.cc: Likewise. * method.cc: Likewise. * module.cc: Likewise. * parser.cc: Likewise. * pt.cc: Likewise. * semantics.cc: Likewise. * typeck.cc: Likewise. * typeck2.cc: Likewise. gcc/d/ChangeLog: * d-diagnostic.cc: Update for diagnostic_t becoming enum class diagnostics::kind. gcc/fortran/ChangeLog: * cpp.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * error.cc: Likewise. * options.cc: Likewise. gcc/jit/ChangeLog: * dummy-frontend.cc: Update for diagnostic_t becoming enum class diagnostics::kind. gcc/m2/ChangeLog: * gm2-gcc/m2linemap.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * gm2-gcc/rtegraph.cc: Likewise. gcc/rust/ChangeLog: * backend/rust-tree.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * backend/rust-tree.h: Likewise. * resolve/rust-ast-resolve-expr.cc: Likewise. * resolve/rust-ice-finalizer.cc: Likewise. * resolve/rust-ice-finalizer.h: Likewise. * resolve/rust-late-name-resolver-2.0.cc: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Update for diagnostic_t becoming enum class diagnostics::kind. * gcc.dg/plugin/expensive_selftests_plugin.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. * lib/gcc-dg.exp: Likewise. libcpp/ChangeLog: * internal.h: Update comment for diagnostic_t becoming enum class diagnostics::kind. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move diagnostics::edit_context -> diagnostics::changes::change_setDavid Malcolm1-4/+4
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Replace diagnostics/changes.o with diagnostics/edit-context.o. * diagnostic.cc: Update for move of diagnostics/edit-context.h to diagnostics/changes.h. (diagnostics::context::initialize): Update for renaming of m_edit_context_ptr to m_fixits_change_set. (diagnostics::context::finish): Likewise. (diagnostics::context::create_edit_context): Rename to... (diagnostics::context::initialize_fixits_change_set): ...this and update for other renamings. (diagnostics::context::report_diagnostic): Update for renaming of m_edit_context_ptr to m_fixits_change_set. * diagnostic.h (diagnostics::edit_context): Drop forward decl * diagnostics/edit-context.cc: Move to... * diagnostics/changes.cc: ...here. Update for move of diagnostics/edit-context.h to diagnostics/changes.h. Rename diagnostics::edit_context to diagnostics::changes::change_set. Rename diagnostics::edited_file to diagnostics::changes::changed_file. Rename diagnostics::edited_line to diagnostics::changes::changed_line. * diagnostics/edit-context.h: Move to... * diagnostics/changes.h: ...here, renaming as above. * diagnostics/context.h (diagnostics::changes::change_set): New forward decl. (diagnostics::context::create_edit_context): Rename to... (diagnostics::context::initialize_fixits_change_set): ...this. (diagnostics::context::get_edit_context): Rename to... (diagnostics::context::get_fixits_change_set): ...this. (diagnostics::context::m_edit_context_ptr): Rename to... (diagnostics::context::m_fixits_change_set): ..this and update type. * diagnostics/diagnostics-selftests.cc: Update for renaming. * diagnostics/diagnostics-selftests.h: Likewise. * diagnostics/html-sink.cc: Update for above changes. * libgdiagnostics.cc: Likewise. * toplev.cc: Likewise. gcc/c-family/ChangeLog: * c-common.cc: Update comment for renaming of edit_context. gcc/testsuite/ChangeLog: * gcc.dg/plugin/expensive_selftests_plugin.cc: Update for change from edit-context.h to changes.h. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: reorganize selftestsDavid Malcolm1-1/+1
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS): Move diagnostics/lazy-paths.o to... (OBJS-libcommon): ...here. Add diagnostics/diagnostics-selftests.o. * diagnostic.cc: Update for move of selftest::test_diagnostic_context to diagnostics::selftest::test_context. * diagnostics/color.cc: Move selftests from selftest:: to diagnostics::selftest::. * diagnostics/diagnostics-selftests.cc: New file. * diagnostics/diagnostics-selftests.h: New file. * diagnostics/digraphs.cc: Move selftests from selftest:: to diagnostics::selftest::. * diagnostics/edit-context.cc: Likewise. * diagnostics/html-sink.cc: Likewise. * diagnostics/lazy-paths.cc: Likewise. Eliminate use of "tree" by porting selftests from simple-diagnostic-path.h to diagnostics/selftest-paths.h. * diagnostics/output-spec.cc: Move selftests from selftest:: to diagnostics::selftest::. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/selftest-context.cc: Move selftest::test_diagnostic_context to diagnostics::selftest::test_context. * diagnostics/selftest-context.h: Likewise. * diagnostics/selftest-logical-locations.cc: Move selftests from selftest:: to diagnostics::logical_locations::selftest::. * diagnostics/selftest-logical-locations.h: Move selftest::logical_location_manager to diagnostics::logical_locations::selftest::logical_location_manager. * diagnostics/selftest-paths.cc: Move selftest::test_diagnostic_path to diagnostics::paths::selftest::test_path. Move selftest::test_diagnostic_event to diagnostics::paths::selftest::test_event. * diagnostics/selftest-paths.h: Likewise, and move selftest::test_diagnostic_thread to diagnostics::paths::selftest::test_thread. * diagnostics/selftest-source-printing.h: Move selftest::diagnostic_show_locus_fixture to diagnostics::selftest::source_printing_fixture. * diagnostics/source-printing.cc: Move selftests from selftest:: to diagnostics::selftest:: and update for renames. * diagnostics/state-graphs.cc: Likewise. * selftest-run-tests.cc: Include "diagnostics/diagnostics-selftests.h". (selftest::run_tests): Replace invocation of the various diagnostics selftests with a call to diagnostics::selftest::run_diagnostics_selftests. * selftest.h: Move decls of the various per-file diagnostics invocation functions to diagnostics/diagnostics-selftests.h, renaming due to diagostics prefix being implied by namespace. gcc/c-family/ChangeLog: * c-format.cc (test_type_mismatch_range_labels): Update for move of selftest::test_diagnostic_context to diagnostics::selftest::test_context. gcc/testsuite/ChangeLog: * gcc.dg/plugin/expensive_selftests_plugin.cc: Update for move of selftest::test_diagnostic_context to diagnostics::selftest::test_context. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move gcc/diagnostic-color.{h,cc} to gcc/diagnostics/color.{h,cc}David Malcolm3-3/+3
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Replace diagnostic-color.o with diagnostics/color.o. (PLUGIN_HEADERS): Remove diagnostic-color.h in favor of glob. * common.opt: Update for move of diagnostic-color.h to diagnostics/color.h. * diagnostic.cc: Likewise. * diagnostic-color.cc: Move to... * diagnostics/color.cc: ...here. * diagnostic-color.h: Move to... * diagnostics/color.h: ...here. * diagnostics/edit-context.cc: Update for move of diagnostic-color.h to diagnostics/color.h. * diagnostics/output-spec.cc: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/source-printing.cc: Likewise. * diagnostics/text-sink.cc: Likewise. * libgdiagnostics.cc: Likewise. * opts.cc: Likewise. * pretty-print-markup.h: Likewise. * pretty-print.cc: Likewise. * selftest-run-tests.cc: Likewise. * selftest.h: Likewise. * text-art/style.cc: Likewise. gcc/cp/ChangeLog: * error.cc: Update for move of diagnostic-color.h to diagnostics/color.h. gcc/fortran/ChangeLog: * error.cc: Update for move of diagnostic-color.h to diagnostics/color.h. gcc/m2/ChangeLog: * gm2-gcc/m2color.cc: Update for move of diagnostic-color.h to diagnostics/color.h. gcc/testsuite/ChangeLog: * gcc.dg/plugin/analyzer_cpython_plugin.cc: Update for move of diagnostic-color.h to diagnostics/color.h. * 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>
2025-07-25diagnostics: move gcc/selftest-diagnostic.{h,cc} -> ↵David Malcolm1-1/+1
gcc/diagnostics/selftest-context.{h,cc} No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Replace selftest-diagnostic.o with diagnostics/selftest-context.o. * diagnostic.cc: Update for move of selftest-diagnostic.h to diagnostics/selftest-context.h. * diagnostics/html-sink.cc: Likewise. * diagnostics/lazy-paths.cc: Likewise. * diagnostics/output-spec.cc: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * selftest-diagnostic.cc: Move to... * diagnostics/selftest-context.cc: ...here and update for move of header file. * selftest-diagnostic.h: Move to... * diagnostics/selftest-context.h: ...here. * diagnostics/source-printing.cc: Update for move of selftest-diagnostic.h to diagnostics/selftest-context.h. gcc/c-family/ChangeLog: * c-format.cc: Update for move of selftest-diagnostic.h to diagnostics/selftest-context.h. gcc/testsuite/ChangeLog: * gcc.dg/plugin/expensive_selftests_plugin.cc: Update for move of selftest-diagnostic.h to diagnostics/selftest-context.h. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move diagnostic_context to diagnostics::context in its own headerDavid Malcolm3-11/+11
No functional change intended. gcc/ada/ChangeLog: * gcc-interface/misc.cc: Update for diagnostic_context becoming diagnostics::context. gcc/analyzer/ChangeLog: * program-point.cc: : Update for diagnostic_context becoming diagnostics::context, and for diagnostic_source_print_policy becoming diagnostics::source_print_policy. gcc/c-family/ChangeLog: * c-common.h: Update for diagnostic_context becoming diagnostics::context. * c-opts.cc: Likewise. gcc/c/ChangeLog: * c-objc-common.cc: Update for diagnostic_context becoming diagnostics::context. * c-tree.h: Likewise. gcc/ChangeLog: * coretypes.h: Update for diagnostic_context becoming diagnostics::context. * diagnostic-global-context.cc: Likewise. * diagnostic.cc: Likewise. Also for diagnostic_option_classifier becoming diagnostics::option_classifier. * diagnostic.h (diagnostic_text_starter_fn): Rename to... (diagnostics::text_starter_fn): ...this, and move to diagnostics/context.h. (get_printer): Rename to... (diagnostics::get_printer): ...this, and move to diagnostics/context.h. (class diagnostic_option_manager): Rename to... (class diagnostics::option_manager): ...this, and move to diagnostics/context.h. (class diagnostic_option_classifier): Rename to... (class diagnostics::option_classifier): ...this, and move to diagnostics/context.h. (struct diagnostic_source_printing_options): Rename to... (struct diagnostics::source_printing_options): ...this, and move to diagnostics/context.h. (class diagnostic_column_policy): Rename to... (class diagnostics::column_policy): ...this, and move to diagnostics/context.h. (class diagnostic_location_print_policy): Rename to... (class diagnostics::location_print_policy): ...this, and move to diagnostics/context.h. (class html_label_writer): Rename to... (class diagnostics::html_label_writer): ...this, and move to diagnostics/context.h. (class diagnostic_source_print_policy): Rename to... (class diagnostics::source_print_policy): ...this, and move to diagnostics/context.h. (struct diagnostic_counters): Rename to... (struct diagnostics::counters): ...this, and move to diagnostics/context.h. (class diagnostic_context): Rename to... (class diagnostics::context): ...this, and move to diagnostics/context.h. (diagnostic_text_starter): Rename to... (diagnostics::text_starter): ...this, and move to diagnostics/context.h. (diagnostic_start_span): Rename to... (diagnostics::start_span): ...this, and move to diagnostics/context.h. (diagnostic_text_finalizer): Rename to... (diagnostics::text_finalizer): ...this, and move to diagnostics/context.h. Include "diagnostics/context.h". * diagnostics/buffering.h: Update for diagnostic_context becoming diagnostics::context; similarly for diagnostic_counters. * diagnostics/client-data-hooks.h: Likewise. * diagnostics/context.h: New file, taken from material in diagnostic.h. * diagnostics/html-sink.cc: : Update for diagnostic_context becoming diagnostics::context. * diagnostics/html-sink.h: Likewise. * diagnostics/lazy-paths.cc: Likewise for diagnostic_option_manager. * diagnostics/output-file.h: Likewise for diagnostic_context. * diagnostics/output-spec.cc: Likewise. * diagnostics/output-spec.h: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/sarif-sink.h: Likewise. * diagnostics/sink.h: Likewise. * diagnostics/source-printing.cc: Likewise. * diagnostics/text-sink.cc: Likewise. * diagnostics/text-sink.h: Likewise. * gcc-rich-location.h: Likewise. * gcc.cc: Likewise. * gdbinit.in: Likewise. * langhooks-def.h: Likewise. * langhooks.cc: Likewise. * langhooks.h: Likewise. * libgdiagnostics.cc: Likewise. * optc-gen.awk: Likewise. * opth-gen.awk: Likewise. * opts-common.cc: Likewise. * opts-diagnostic.cc: Likewise. * opts-diagnostic.h: Likewise. * opts-global.cc: Likewise. * opts.cc: Likewise. * opts.h: Likewise. * selftest-diagnostic.cc: Likewise. * selftest-diagnostic.h: Likewise. * toplev.cc: Likewise. * tree-diagnostic-client-data-hooks.cc: Likewise. * tree-diagnostic.cc: Likewise. * tree-diagnostic.h: Likewise. gcc/cp/ChangeLog: * cp-tree.h: Update for diagnostic_context becoming diagnostics::context. * error.cc: Likewise. * module.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Update for diagnostic_context becoming diagnostics::context. gcc/jit/ChangeLog: * dummy-frontend.cc: Update for diagnostic_context becoming diagnostics::context. * jit-playback.h: Likewise. gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc: Update for diagnostic_text_finalizer becoming diagnostics::text_finalizer. * resolve/rust-late-name-resolver-2.0.cc: Likewise. gcc/testsuite/ChangeLog: * g++.dg/plugin/show_template_tree_color_plugin.cc: Update for moves to namespace diagnostics. * gcc.dg/plugin/diagnostic_group_plugin.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: add m_ prefix to fields of diagnostic_infoDavid Malcolm1-1/+1
No functional change intended. gcc/c-family/ChangeLog: * c-opts.cc (c_diagnostic_text_finalizer): Add "m_" prefix to fields of diagnostic_info. gcc/c/ChangeLog: * c-errors.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. gcc/cp/ChangeLog: * constexpr.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. * error.cc: Likewise. gcc/d/ChangeLog: * d-diagnostic.cc (d_diagnostic_report_diagnostic): Update to add "m_" prefix to fields of diagnostic_info throughout. gcc/ChangeLog: * diagnostic.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. * diagnostic.h: Likewise. * diagnostics/html-sink.cc: Likewise. * diagnostics/sarif-sink.cc: Likewise. * diagnostics/text-sink.cc: Likewise. * libgdiagnostics.cc: Likewise. * substring-locations.cc: Likewise. * tree-diagnostic.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Update to add "m_" prefix to fields of diagnostic_info throughout. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: introduce diagnostics/source-printing.ccDavid Malcolm1-1/+1
Move diagnostic-show-locus.cc to diagnostics/source-printing.cc Move diagnostic-label-effects.h to diagnostics/source-printing-effects.h Move selftest-diagnostic-show-locus.h to diagnostics/selftest-source-printing.h No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS): Replace diagnostic-show-locus.o with diagnostics/source-printing.o. * diagnostic.h (class diagnostic_source_effect_info): Replace with... (class diagnotics::source_effect_info): ...this. * diagnostics/paths-output.cc: Likewise. Update for move of "diagnostic-label-effects.h" to "diagnostics/source-printing-effects.h". * diagnostics/sarif-sink.cc: Update for move of "selftest-diagnostic-show-locus.h" to "diagnostics/selftest-source-printing.h". * selftest-diagnostic-show-locus.h: Move to... * diagnostics/selftest-source-printing.h: ...here. * diagnostic-label-effects.h: Move to... * diagnostics/source-printing-effects.h: ...here, updating for above changes. * diagnostic-show-locus.cc: Move to... * diagnostics/source-printing.cc: ...here. * gcc-rich-location.h: Likewise. * selftest-run-tests.cc: Likewise. * selftest.h: Likewise. gcc/testsuite/ChangeLog: * g++.dg/plugin/show-template-tree-color-labels.C: Update for moves to "source-printing". * gcc.dg/plugin/diagnostic-test-show-locus.py: Likewise. libcpp/ChangeLog: * include/cpplib.h: Update for moves to "source-printing". * include/rich-location.h (class label_effects): Move to... (class diagnostics::label_effects): ...here. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move/rename output formats to diagnostics as "sinks"David Malcolm3-14/+13
Within gcc/ move diagnostic-buffer.h to diagnostics/buffering.h move diagnostic-format-html.cc to diagnostics/html-sink.cc move diagnostic-format-html.h to diagnostics/html-sink.h move diagnostic-format-sarif.cc to diagnostics/sarif-sink.cc move diagnostic-format-sarif.h to diagnostics/sarif-sink.h move diagnostic-format.h to diagnostics/sink.h move diagnostic-format-text.cc to diagnostics/text-sink.cc move diagnostic-format-text.h to diagnostics/text-sink.h renaming various types including: Old name: New name: diagnostic_output_format diagnostics::sink diagnostic_buffer diagnostics::buffer diagnostic_per_format_buffer diagnostics::per_sink_buffer diagnostic_text_output_format diagnostics::text_sink sarif_output_format diagnostics::sarif_sink diagnostic_sarif_format_buffer diagnostics::sarif_sink_buffer html_output_format diagnostics::html_sink diagnostic_html_format_buffer diagnostics::html_sink_buffer No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS): Replace diagnostic-format-html.o with diagnostics/html-sink.o, diagnostic-format-sarif.o with diagnostics/sarif-sink.o, and diagnostic-format-text.o with diagnostics/text-sink.o. * coretypes.h (class diagnostic_text_output_format): Replace with... (class diagnostics::text_sink): ...this. * diagnostic-global-context.cc: Update for move of diagnostics output formats into namespace "diagnostics", as "sinks". * diagnostic-macro-unwinding.cc: Likewise. * diagnostic-macro-unwinding.h: Likewise. * diagnostic-show-locus.cc: Likewise. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostic-buffer.h: Rename to... * diagnostics/buffering.h: ...this, updating for above changes. * diagnostics/client-data-hooks.h: Likewise. * diagnostics/digraphs.cc: Likewise. * diagnostic-format-html.cc: Rename to... * diagnostics/html-sink.cc: ...this, updating for above changes. * diagnostic-format-html.h: Rename to... * diagnostics/html-sink.h: ...this, updating for above changes. * diagnostics/lazy-paths.cc: Likewise. * diagnostics/metadata.h: Likewise. * diagnostics/output-spec.cc: Likewise. * diagnostics/output-spec.h: Likewise. * diagnostics/paths-output.cc: Likewise. * diagnostics/paths.h: Likewise. * diagnostic-format-sarif.cc: Rename to... * diagnostics/sarif-sink.cc: ...this, updating for above changes. * diagnostic-format-sarif.h: Rename to... * diagnostics/sarif-sink.h: ...this, updating for above changes. * diagnostic-format.h: Rename to... * diagnostics/sink.h: ...this, updating for above changes. * diagnostics/state-graphs-to-dot.cc: Likewise. * diagnostic-format-text.cc: Rename to... * diagnostics/text-sink.cc: ...this, updating for above changes. * diagnostic-format-text.h: Rename to... * diagnostics/text-sink.h: ...this, updating for above changes. * gcc.cc: Likewise. * langhooks-def.h: Likewise. * langhooks.cc: Likewise. * langhooks.h: Likewise. * libgdiagnostics.cc: Likewise. * opts-diagnostic.cc: Likewise. * opts.cc: Likewise. * selftest-diagnostic.cc: Likewise. * selftest-run-tests.cc: Likewise. * selftest.h: Likewise. * tree-diagnostic-client-data-hooks.cc: Likewise. * tree-diagnostic.cc: Likewise. gcc/analyzer/ChangeLog: * ana-state-to-diagnostic-state.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * bounds-checking.cc: Likewise. * call-details.cc: Likewise. * checker-event.cc: Likewise. * checker-event.h: Likewise. * diagnostic-manager.cc: Likewise. * diagnostic-manager.h: Likewise. * infinite-loop.cc: Likewise. * infinite-recursion.cc: Likewise. * pending-diagnostic.h: Likewise. * region-model.cc: Likewise. * sm-taint.cc: Likewise. gcc/c-family/ChangeLog: * c-opts.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". gcc/cp/ChangeLog: * cp-tree.h: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * error.cc: Likewise. gcc/fortran/ChangeLog: * error.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * gfortran.h: Likewise. gcc/jit/ChangeLog: * dummy-frontend.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". gcc/rust/ChangeLog: * resolve/rust-ice-finalizer.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * resolve/rust-ice-finalizer.h: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_group_plugin.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc: Likewise. * gcc.dg/plugin/location_overflow_plugin.cc: Likewise. libcc1/ChangeLog: * context.cc: Update for move of diagnostics output formats into namespace "diagnostics" as "sinks". Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: introduce namespace diagnostics::pathsDavid Malcolm2-13/+14
Move more diagnostic-specific code from gcc/ to gcc/diagnostics/ No functional change intended. contrib/ChangeLog: * filter-clang-warnings.py: Update for move of diagnostic-path-output.cc to diagnostics/paths-output.cc. gcc/ChangeLog: * Makefile.in (OBJS): Replace lazy-diagnostic-path.o with diagnostics/lazy-paths.o. (OBJS-libcommon): Replace diagnostic-path.o with diagnostics/paths.o, diagnostic-path-output.o with diagnostics/paths-output.o, and selftest-diagnostic-path.o with diagnostics/selftest-paths.o. (EXTRA_BACKEND_OBJS): Replace lazy-diagnostic-path.o with diagnostics/lazy-paths.o. * diagnostic-format-html.cc: Update #include for "diagnostic-path.h" moving to "diagnostics/paths.h", diagnostic_thread_id_t to diagnostics::paths::thread_id_t, diagnostic_event_id_t to diagnostics::paths::event_id_t, diagnostic_path to diagnostics::paths::path, and diagnostic_thread to diagnostics::paths::thread, and diagnostic_event to diagnostics::paths::event. * diagnostic-format-html.h: Likewise. * diagnostic-format-sarif.cc: Likewise. Update PROPERTY_PREFIX for threadFlowLocations from "gcc/diagnostic_event/" to "gcc/diagnostics/paths/event/". * diagnostic-format-text.cc: Likewise. * diagnostic-format-text.h: Likewise. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostic-event-id.h: Move to... * diagnostics/event-id.h: ...here, updating header guard. (diagnostics:paths:event_id_t): New typedef. (diagnostic_thread_id_t): Replace with... (diagnostics:paths:thread_id_t): New typedef. * lazy-diagnostic-path.cc: Move to... * diagnostics/lazy-paths.cc: ...here. Update for above changes, lazy_diagnostic_path becomes diagnostics::paths::lazy_path. (lazy_diagnostic_path_cc_tests): Rename to... (diagnostics_lazy_paths_cc_tests): ...this. * lazy-diagnostic-path.h: Move to... * diagnostics/lazy-paths.h: ...here, updating header guard. Update for above changes. * diagnostic-path-output.cc: Move to... * diagnostics/paths-output.cc: ...here. Update for above changes. (diagnostic_path_output_cc_tests): Rename to... (diagnostics_paths_output_cc_tests): ...this. * diagnostic-path.cc: Move to... * diagnostics/paths.cc: ...here. Update for above changes. * diagnostic-path.h: Move to... * diagnostics/paths.h: ...here, updating header guard. Update #include for moving "diagnostic-event-id.h" to "diagnostics/event-id.h". (class diagnostic_event): Convert to... (class diagnostics::paths::event): ...this. (class diagnostic_thread): Convert to... (class diagnostics::paths::thread): ...this. (class diagnostic_path): Convert to... (class diagnostics::paths::path): ...this. * diagnostic-show-locus.cc: Update for above changes. * doc/analyzer.texi: Likewise. * selftest-diagnostic-path.cc: Move to... * diagnostics/selftest-paths.cc: ...here. Update for above changes, and for "selftest-diagnostic-path.h" moving to "diagnostics/selftest-paths.h". * selftest-diagnostic-path.h: Move to... * diagnostics/selftest-paths.h: ...here, updating header guard. Update for above changes. * libgdiagnostics.cc: Update for above changes. * libsarifreplay.cc: Update property prefix for threadFlowLocations from "gcc/diagnostic_event/" to "gcc/diagnostics/paths/event/". * pretty-print-format-impl.h: Update for above changes. * pretty-print.cc: Likewise. * selftest-run-tests.cc (selftest::run_tests): Update for renaming of lazy_diagnostic_path_cc_tests to diagnostics_lazy_paths_cc_tests, and of diagnostic_path_output_cc_tests to diagnostics_paths_output_cc_tests. * selftest.h (lazy_diagnostic_path_cc_tests): Replace decl with... (diagnostics_lazy_paths_cc_tests): ...this. (diagnostic_path_output_cc_tests): Replace decl with... (diagnostics_paths_output_cc_tests): ...this. * simple-diagnostic-path.cc: Clarify that this relates to "tree" and thus shouldn't be in "diagnostics". Update for above changes. * simple-diagnostic-path.h: Likewise. gcc/analyzer/ChangeLog: * access-diagram.cc: Update for changes to diagnostic paths: "diagnostic-path.h" moving to "diagnostics/paths.h", "diagnostic-event-id.h" moving to "diagnostics/event-id.h", diagnostic_event_id_t to diagnostics::paths::event_id_t, diagnostic_path to diagnostics::paths::path, and diagnostic_event to diagnostics::paths::event. * access-diagram.h: Likewise. * analyzer.cc: Likewise. * bounds-checking.cc: Likewise. * call-info.cc: Likewise. * checker-event.cc: Likewise. * checker-event.h: Likewise. * checker-path.cc: Likewise. * checker-path.h: Likewise. * common.h: Likewise. * diagnostic-manager.cc: Likewise. * pending-diagnostic.cc: Likewise. * pending-diagnostic.h: Likewise. * program-point.cc: Likewise. * program-state.cc: Likewise. * region-model.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. * varargs.cc: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/analyzer_gil_plugin.cc: Update #include for "diagnostic-path.h" moving to "diagnostics/paths.h", diagnostic_thread_id_t to diagnostics::paths::thread_id_t, diagnostic_event_id_t to diagnostics::paths::event_id_t, diagnostic_path to diagnostics::paths::path, and diagnostic_thread to diagnostics::paths::thread, and diagnostic_event to diagnostics::paths::event. * gcc.dg/plugin/diagnostic_plugin_test_paths.cc: Likewise. * lib/sarif.py (get_state_graph): Update property prefix for threadFlowLocations from "gcc/diagnostic_event/" to "gcc/diagnostics/paths/event/". * gcc.dg/sarif-output/include-chain-2.h: Update comment. libcpp/ChangeLog: * include/rich-location.h: Replace diagnostic_path with diagnostics::paths::path. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move edit_context to namespace/dir "diagnostics"David Malcolm1-2/+2
No functional change intended. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Replace edit-context.o with diagnostics/edit-context.o. * diagnostic-format-html.cc: Update #include for move of edit-context.h to diagnostics subdir. * diagnostic.cc: Likewise. Update for move of edit_context to diagnostics::edit_context. * diagnostic.h: Likewise. * edit-context.cc: Move to... * diagnostics/edit-context.cc: ...here. Update #include for move of edit-context.h to diagnostics subdir. Move all code within namespace diagnostics. * edit-context.h: Move to... * diagnostics/edit-context.h: ...here, updating header guard. Move all code within namespace diagnostics. * libgdiagnostics.cc: Update #include for move of edit-context.h to diagnostics subdir. Update for move of edit_context to diagnostics::edit_context. * toplev.cc: Update #include for move of edit-context.h to diagnostics subdir. gcc/testsuite/ChangeLog: * gcc.dg/plugin/expensive_selftests_plugin.cc: Update #include for move of edit-context.h to diagnostics subdir. Update for move of edit_context to diagnostics::edit_context. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move diagnostic_diagram to diagnostics::diagramDavid Malcolm1-2/+2
No functional change intended. gcc/analyzer/ChangeLog: * bounds-checking.cc: Update #include for move of "diagnostic-diagram.h" to "diagnostics/diagram.h". Update for move of diagnostic_diagram to diagnostics::diagram. gcc/ChangeLog: * diagnostic-format-html.cc: Update for move of diagnostic_diagram to diagnostics::diagram. * diagnostic-format-sarif.cc: Update #include for move of "diagnostic-diagram.h" to "diagnostics/diagram.h". Update for move of diagnostic_diagram to diagnostics::diagram. * diagnostic-format-text.cc: Likewise. * diagnostic-format-text.h: Update for move of diagnostic_diagram to diagnostics::diagram. * diagnostic-format.h: Likewise. * diagnostic.cc: Update #include for move of "diagnostic-diagram.h" to "diagnostics/diagram.h". Update for move of diagnostic_diagram to diagnostics::diagram. * diagnostic.h: Update for move of diagnostic_diagram to diagnostics::diagram. * diagnostic-diagram.h: Move to... * diagnostics/diagram.h: ...here. (class diagnostic_diagram): Convert to... (class diagnostics::diagram): ...this. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_text_art.cc: Update #include for move of "diagnostic-diagram.h" to "diagnostics/diagram.h". Update for move of diagnostic_diagram to diagnostics::diagram. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: move diagnostic_metadata to diagnostics::metadataDavid Malcolm6-15/+15
renamed: gcc/diagnostic-metadata.h -> gcc/diagnostics/metadata.h No functional change intended. gcc/analyzer/ChangeLog: * diagnostic-manager.cc: Update for move of diagnostic_metadata to diagnostics::metadata. * kf.cc: Likewise. * pending-diagnostic.h: Likewise; also, update #include for move of "diagnostic-metadata.h" to "diagnostics/metadata.h". gcc/cobol/ChangeLog: * util.cc: Remove redundant #includes gcc/ChangeLog: * diagnostic-core.h: Update for move of diagnostic_metadata to diagnostics::metadata. * diagnostic-format-html.cc: Likewise; also, update #include for move of "diagnostic-metadata.h" to "diagnostics/metadata.h". * diagnostic-format-sarif.cc: Likewise. * diagnostic-format-text.cc: Likewise. * diagnostic-global-context.cc: Likewise. * diagnostic.cc: Likewise. * diagnostic.h: Likewise. * diagnostic-metadata.h: Move to... * diagnostics/metadata.h: ...here, updating header guard. (class diagnostic_metadata): Move to... (class diagnostics::metadata): ...here. Drop redundant "diagnostics::" qualifiers. * libgdiagnostics.cc: : Update #include for move of "diagnostic-metadata.h" to "diagnostics/metadata.h", and update for move of diagnostic_metadata to diagnostics::metadata. * selftest-diagnostic.cc: Update for move of diagnostic_metadata to diagnostics::metadata. * selftest-diagnostic.h: Likewise. gcc/rust/ChangeLog: * rust-diagnostics.cc: Update #include for move of "diagnostic-metadata.h" to "diagnostics/metadata.h", and update for move of diagnostic_metadata to diagnostics::metadata. gcc/testsuite/ChangeLog: * gcc.dg/plugin/analyzer_cpython_plugin.cc: : Update #include for move of "diagnostic-metadata.h" to "diagnostics/metadata.h" * gcc.dg/plugin/analyzer_kernel_plugin.cc: Likewise. * gcc.dg/plugin/analyzer_known_fns_plugin.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_graphs.cc: Likewise. Also update for move of diagnostic_metadata to diagnostics::metadata. * gcc.dg/plugin/diagnostic_plugin_test_metadata.cc: Likewise. * gcc.dg/plugin/diagnostic_plugin_test_paths.cc: Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-25diagnostics: introduce a "gcc/diagnostics" subdirectoryDavid Malcolm1-1/+1
The "gcc" subdirectory of our source tree currently contains a total of almost 1000 .cc and .h files, enough to hit rate-limiting in some git web UIs, and obscuring the logical relationships between subsystems. In r16-2211-ga5d9debedd2f46 I started introducing a "namespace diagnostics" so it makes sense to move such code into a new "gcc/diagnostics" subdirectory. My intent is for the "diagnostics" namespace/directory to contain shared parts of the diagnostics code that are in libcommon, in particular which don't have knowledge of trees. This patch begins moving of the existing code within "namespace diagnostics" into a new "gcc/diagnostics" subdirectory. No functional change intended. renamed: gcc/diagnostic-digraphs.cc -> gcc/diagnostics/digraphs.cc renamed: gcc/diagnostic-digraphs.h -> gcc/diagnostics/digraphs.h renamed: gcc/diagnostic-state-to-dot.cc -> gcc/diagnostics/state-graphs-to-dot.cc renamed: gcc/diagnostic-state-graphs.cc -> gcc/diagnostics/state-graphs.cc renamed: gcc/diagnostic-state-graphs.h -> gcc/diagnostics/state-graphs.h contrib/ChangeLog: * gcc.doxy (INPUT): Add gcc/diagnostics subdir. gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Rename diagnostic-digraphs.o to diagnostics/digraphs.o. Rename diagnostic-state-graphs.o to diagnostics/state-graphs.o. Rename diagnostic-state-to-dot.o to diagnostics/state-graphs-to-dot.o. (PLUGIN_HEADERS): Add $(srcdir)/diagnostics/*.h. (install-plugin:): Likewise. * configure: Regenerate. * configure.ac (gccdepdir): Add "diagnostics" to directories. * diagnostic-format-html.cc: Update #includes for move of "diagnostic-digraphs.h" to "diagnostics/digraphs.h" and of move of "diagnostic-state-graphs.h" to "diagnostics/state-graphs.h". * diagnostic-format-sarif.cc: Likewise. * diagnostic-path.cc: Likewise for state-graphs.h * diagnostic-digraphs.cc: Move... * diagnostics/digraphs.cc: ...to here. Update #include for renaming of digraphs.h. (selftest::diagnostic_digraphs_cc_tests): Rename to... (selftest::diagnostics_digraphs_cc_tests): ...this. * diagnostic-digraphs.h: Move... * diagnostics/digraphs.h: ...to here, updating header guard. * diagnostic-state-to-dot.cc: Move... * diagnostics/state-graphs-to-dot.cc: ...to here. Update #include of state-graphs.h. * diagnostic-state-graphs.cc: Move... * diagnostics/state-graphs.cc: ...to here. Update #include of state-graphs.h. (selftest::diagnostic_state_graphs_cc_tests): Rename... (selftest::diagnostics_state_graphs_cc_tests): ...to this. * diagnostic-state-graphs.h: Move... * diagnostics/state-graphs.h: ...to here, updating header guard. * libgdiagnostics.cc: Update #includes for move of "diagnostic-digraphs.h" to "diagnostics/digraphs.h" and of move of "diagnostic-state-graphs.h" to "diagnostics/state-graphs.h". * selftest-run-tests.cc (selftest::run_tests): Update for function renamings that reflect file renamings. * selftest.h (selftest::diagnostic_digraphs_cc_tests): Rename to... (selftest::diagnostics_digraphs_cc_tests): ...this. (selftest::diagnostic_state_graphs_cc_tests): Rename... (selftest::diagnostics_state_graphs_cc_tests): ...to this. gcc/analyzer/ChangeLog: * ana-state-to-diagnostic-state.cc: Update #include for move of "diagnostic-state-graphs.h" to "diagnostics/state-graphs.h". * ana-state-to-diagnostic-state.h: Likewise. * checker-event.cc: Likewise. * checker-event.h: Update #include for move of "diagnostic-digraphs.h" to "diagnostics/digraphs.h". * program-state.cc: : Update #include for move of "diagnostic-state-graphs.h" to "diagnostics/state-graphs.h". gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_graphs.cc: Update #include for move of "diagnostic-digraphs.h" to "diagnostics/digraphs.h". Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-07-11diagnostics: add support for directed graphs; use them for state graphsDavid Malcolm7-0/+427
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>
2025-06-30diagnostics: convert diagnostic_event::meaning enums to enum classDavid Malcolm1-4/+4
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>
2025-06-30diagnostics: remove "json" output formatDavid Malcolm2-76/+0
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>
2025-06-23diagnostics: add state diagrams to analyzer experimental-html output [PR116792]David Malcolm4-0/+4
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>
2025-06-10diagnostics: make experimental-html sink prettier [PR116792]David Malcolm4-175/+41
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>
2025-05-27diagnostics: rework experimental-html output [PR116792]David Malcolm9-29/+354
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>
2025-05-12diagnostics: improvements to experimental-html output [PR116792]David Malcolm5-1/+124
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>
2025-05-08diagnostics: convert HTML output test plugin to 'experimental-html' sink ↵David Malcolm3-1006/+0
[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>
2025-05-07libcpp: Further fixes for incorrect line numbers in large files [PR120061]Jakub Jelinek8-4/+40
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.
2025-05-06diagnostics: add logical_location_manager; reimplement logical_locationDavid Malcolm1-2/+8
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>
2025-04-28Eliminate make-unique.h and ::make_uniqueDavid Malcolm6-61/+60
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>
2025-04-28analyzer: convert gcall * to gcall & in many placesDavid Malcolm1-12/+13
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>
2025-04-28analyzer: convert various enums to "enum class"David Malcolm1-2/+2
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>
2025-04-28analyzer: use analyzer/common.h as a common headerDavid Malcolm4-4/+4
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>
2025-04-28Fix size_t in id-15.c and infoleak-net-ethtool-ioctl.c for llp64Jonathan Yong1-2/+1
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.
2025-03-26testsuite: fix broken dg directivesDavid Malcolm1-1/+1
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>
2025-01-02Update copyright years.Jakub Jelinek1-1/+1
2024-12-16diagnostics: move libgdiagnostics dc from sinks into diagnostic_managerDavid Malcolm3-2/+5
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>
2024-12-11diagnostics: suppress "note: " prefix in nested diagnostics [PR116253]David Malcolm3-36/+36
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>
2024-12-08Support for 64-bit location_t: Activate 64-bit location_tLewis Hyatt2-7/+8
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.
2024-11-28expr, c: Don't clear whole unions [PR116416]Jakub Jelinek1-4/+10
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.
2024-11-26testsuite: rename plugins from .c to .ccDavid Malcolm34-33/+33
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>
2024-11-18diagnostics: add support for nested diagnostics [PR116253]David Malcolm8-0/+286
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>
2024-10-29diagnostics: support multiple output formats simultaneously [PR116613]David Malcolm5-16/+38
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>
2024-10-24analyzer: avoid implicit use of global_dc's pretty_printer [PR116613]David Malcolm2-27/+46
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>
2024-10-24Use unique_ptr in more places in pretty_printer/diagnostics [PR116613]David Malcolm3-7/+11
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>