diff options
Diffstat (limited to 'gcc/analyzer')
32 files changed, 354 insertions, 227 deletions
diff --git a/gcc/analyzer/ChangeLog b/gcc/analyzer/ChangeLog index 2c946f0..8e5d38e 100644 --- a/gcc/analyzer/ChangeLog +++ b/gcc/analyzer/ChangeLog @@ -1,3 +1,105 @@ +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * program-point.cc: Make diagnostics::context::m_source_printing + private. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * pending-diagnostic.cc: Update for diagnostic_t becoming + enum class diagnostics::kind. + * program-point.cc: Likewise. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * program-point.cc: : Update for diagnostic_context becoming + diagnostics::context, and for diagnostic_source_print_policy + becoming diagnostics::source_print_policy. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * 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. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * 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. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * bounds-checking.cc: Update #include for move of + "diagnostic-diagram.h" to "diagnostics/diagram.h". Update for + move of diagnostic_diagram to diagnostics::diagram. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * 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". + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * checker-event.h (checker_event::get_logical_location): Update + for conversion of logical_location to + diagnostics::logical_locations::key. + (checker_event::m_logical_loc): Likewise. + * diagnostic-manager.cc + (diagnostic_manager::get_logical_location_manager): Likewise. + * diagnostic-manager.h + (diagnostic_manager::get_logical_location_manager): Likewise. + +2025-07-25 David Malcolm <dmalcolm@redhat.com> + + * 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". + 2025-07-21 Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org> * region-model-asm.cc (region_model::on_asm_stmt): Pass null diff --git a/gcc/analyzer/access-diagram.cc b/gcc/analyzer/access-diagram.cc index 90b396c..166be08 100644 --- a/gcc/analyzer/access-diagram.cc +++ b/gcc/analyzer/access-diagram.cc @@ -1300,7 +1300,7 @@ class valid_region_spatial_item : public spatial_item { public: valid_region_spatial_item (const access_operation &op, - diagnostic_event_id_t region_creation_event_id, + diagnostics::paths::event_id_t region_creation_event_id, const theme &theme) : m_op (op), m_region_creation_event_id (region_creation_event_id), @@ -1523,7 +1523,7 @@ public: private: const access_operation &m_op; - diagnostic_event_id_t m_region_creation_event_id; + diagnostics::paths::event_id_t m_region_creation_event_id; mutable const boundaries *m_boundaries; const svalue *m_existing_sval; std::unique_ptr<spatial_item> m_existing_sval_spatial_item; @@ -2012,7 +2012,7 @@ class access_diagram_impl : public vbox_widget { public: access_diagram_impl (const access_operation &op, - diagnostic_event_id_t region_creation_event_id, + diagnostics::paths::event_id_t region_creation_event_id, style_manager &sm, const theme &theme, logger *logger) @@ -2564,7 +2564,7 @@ private: } const access_operation &m_op; - diagnostic_event_id_t m_region_creation_event_id; + diagnostics::paths::event_id_t m_region_creation_event_id; style_manager &m_sm; const theme &m_theme; logger *m_logger; @@ -2662,7 +2662,7 @@ direction_widget::paint_to_canvas (canvas &canvas) an access_diagram_impl. */ access_diagram::access_diagram (const access_operation &op, - diagnostic_event_id_t region_creation_event_id, + diagnostics::paths::event_id_t region_creation_event_id, style_manager &sm, const theme &theme, logger *logger) diff --git a/gcc/analyzer/access-diagram.h b/gcc/analyzer/access-diagram.h index e31dd28..d558f53 100644 --- a/gcc/analyzer/access-diagram.h +++ b/gcc/analyzer/access-diagram.h @@ -152,7 +152,7 @@ class access_diagram : public text_art::wrapper_widget { public: access_diagram (const access_operation &op, - diagnostic_event_id_t region_creation_event_id, + diagnostics::paths::event_id_t region_creation_event_id, text_art::style_manager &sm, const text_art::theme &theme, logger *logger); diff --git a/gcc/analyzer/ana-state-to-diagnostic-state.cc b/gcc/analyzer/ana-state-to-diagnostic-state.cc index 2701259..996538c 100644 --- a/gcc/analyzer/ana-state-to-diagnostic-state.cc +++ b/gcc/analyzer/ana-state-to-diagnostic-state.cc @@ -23,8 +23,8 @@ along with GCC; see the file COPYING3. If not see #define INCLUDE_SET #include "analyzer/common.h" -#include "diagnostic-state-graphs.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/state-graphs.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/region-model.h" #include "analyzer/program-state.h" diff --git a/gcc/analyzer/ana-state-to-diagnostic-state.h b/gcc/analyzer/ana-state-to-diagnostic-state.h index 186e19d..3a5ccc1 100644 --- a/gcc/analyzer/ana-state-to-diagnostic-state.h +++ b/gcc/analyzer/ana-state-to-diagnostic-state.h @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_ANALYZER_ANA_STATE_TO_DIAGNOSTIC_STATE_H #define GCC_ANALYZER_ANA_STATE_TO_DIAGNOSTIC_STATE_H -#include "diagnostic-state-graphs.h" +#include "diagnostics/state-graphs.h" #include "tree-logical-location.h" namespace ana { diff --git a/gcc/analyzer/analyzer.cc b/gcc/analyzer/analyzer.cc index 938ad6d..9f6f7b4 100644 --- a/gcc/analyzer/analyzer.cc +++ b/gcc/analyzer/analyzer.cc @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" #include "tree-pretty-print.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "tree-dfa.h" #include "intl.h" @@ -232,7 +232,7 @@ tree_to_json (tree node) for unknown). */ std::unique_ptr<json::value> -diagnostic_event_id_to_json (const diagnostic_event_id_t &event_id) +diagnostic_event_id_to_json (const diagnostics::paths::event_id_t &event_id) { if (event_id.known_p ()) { diff --git a/gcc/analyzer/bounds-checking.cc b/gcc/analyzer/bounds-checking.cc index d2e2b34..921ad16 100644 --- a/gcc/analyzer/bounds-checking.cc +++ b/gcc/analyzer/bounds-checking.cc @@ -20,8 +20,8 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" #include "intl.h" -#include "diagnostic-diagram.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/diagram.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/region-model.h" @@ -51,7 +51,7 @@ public: } void prepare_for_emission (checker_path *path, pending_diagnostic *pd, - diagnostic_event_id_t emission_id) override + diagnostics::paths::event_id_t emission_id) override { region_creation_event_capacity::prepare_for_emission (path, pd, @@ -101,10 +101,11 @@ public: *this)); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/out_of_bounds/" props.set_string (PROPERTY_PREFIX "dir", get_dir () == access_direction::read ? "read" : "write"); @@ -181,7 +182,7 @@ protected: a problem. Give up if that's happened. */ return; } - diagnostic_diagram diagram + diagnostics::diagram diagram (canvas, /* Alt text. */ _("Diagram visualizing the predicted out-of-bounds access")); @@ -203,7 +204,7 @@ protected: const region *m_reg; tree m_diag_arg; const svalue *m_sval_hint; - diagnostic_event_id_t m_region_creation_event_id; + diagnostics::paths::event_id_t m_region_creation_event_id; }; /* Abstract base class for all out-of-bounds warnings where the @@ -228,11 +229,11 @@ public: && m_out_of_bounds_bits == other.m_out_of_bounds_bits); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const override { out_of_bounds::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/concrete_out_of_bounds/" props.set (PROPERTY_PREFIX "out_of_bounds_bits", m_out_of_bounds_bits.to_json ()); @@ -294,11 +295,11 @@ public: *this)); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { concrete_out_of_bounds::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/concrete_past_the_end/" props.set (PROPERTY_PREFIX "bit_bound", tree_to_json (m_bit_bound)); @@ -966,11 +967,12 @@ public: && pending_diagnostic::same_tree_p (m_capacity, other.m_capacity)); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { out_of_bounds::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/symbolic_past_the_end/" props.set (PROPERTY_PREFIX "offset", tree_to_json (m_offset)); props.set (PROPERTY_PREFIX "num_bytes", tree_to_json (m_num_bytes)); diff --git a/gcc/analyzer/call-details.cc b/gcc/analyzer/call-details.cc index cb95843..ede1229 100644 --- a/gcc/analyzer/call-details.cc +++ b/gcc/analyzer/call-details.cc @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-pretty-print.h" #include "stringpool.h" #include "attribs.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/region-model.h" @@ -528,10 +528,10 @@ public: return true; } - void maybe_add_sarif_properties (sarif_object &result_obj) + void maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/overlapping_buffers/" props.set (PROPERTY_PREFIX "bytes_range_a", m_byte_range_a.to_json ()); diff --git a/gcc/analyzer/call-info.cc b/gcc/analyzer/call-info.cc index 9a698ef..f431143 100644 --- a/gcc/analyzer/call-info.cc +++ b/gcc/analyzer/call-info.cc @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "cfg.h" #include "digraph.h" #include "sbitmap.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "analyzer/analyzer-logging.h" #include "analyzer/supergraph.h" diff --git a/gcc/analyzer/checker-event.cc b/gcc/analyzer/checker-event.cc index 8cc5ac2..4eac945 100644 --- a/gcc/analyzer/checker-event.cc +++ b/gcc/analyzer/checker-event.cc @@ -1,4 +1,4 @@ -/* Subclasses of diagnostic_event for analyzer diagnostics. +/* Subclasses of diagnostics::paths::event for analyzer diagnostics. Copyright (C) 2019-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.com>. @@ -27,8 +27,8 @@ along with GCC; see the file COPYING3. If not see #include "gimple-iterator.h" #include "inlining-iterator.h" #include "tree-logical-location.h" -#include "diagnostic-format-sarif.h" -#include "diagnostic-state-graphs.h" +#include "diagnostics/sarif-sink.h" +#include "diagnostics/state-graphs.h" #include "analyzer/analyzer-logging.h" #include "analyzer/sm.h" @@ -101,7 +101,7 @@ event_kind_to_string (enum event_kind ek) } } -/* class checker_event : public diagnostic_event. */ +/* class checker_event : public diagnostics::paths::event. */ /* checker_event's ctor. */ @@ -131,24 +131,24 @@ checker_event::checker_event (enum event_kind kind, } } -/* No-op implementation of diagnostic_event::get_meaning vfunc for +/* No-op implementation of diagnostics::paths::event::get_meaning vfunc for checker_event: checker events have no meaning by default. */ -diagnostic_event::meaning +diagnostics::paths::event::meaning checker_event::get_meaning () const { - return meaning (); + return diagnostics::paths::event::meaning (); } -/* Implementation of diagnostic_event::maybe_add_sarif_properties +/* Implementation of diagnostics::paths::event::maybe_add_sarif_properties for checker_event. */ void checker_event:: -maybe_add_sarif_properties (sarif_builder &builder, - sarif_object &thread_flow_loc_obj) const +maybe_add_sarif_properties (diagnostics::sarif_builder &builder, + diagnostics::sarif_object &thread_flow_loc_obj) const { - sarif_property_bag &props = thread_flow_loc_obj.get_or_create_properties (); + auto &props = thread_flow_loc_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/checker_event/" props.set (PROPERTY_PREFIX "emission_id", diagnostic_event_id_to_json (m_emission_id)); @@ -215,7 +215,7 @@ checker_event::debug () const void checker_event::prepare_for_emission (checker_path *path, pending_diagnostic *pd, - diagnostic_event_id_t emission_id) + diagnostics::paths::event_id_t emission_id) { m_path = path; m_pending_diagnostic = pd; @@ -252,7 +252,7 @@ checker_event::maybe_make_diagnostic_state_graph (bool debug) const /* class debug_event : public checker_event. */ -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for debug_event. Use the saved string as the event's description. */ @@ -264,7 +264,7 @@ debug_event::print_desc (pretty_printer &pp) const /* class precanned_custom_event : public custom_event. */ -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for precanned_custom_event. Use the saved string as the event's description. */ @@ -287,7 +287,7 @@ statement_event::statement_event (const gimple *stmt, tree fndecl, int depth, { } -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for statement_event. Use the statement's dump form as the event's description. */ @@ -383,7 +383,7 @@ function_entry_event::function_entry_event (const program_point &dst_point, { } -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for function_entry_event. Use a string such as "entry to 'foo'" as the event's description. */ @@ -394,10 +394,10 @@ function_entry_event::print_desc (pretty_printer &pp) const pp_printf (&pp, "entry to %qE", m_effective_fndecl); } -/* Implementation of diagnostic_event::get_meaning vfunc for +/* Implementation of diagnostics::paths::event::get_meaning vfunc for function entry. */ -diagnostic_event::meaning +diagnostics::paths::event::meaning function_entry_event::get_meaning () const { return meaning (verb::enter, noun::function); @@ -429,7 +429,7 @@ state_change_event::state_change_event (const supernode *node, { } -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for state_change_event. Attempt to generate a nicer human-readable description. @@ -471,7 +471,7 @@ state_change_event::print_desc (pretty_printer &pp) const pp_string (&pp, "NULL origin"); /* Get any "meaning" of event. */ - diagnostic_event::meaning meaning = get_meaning (); + diagnostics::paths::event::meaning meaning = get_meaning (); pp_string (&pp, ", meaning: "); meaning.dump_to_pp (&pp); pp_string (&pp, ")"); @@ -508,11 +508,11 @@ state_change_event::print_desc (pretty_printer &pp) const } } -/* Implementation of diagnostic_event::get_meaning vfunc for +/* Implementation of diagnostics::paths::event::get_meaning vfunc for state change events: delegate to the pending_diagnostic to get any meaning. */ -diagnostic_event::meaning +diagnostics::paths::event::meaning state_change_event::get_meaning () const { if (m_pending_diagnostic) @@ -530,16 +530,17 @@ state_change_event::get_meaning () const /* class superedge_event : public checker_event. */ -/* Implementation of diagnostic_event::maybe_add_sarif_properties +/* Implementation of diagnostics::paths::event::maybe_add_sarif_properties for superedge_event. */ void -superedge_event::maybe_add_sarif_properties (sarif_builder &builder, - sarif_object &thread_flow_loc_obj) +superedge_event:: +maybe_add_sarif_properties (diagnostics::sarif_builder &builder, + diagnostics::sarif_object &thread_flow_loc_obj) const { checker_event::maybe_add_sarif_properties (builder, thread_flow_loc_obj); - sarif_property_bag &props = thread_flow_loc_obj.get_or_create_properties (); + auto &props = thread_flow_loc_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/superedge_event/" if (m_sedge) props.set (PROPERTY_PREFIX "superedge", m_sedge->to_json ()); @@ -626,10 +627,10 @@ cfg_edge_event::cfg_edge_event (enum event_kind kind, gcc_assert (eedge.m_sedge->m_kind == SUPEREDGE_CFG_EDGE); } -/* Implementation of diagnostic_event::get_meaning vfunc for +/* Implementation of diagnostics::paths::event::get_meaning vfunc for CFG edge events. */ -diagnostic_event::meaning +diagnostics::paths::event::meaning cfg_edge_event::get_meaning () const { const cfg_superedge& cfg_sedge = get_cfg_superedge (); @@ -643,7 +644,7 @@ cfg_edge_event::get_meaning () const /* class start_cfg_edge_event : public cfg_edge_event. */ -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for start_cfg_edge_event. If -fanalyzer-verbose-edges, then generate low-level descriptions, such @@ -844,7 +845,7 @@ call_event::call_event (const exploded_edge &eedge, m_dest_snode = eedge.m_dest->get_supernode (); } -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for call_event. If this call event passes critical state for an sm-based warning, @@ -876,10 +877,10 @@ call_event::print_desc (pretty_printer &pp) const get_caller_fndecl ()); } -/* Implementation of diagnostic_event::get_meaning vfunc for +/* Implementation of diagnostics::paths::event::get_meaning vfunc for function call events. */ -diagnostic_event::meaning +diagnostics::paths::event::meaning call_event::get_meaning () const { return meaning (verb::call, noun::function); @@ -928,7 +929,7 @@ return_event::return_event (const exploded_edge &eedge, m_dest_snode = eedge.m_dest->get_supernode (); } -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for return_event. If this return event returns critical state for an sm-based warning, @@ -960,10 +961,10 @@ return_event::print_desc (pretty_printer &pp) const m_src_snode->m_fun->decl); } -/* Implementation of diagnostic_event::get_meaning vfunc for +/* Implementation of diagnostics::paths::event::get_meaning vfunc for function return events. */ -diagnostic_event::meaning +diagnostics::paths::event::meaning return_event::get_meaning () const { return meaning (verb::return_, noun::function); @@ -987,10 +988,10 @@ start_consolidated_cfg_edges_event::print_desc (pretty_printer &pp) const m_edge_sense ? "true" : "false"); } -/* Implementation of diagnostic_event::get_meaning vfunc for +/* Implementation of diagnostics::paths::event::get_meaning vfunc for start_consolidated_cfg_edges_event. */ -diagnostic_event::meaning +diagnostics::paths::event::meaning start_consolidated_cfg_edges_event::get_meaning () const { return meaning (verb::branch, @@ -1008,10 +1009,10 @@ inlined_call_event::print_desc (pretty_printer &pp) const m_apparent_caller_fndecl); } -/* Implementation of diagnostic_event::get_meaning vfunc for +/* Implementation of diagnostics::paths::event::get_meaning vfunc for reconstructed inlined function calls. */ -diagnostic_event::meaning +diagnostics::paths::event::meaning inlined_call_event::get_meaning () const { return meaning (verb::call, noun::function); @@ -1019,7 +1020,7 @@ inlined_call_event::get_meaning () const /* class setjmp_event : public checker_event. */ -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for setjmp_event. */ void @@ -1038,7 +1039,7 @@ setjmp_event::print_desc (pretty_printer &pp) const void setjmp_event::prepare_for_emission (checker_path *path, pending_diagnostic *pd, - diagnostic_event_id_t emission_id) + diagnostics::paths::event_id_t emission_id) { checker_event::prepare_for_emission (path, pd, emission_id); path->record_setjmp_event (m_enode, emission_id); @@ -1077,7 +1078,7 @@ rewind_event::rewind_event (const exploded_edge *eedge, /* class rewind_from_longjmp_event : public rewind_event. */ -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for rewind_from_longjmp_event. */ void @@ -1101,7 +1102,7 @@ rewind_from_longjmp_event::print_desc (pretty_printer &pp) const /* class rewind_to_setjmp_event : public rewind_event. */ -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for rewind_to_setjmp_event. */ void @@ -1150,7 +1151,7 @@ rewind_to_setjmp_event::print_desc (pretty_printer &pp) const void rewind_to_setjmp_event::prepare_for_emission (checker_path *path, pending_diagnostic *pd, - diagnostic_event_id_t emission_id) + diagnostics::paths::event_id_t emission_id) { checker_event::prepare_for_emission (path, pd, emission_id); path->get_setjmp_event (m_rewind_info->get_enode_origin (), @@ -1203,7 +1204,7 @@ unwind_event::print_desc (pretty_printer &pp) const /* class warning_event : public checker_event. */ -/* Implementation of diagnostic_event::print_desc vfunc for +/* Implementation of diagnostics::paths::event::print_desc vfunc for warning_event. If the pending diagnostic implements describe_final_event, use it, @@ -1248,10 +1249,10 @@ warning_event::print_desc (pretty_printer &pp) const pp_string (&pp, "here"); } -/* Implementation of diagnostic_event::get_meaning vfunc for +/* Implementation of diagnostics::paths::event::get_meaning vfunc for warning_event. */ -diagnostic_event::meaning +diagnostics::paths::event::meaning warning_event::get_meaning () const { return meaning (verb::danger, noun::unknown); diff --git a/gcc/analyzer/checker-event.h b/gcc/analyzer/checker-event.h index cf24e77..909e388 100644 --- a/gcc/analyzer/checker-event.h +++ b/gcc/analyzer/checker-event.h @@ -1,4 +1,4 @@ -/* Subclasses of diagnostic_event for analyzer diagnostics. +/* Subclasses of diagnostics::paths::event for analyzer diagnostics. Copyright (C) 2019-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.com>. @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-logical-location.h" #include "analyzer/program-state.h" #include "analyzer/event-loc-info.h" -#include "diagnostic-digraphs.h" +#include "diagnostics/digraphs.h" namespace ana { @@ -62,7 +62,7 @@ extern const char *event_kind_to_string (enum event_kind ek); The class hierarchy looks like this (using indentation to show inheritance, and with event_kinds shown for the concrete subclasses): - diagnostic_event + diagnostics::paths::event checker_event debug_event (event_kind::debug) custom_event (event_kind::custom) @@ -91,30 +91,32 @@ extern const char *event_kind_to_string (enum event_kind ek); unwind_event (event_kind::unwind) warning_event (event_kind::warning). */ -/* Abstract subclass of diagnostic_event; the base class for use in - checker_path (the analyzer's diagnostic_path subclass). */ +/* Abstract subclass of diagnostics::paths::event; the base class for use in + checker_path (the analyzer's diagnostics::paths::path subclass). */ -class checker_event : public diagnostic_event +class checker_event : public diagnostics::paths::event { public: - /* Implementation of diagnostic_event. */ + /* Implementation of diagnostics::paths::event. */ location_t get_location () const final override { return m_loc; } int get_stack_depth () const final override { return m_effective_depth; } - logical_location get_logical_location () const final override + diagnostics::logical_locations::key + get_logical_location () const final override { return m_logical_loc; } meaning get_meaning () const override; bool connect_to_next_event_p () const override { return false; } - diagnostic_thread_id_t get_thread_id () const final override + diagnostics::paths::thread_id_t get_thread_id () const final override { return 0; } void - maybe_add_sarif_properties (sarif_builder &, - sarif_object &thread_flow_loc_obj) const override; + maybe_add_sarif_properties (diagnostics::sarif_builder &, + diagnostics::sarif_object &thread_flow_loc_obj) + const override; /* Additional functionality. */ enum event_kind get_kind () const { return m_kind; } @@ -124,7 +126,7 @@ public: virtual void prepare_for_emission (checker_path *, pending_diagnostic *pd, - diagnostic_event_id_t emission_id); + diagnostics::paths::event_id_t emission_id); virtual bool is_call_p () const { return false; } virtual bool is_function_entry_p () const { return false; } virtual bool is_return_p () const { return false; } @@ -136,7 +138,7 @@ public: get_program_state () const { return nullptr; } /* For use with %@. */ - const diagnostic_event_id_t *get_id_ptr () const + const diagnostics::paths::event_id_t *get_id_ptr () const { return &m_emission_id; } @@ -160,8 +162,8 @@ protected: int m_original_depth; int m_effective_depth; pending_diagnostic *m_pending_diagnostic; - diagnostic_event_id_t m_emission_id; // only set once all pruning has occurred - logical_location m_logical_loc; + diagnostics::paths::event_id_t m_emission_id; // only set once all pruning has occurred + diagnostics::logical_locations::key m_logical_loc; }; /* A concrete event subclass for a purely textual event, for use in @@ -422,8 +424,9 @@ public: class superedge_event : public checker_event { public: - void maybe_add_sarif_properties (sarif_builder &, - sarif_object &thread_flow_loc_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_builder &, + diagnostics::sarif_object &thread_flow_loc_obj) const override; /* Mark this edge event as being either an interprocedural call or @@ -665,7 +668,7 @@ public: void prepare_for_emission (checker_path *path, pending_diagnostic *pd, - diagnostic_event_id_t emission_id) final override; + diagnostics::paths::event_id_t emission_id) final override; private: const exploded_node *m_enode; @@ -731,10 +734,10 @@ public: void prepare_for_emission (checker_path *path, pending_diagnostic *pd, - diagnostic_event_id_t emission_id) final override; + diagnostics::paths::event_id_t emission_id) final override; private: - diagnostic_event_id_t m_original_setjmp_event_id; + diagnostics::paths::event_id_t m_original_setjmp_event_id; }; /* An abstract subclass for throwing/rethrowing an exception. */ diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index 45593e0..646d72c 100644 --- a/gcc/analyzer/checker-path.cc +++ b/gcc/analyzer/checker-path.cc @@ -1,4 +1,4 @@ -/* Subclass of diagnostic_path for analyzer diagnostics. +/* Subclass of diagnostics::paths::path for analyzer diagnostics. Copyright (C) 2019-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.com>. diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h index 3c174bf..490d21b 100644 --- a/gcc/analyzer/checker-path.h +++ b/gcc/analyzer/checker-path.h @@ -1,4 +1,4 @@ -/* Subclass of diagnostic_path for analyzer diagnostics. +/* Subclass of diagnostics::paths::path for analyzer diagnostics. Copyright (C) 2019-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.com>. @@ -26,28 +26,29 @@ along with GCC; see the file COPYING3. If not see namespace ana { -/* Subclass of diagnostic_path for analyzer diagnostics. */ +/* Subclass of diagnostic path for analyzer diagnostics. */ -class checker_path : public diagnostic_path +class checker_path : public diagnostics::paths::path { public: - checker_path (const logical_location_manager &logical_loc_mgr, + checker_path (const diagnostics::logical_locations::manager &logical_loc_mgr, const extrinsic_state &ext_state, logger *logger) - : diagnostic_path (logical_loc_mgr), + : diagnostics::paths::path (logical_loc_mgr), m_ext_state (ext_state), m_thread ("main"), m_logger (logger) {} - /* Implementation of diagnostic_path vfuncs. */ + /* Implementation of diagnostics::paths::path vfuncs. */ unsigned num_events () const final override { return m_events.length (); } - const diagnostic_event & get_event (int idx) const final override + const diagnostics::paths::event & + get_event (int idx) const final override { return *m_events[idx]; } @@ -55,8 +56,8 @@ public: { return 1; } - const diagnostic_thread & - get_thread (diagnostic_thread_id_t) const final override + const diagnostics::paths::thread & + get_thread (diagnostics::paths::thread_id_t) const final override { return m_thread; } @@ -115,21 +116,22 @@ public: checker_event *e; int i; FOR_EACH_VEC_ELT (m_events, i, e) - e->prepare_for_emission (this, pd, diagnostic_event_id_t (i)); + e->prepare_for_emission (this, pd, diagnostics::paths::event_id_t (i)); } void fixup_locations (pending_diagnostic *pd); void record_setjmp_event (const exploded_node *enode, - diagnostic_event_id_t setjmp_emission_id) + diagnostics::paths::event_id_t setjmp_emission_id) { m_setjmp_event_ids.put (enode, setjmp_emission_id); } bool get_setjmp_event (const exploded_node *enode, - diagnostic_event_id_t *out_emission_id) + diagnostics::paths::event_id_t *out_emission_id) { - if (diagnostic_event_id_t *emission_id = m_setjmp_event_ids.get (enode)) + if (diagnostics::paths::event_id_t *emission_id + = m_setjmp_event_ids.get (enode)) { *out_emission_id = *emission_id; return true; @@ -154,7 +156,7 @@ private: /* During prepare_for_emission (and after), the setjmp_event for each exploded_node *, so that rewind events can refer to them in their descriptions. */ - hash_map <const exploded_node *, diagnostic_event_id_t> m_setjmp_event_ids; + hash_map <const exploded_node *, diagnostics::paths::event_id_t> m_setjmp_event_ids; logger *m_logger; }; diff --git a/gcc/analyzer/common.h b/gcc/analyzer/common.h index 148bfdd..ac3048c 100644 --- a/gcc/analyzer/common.h +++ b/gcc/analyzer/common.h @@ -34,7 +34,7 @@ along with GCC; see the file COPYING3. If not see #include "options.h" #include "bitmap.h" #include "diagnostic-core.h" -#include "diagnostic-path.h" +#include "diagnostics/paths.h" #include "rich-location.h" #include "function.h" #include "json.h" @@ -443,7 +443,7 @@ extern std::unique_ptr<json::value> tree_to_json (tree node); extern std::unique_ptr<json::value> -diagnostic_event_id_to_json (const diagnostic_event_id_t &); +diagnostic_event_id_to_json (const diagnostics::paths::event_id_t &); extern std::unique_ptr<json::value> bit_offset_to_json (const bit_offset_t &offset); diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index c083b8c..88f72d1 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -29,7 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "digraph.h" #include "gcc-rich-location.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/sm.h" @@ -1017,9 +1017,10 @@ saved_diagnostic::emit_any_notes () const This extra data is intended for use when debugging the analyzer. */ void -saved_diagnostic::maybe_add_sarif_properties (sarif_object &result_obj) const +saved_diagnostic:: +maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/saved_diagnostic/" if (m_sm) props.set_string (PROPERTY_PREFIX "sm", m_sm->get_name ()); @@ -1044,7 +1045,7 @@ saved_diagnostic::maybe_add_sarif_properties (sarif_object &result_obj) const auto duplicates_arr = std::make_unique<json::array> (); for (auto iter : m_duplicates) { - auto sd_obj = std::make_unique<sarif_object> (); + auto sd_obj = std::make_unique<diagnostics::sarif_object> (); iter->maybe_add_sarif_properties (*sd_obj); duplicates_arr->append (std::move (sd_obj)); } @@ -1541,12 +1542,12 @@ diagnostic_manager::emit_saved_diagnostics (const exploded_graph &eg) best_candidates.emit_best (this, eg); } -/* Custom subclass of diagnostic_metadata which, for SARIF output, +/* Custom subclass of diagnostics::metadata which, for SARIF output, populates the property bag of the diagnostic's "result" object with information from the saved_diagnostic and the pending_diagnostic. */ -class pending_diagnostic_metadata : public diagnostic_metadata +class pending_diagnostic_metadata : public diagnostics::metadata { public: pending_diagnostic_metadata (const saved_diagnostic &sd) @@ -1555,7 +1556,8 @@ public: } void - maybe_add_sarif_properties (sarif_object &result_obj) const override + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) + const override { m_sd.maybe_add_sarif_properties (result_obj); } @@ -1583,7 +1585,7 @@ diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg, /* Precompute all enodes from which the diagnostic is reachable. */ path_builder pb (eg, *epath, sd.get_feasibility_problem (), sd); - /* This is the diagnostic_path subclass that will be built for + /* This is the diagnostics::paths::path subclass that will be built for the diagnostic. */ checker_path emission_path (get_logical_location_manager (), eg.get_ext_state (), @@ -1663,7 +1665,7 @@ diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg, } } -const logical_location_manager & +const diagnostics::logical_locations::manager & diagnostic_manager::get_logical_location_manager () const { gcc_assert (global_dc); diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h index aa0bd79..d9cf109 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -67,7 +67,8 @@ public: void emit_any_notes () const; - void maybe_add_sarif_properties (sarif_object &result_obj) const; + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const; //private: const state_machine *m_sm; @@ -191,7 +192,7 @@ public: } private: - const logical_location_manager & + const diagnostics::logical_locations::manager & get_logical_location_manager () const; void build_emission_path (const path_builder &pb, diff --git a/gcc/analyzer/infinite-loop.cc b/gcc/analyzer/infinite-loop.cc index ec0b079..a53807c 100644 --- a/gcc/analyzer/infinite-loop.cc +++ b/gcc/analyzer/infinite-loop.cc @@ -25,7 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-pretty-print.h" #include "cgraph.h" #include "digraph.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/call-string.h" @@ -307,10 +307,11 @@ public: } } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/infinite_loop_diagnostic/" props.set (PROPERTY_PREFIX "inf_loop", m_inf_loop->to_json ()); #undef PROPERTY_PREFIX diff --git a/gcc/analyzer/infinite-recursion.cc b/gcc/analyzer/infinite-recursion.cc index b80b94a..960b487 100644 --- a/gcc/analyzer/infinite-recursion.cc +++ b/gcc/analyzer/infinite-recursion.cc @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-pretty-print.h" #include "cgraph.h" #include "digraph.h" +#include "diagnostics/sarif-sink.h" #include "analyzer/analyzer-logging.h" #include "analyzer/call-string.h" @@ -40,7 +41,6 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/exploded-graph.h" #include "analyzer/checker-path.h" #include "analyzer/feasible-graph.h" -#include "diagnostic-format-sarif.h" /* A subclass of pending_diagnostic for complaining about suspected infinite recursion. */ @@ -223,10 +223,11 @@ public: return false; } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/infinite_recursion_diagnostic/" props.set_integer (PROPERTY_PREFIX "prev_entry_enode", m_prev_entry_enode->m_index); diff --git a/gcc/analyzer/kf.cc b/gcc/analyzer/kf.cc index fe25520..2a7c357 100644 --- a/gcc/analyzer/kf.cc +++ b/gcc/analyzer/kf.cc @@ -783,7 +783,7 @@ public: /* SEI CERT C Coding Standard: "POS34-C. Do not call putenv() with a pointer to an automatic variable as the argument". */ - diagnostic_metadata::precanned_rule + diagnostics::metadata::precanned_rule rule ("POS34-C", "https://wiki.sei.cmu.edu/confluence/x/6NYxBQ"); ctxt.add_rule (rule); diff --git a/gcc/analyzer/pending-diagnostic.cc b/gcc/analyzer/pending-diagnostic.cc index 5e95edd..cc2d795 100644 --- a/gcc/analyzer/pending-diagnostic.cc +++ b/gcc/analyzer/pending-diagnostic.cc @@ -20,7 +20,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "cpplib.h" #include "digraph.h" #include "ordered-hash-map.h" @@ -92,7 +92,7 @@ diagnostic_emission_context::warn (const char *gmsgid, ...) auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); - const bool result = emit_diagnostic_valist_meta (DK_WARNING, + const bool result = emit_diagnostic_valist_meta (diagnostics::kind::warning, &m_rich_loc, &m_metadata, pd.get_controlling_option (), gmsgid, &ap); @@ -110,7 +110,7 @@ diagnostic_emission_context::inform (const char *gmsgid, ...) auto_diagnostic_group d; va_list ap; va_start (ap, gmsgid); - emit_diagnostic_valist_meta (DK_NOTE, + emit_diagnostic_valist_meta (diagnostics::kind::note, &m_rich_loc, &m_metadata, pd.get_controlling_option (), gmsgid, &ap); diff --git a/gcc/analyzer/pending-diagnostic.h b/gcc/analyzer/pending-diagnostic.h index 469513c..b5d90a2 100644 --- a/gcc/analyzer/pending-diagnostic.h +++ b/gcc/analyzer/pending-diagnostic.h @@ -21,8 +21,7 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_ANALYZER_PENDING_DIAGNOSTIC_H #define GCC_ANALYZER_PENDING_DIAGNOSTIC_H -#include "diagnostic-metadata.h" -#include "diagnostic-path.h" +#include "diagnostics/metadata.h" #include "analyzer/sm.h" namespace ana { @@ -44,7 +43,7 @@ struct interesting_t }; /* Various bundles of information used for generating more precise - messages for events within a diagnostic_path, for passing to the + messages for events within a diagnostic path, for passing to the various "describe_*" vfuncs of pending_diagnostic. See those for more information. */ @@ -58,7 +57,7 @@ struct state_change tree origin, state_machine::state_t old_state, state_machine::state_t new_state, - diagnostic_event_id_t event_id, + diagnostics::paths::event_id_t event_id, const state_change_event &event) : m_expr (expr), m_origin (origin), m_old_state (old_state), m_new_state (new_state), @@ -71,7 +70,7 @@ struct state_change tree m_origin; state_machine::state_t m_old_state; state_machine::state_t m_new_state; - diagnostic_event_id_t m_event_id; + diagnostics::paths::event_id_t m_event_id; const state_change_event &m_event; }; @@ -131,14 +130,14 @@ struct final_event pending_diagnostic::emit vfunc. The rich_location will have already been populated with a - diagnostic_path. */ + diagnostics::paths::path. */ class diagnostic_emission_context { public: diagnostic_emission_context (const saved_diagnostic &sd, rich_location &rich_loc, - diagnostic_metadata &metadata, + diagnostics::metadata &metadata, logger *logger) : m_sd (sd), m_rich_loc (rich_loc), @@ -156,7 +155,7 @@ public: logger *get_logger () const { return m_logger; } void add_cwe (int cwe) { m_metadata.add_cwe (cwe); } - void add_rule (const diagnostic_metadata::rule &r) + void add_rule (const diagnostics::metadata::rule &r) { m_metadata.add_rule (r); } @@ -164,7 +163,7 @@ public: private: const saved_diagnostic &m_sd; rich_location &m_rich_loc; - diagnostic_metadata &m_metadata; + diagnostics::metadata &m_metadata; logger *m_logger; }; @@ -182,7 +181,7 @@ private: As well as emitting a diagnostic, the class has various "precision of wording" virtual functions, for generating descriptions for events - within a diagnostic_path. These are optional, but implementing these + within a diagnostic path. These are optional, but implementing these allows for more precise wordings than the more generic implementation. */ @@ -238,7 +237,7 @@ class pending_diagnostic virtual location_t fixup_location (location_t loc, bool primary) const; /* Precision-of-wording vfunc for describing a critical state change - within the diagnostic_path. + within the diagnostic path. For example, a double-free diagnostic might use the descriptions: - "first 'free' happens here" @@ -260,13 +259,13 @@ class pending_diagnostic return false; } - /* Vfunc for implementing diagnostic_event::get_meaning for + /* Vfunc for implementing event::get_meaning for state_change_event. */ - virtual diagnostic_event::meaning + virtual diagnostics::paths::event::meaning get_meaning_for_state_change (const evdesc::state_change &) const { /* Default no-op implementation. */ - return diagnostic_event::meaning (); + return diagnostics::paths::event::meaning (); } /* Precision-of-wording vfunc for describing an interprocedural call @@ -285,7 +284,7 @@ class pending_diagnostic } /* Precision-of-wording vfunc for describing an interprocedural return - within the diagnostic_path that carries critial state for the + within the diagnostic path that carries critial state for the diagnostic, from callee back to caller. For example, a deref-of-unchecked-malloc diagnostic might use: @@ -301,7 +300,7 @@ class pending_diagnostic } /* Precision-of-wording vfunc for describing the final event within a - diagnostic_path. + diagnostic path. For example a double-free diagnostic might use: - "second 'free' here; first 'free' was at (3)" @@ -402,7 +401,8 @@ class pending_diagnostic the opportunity to add diagnostic-specific properties to the SARIF "result" object for the diagnostic. This is intended for use when debugging a diagnostic. */ - virtual void maybe_add_sarif_properties (sarif_object &/*result_obj*/) const + virtual void + maybe_add_sarif_properties (diagnostics::sarif_object &/*result_obj*/) const { /* Default no-op implementation. */ } diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc index 1f82559..9baa007 100644 --- a/gcc/analyzer/program-point.cc +++ b/gcc/analyzer/program-point.cc @@ -20,7 +20,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "gcc-rich-location.h" #include "gimple-pretty-print.h" #include "sbitmap.h" @@ -234,17 +234,18 @@ function_point::before_supernode (const supernode *supernode, return function_point (supernode, from_edge, 0, PK_BEFORE_SUPERNODE); } -/* A subclass of diagnostic_context for use by +/* A subclass of diagnostics::context for use by program_point::print_source_line. */ -class debug_diagnostic_context : public diagnostic_context +class debug_diagnostic_context : public diagnostics::context { public: debug_diagnostic_context () { diagnostic_initialize (this, 0); - m_source_printing.show_line_numbers_p = true; - m_source_printing.enabled = true; + auto &source_printing_opts = get_source_printing_options (); + source_printing_opts.show_line_numbers_p = true; + source_printing_opts.enabled = true; } ~debug_diagnostic_context () { @@ -263,9 +264,9 @@ function_point::print_source_line (pretty_printer *pp) const // TODO: monospace font debug_diagnostic_context tmp_dc; gcc_rich_location richloc (stmt->location); - diagnostic_source_print_policy source_policy (tmp_dc); + diagnostics::source_print_policy source_policy (tmp_dc); gcc_assert (pp); - source_policy.print (*pp, richloc, DK_ERROR, nullptr); + source_policy.print (*pp, richloc, diagnostics::kind::error, nullptr); pp_string (pp, pp_formatted_text (tmp_dc.get_reference_printer ())); } diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc index 85cbe75..e16a50f 100644 --- a/gcc/analyzer/program-state.cc +++ b/gcc/analyzer/program-state.cc @@ -27,8 +27,8 @@ along with GCC; see the file COPYING3. If not see #include "gimple-iterator.h" #include "cgraph.h" #include "digraph.h" -#include "diagnostic-event-id.h" -#include "diagnostic-state-graphs.h" +#include "diagnostics/event-id.h" +#include "diagnostics/state-graphs.h" #include "graphviz.h" #include "text-art/tree-widget.h" diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 6df3842..618d96b 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -26,7 +26,7 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "cfg.h" #include "sbitmap.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "stor-layout.h" #include "stringpool.h" #include "attribs.h" @@ -40,7 +40,7 @@ along with GCC; see the file COPYING3. If not see #include "is-a.h" #include "gcc-rich-location.h" #include "gcc-urlifier.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "tree-pretty-print.h" #include "fold-const.h" #include "selftest-tree.h" @@ -907,9 +907,10 @@ public: } void - maybe_add_sarif_properties (sarif_object &result_obj) const final override + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) + const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/poisoned_value_diagnostic/" props.set (PROPERTY_PREFIX "expr", tree_to_json (m_expr)); props.set_string (PROPERTY_PREFIX "kind", poison_kind_to_str (m_pkind)); @@ -3835,10 +3836,11 @@ public: interest->add_region_creation (m_rhs); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/dubious_allocation_size/" props.set (PROPERTY_PREFIX "lhs", m_lhs->to_json ()); props.set (PROPERTY_PREFIX "rhs", m_rhs->to_json ()); @@ -7595,9 +7597,10 @@ public: } void - maybe_add_sarif_properties (sarif_object &result_obj) const final override + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) + const final override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/-Wanalyzer-exposure-through-uninit-copy/" props.set (PROPERTY_PREFIX "src_region", m_src_region->to_json ()); props.set (PROPERTY_PREFIX "dest_region", m_dest_region->to_json ()); diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc index 370d7a0..b8ae0a1 100644 --- a/gcc/analyzer/sm-fd.cc +++ b/gcc/analyzer/sm-fd.cc @@ -20,7 +20,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "stringpool.h" #include "attribs.h" @@ -392,21 +392,22 @@ public: return false; } - diagnostic_event::meaning + diagnostics::paths::event::meaning get_meaning_for_state_change ( const evdesc::state_change &change) const final override { + using event = diagnostics::paths::event; if (change.m_old_state == m_sm.get_start_state () && (m_sm.is_unchecked_fd_p (change.m_new_state) || change.m_new_state == m_sm.m_new_datagram_socket || change.m_new_state == m_sm.m_new_stream_socket || change.m_new_state == m_sm.m_new_unknown_socket)) - return diagnostic_event::meaning (diagnostic_event::verb::acquire, - diagnostic_event::noun::resource); + return event::meaning (event::verb::acquire, + event::noun::resource); if (change.m_new_state == m_sm.m_closed) - return diagnostic_event::meaning (diagnostic_event::verb::release, - diagnostic_event::noun::resource); - return diagnostic_event::meaning (); + return event::meaning (event::verb::release, + event::noun::resource); + return event::meaning (); } protected: @@ -561,7 +562,7 @@ public: } private: - diagnostic_event_id_t m_open_event; + diagnostics::paths::event_id_t m_open_event; std::unique_ptr<program_state> m_final_state; }; @@ -705,7 +706,7 @@ public: } private: - diagnostic_event_id_t m_first_close_event; + diagnostics::paths::event_id_t m_first_close_event; }; class fd_use_after_close : public fd_param_diagnostic @@ -784,7 +785,7 @@ public: } private: - diagnostic_event_id_t m_first_close_event; + diagnostics::paths::event_id_t m_first_close_event; }; class fd_use_without_check : public fd_param_diagnostic @@ -854,7 +855,7 @@ public: } private: - diagnostic_event_id_t m_first_open_event; + diagnostics::paths::event_id_t m_first_open_event; }; /* Concrete pending_diagnostic subclass for -Wanalyzer-fd-phase-mismatch. */ diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc index 4b1fc77..c852c02 100644 --- a/gcc/analyzer/sm-file.cc +++ b/gcc/analyzer/sm-file.cc @@ -20,7 +20,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "selftest.h" #include "analyzer/analyzer-logging.h" @@ -155,18 +155,20 @@ public: return false; } - diagnostic_event::meaning + diagnostics::paths::event::meaning get_meaning_for_state_change (const evdesc::state_change &change) const final override { + using event = diagnostics::paths::event; + if (change.m_old_state == m_sm.get_start_state () && change.m_new_state == m_sm.m_unchecked) - return diagnostic_event::meaning (diagnostic_event::verb::acquire, - diagnostic_event::noun::resource); + return event::meaning (event::verb::acquire, + event::noun::resource); if (change.m_new_state == m_sm.m_closed) - return diagnostic_event::meaning (diagnostic_event::verb::release, - diagnostic_event::noun::resource); - return diagnostic_event::meaning (); + return event::meaning (event::verb::release, + event::noun::resource); + return event::meaning (); } protected: @@ -225,7 +227,7 @@ public: } private: - diagnostic_event_id_t m_first_fclose_event; + diagnostics::paths::event_id_t m_first_fclose_event; }; class file_leak : public file_diagnostic @@ -303,7 +305,7 @@ public: } private: - diagnostic_event_id_t m_fopen_event; + diagnostics::paths::event_id_t m_fopen_event; std::unique_ptr<program_state> m_final_state; }; diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index 2a218d0..a6b1421 100644 --- a/gcc/analyzer/sm-malloc.cc +++ b/gcc/analyzer/sm-malloc.cc @@ -20,7 +20,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "stringpool.h" #include "attribs.h" #include "xml-printer.h" @@ -814,18 +814,18 @@ public: return false; } - diagnostic_event::meaning + diagnostics::paths::event::meaning get_meaning_for_state_change (const evdesc::state_change &change) const final override { if (change.m_old_state == m_sm.get_start_state () && unchecked_p (change.m_new_state)) - return diagnostic_event::meaning (diagnostic_event::verb::acquire, - diagnostic_event::noun::memory); + return diagnostics::paths::event::meaning (diagnostics::paths::event::verb::acquire, + diagnostics::paths::event::noun::memory); if (freed_p (change.m_new_state)) - return diagnostic_event::meaning (diagnostic_event::verb::release, - diagnostic_event::noun::memory); - return diagnostic_event::meaning (); + return diagnostics::paths::event::meaning (diagnostics::paths::event::verb::release, + diagnostics::paths::event::noun::memory); + return diagnostics::paths::event::meaning (); } protected: @@ -918,7 +918,7 @@ public: } private: - diagnostic_event_id_t m_alloc_event; + diagnostics::paths::event_id_t m_alloc_event; const deallocator_set *m_expected_deallocators; const deallocator *m_actual_dealloc; }; @@ -988,7 +988,7 @@ public: } private: - diagnostic_event_id_t m_first_free_event; + diagnostics::paths::event_id_t m_first_free_event; const char *m_funcname; }; @@ -1031,7 +1031,7 @@ public: } protected: - diagnostic_event_id_t m_origin_of_unchecked_event; + diagnostics::paths::event_id_t m_origin_of_unchecked_event; }; /* Concrete subclass for describing dereference of a possible NULL @@ -1419,7 +1419,7 @@ public: } private: - diagnostic_event_id_t m_free_event; + diagnostics::paths::event_id_t m_free_event; const deallocator *m_deallocator; }; @@ -1500,7 +1500,7 @@ public: } private: - diagnostic_event_id_t m_alloc_event; + diagnostics::paths::event_id_t m_alloc_event; std::unique_ptr<program_state> m_final_state; }; @@ -1768,7 +1768,7 @@ private: return result; } - diagnostic_event_id_t m_first_deref_event; + diagnostics::paths::event_id_t m_first_deref_event; const exploded_node *m_deref_enode; tree m_deref_expr; const exploded_node *m_check_enode; diff --git a/gcc/analyzer/sm-pattern-test.cc b/gcc/analyzer/sm-pattern-test.cc index 02b32ac..12449a1 100644 --- a/gcc/analyzer/sm-pattern-test.cc +++ b/gcc/analyzer/sm-pattern-test.cc @@ -23,7 +23,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" #include "tree-pretty-print.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "analyzer/analyzer-logging.h" #include "analyzer/sm.h" diff --git a/gcc/analyzer/sm-sensitive.cc b/gcc/analyzer/sm-sensitive.cc index f8fcded..4611b10e 100644 --- a/gcc/analyzer/sm-sensitive.cc +++ b/gcc/analyzer/sm-sensitive.cc @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "analyzer/analyzer-logging.h" #include "analyzer/sm.h" @@ -106,14 +106,15 @@ public: return false; } - diagnostic_event::meaning + diagnostics::paths::event::meaning get_meaning_for_state_change (const evdesc::state_change &change) const final override { + using event = diagnostics::paths::event; + if (change.m_new_state == m_sm.m_sensitive) - return diagnostic_event::meaning (diagnostic_event::verb::acquire, - diagnostic_event::noun::sensitive); - return diagnostic_event::meaning (); + return event::meaning (event::verb::acquire, event::noun::sensitive); + return event::meaning (); } bool describe_call_with_state (pretty_printer &pp, @@ -162,7 +163,7 @@ public: private: const sensitive_state_machine &m_sm; tree m_arg; - diagnostic_event_id_t m_first_sensitive_event; + diagnostics::paths::event_id_t m_first_sensitive_event; }; /* sensitive_state_machine's ctor. */ diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc index 5a4b384..35ecde1 100644 --- a/gcc/analyzer/sm-signal.cc +++ b/gcc/analyzer/sm-signal.cc @@ -22,7 +22,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/common.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "sbitmap.h" #include "ordered-hash-map.h" #include "selftest.h" diff --git a/gcc/analyzer/sm-taint.cc b/gcc/analyzer/sm-taint.cc index 5c8cc7e..f2a94e8 100644 --- a/gcc/analyzer/sm-taint.cc +++ b/gcc/analyzer/sm-taint.cc @@ -30,7 +30,7 @@ along with GCC; see the file COPYING3. If not see #include "stringpool.h" #include "attribs.h" #include "fold-const.h" -#include "diagnostic-format-sarif.h" +#include "diagnostics/sarif-sink.h" #include "gcc-urlifier.h" #include "analyzer/analyzer-logging.h" @@ -209,20 +209,22 @@ public: return false; } - diagnostic_event::meaning + diagnostics::paths::event::meaning get_meaning_for_state_change (const evdesc::state_change &change) const final override { + using event = diagnostics::paths::event; if (change.m_new_state == m_sm.m_tainted) - return diagnostic_event::meaning (diagnostic_event::verb::acquire, - diagnostic_event::noun::taint); - return diagnostic_event::meaning (); + return event::meaning (event::verb::acquire, + event::noun::taint); + return event::meaning (); } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const override { - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/taint_diagnostic/" props.set (PROPERTY_PREFIX "arg", tree_to_json (m_arg)); props.set_string (PROPERTY_PREFIX "has_bounds", @@ -495,11 +497,12 @@ public: } } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { taint_diagnostic::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/tainted_offset/" props.set (PROPERTY_PREFIX "offset", m_offset->to_json ()); #undef PROPERTY_PREFIX @@ -864,11 +867,12 @@ public: } } - void maybe_add_sarif_properties (sarif_object &result_obj) + void + maybe_add_sarif_properties (diagnostics::sarif_object &result_obj) const final override { taint_diagnostic::maybe_add_sarif_properties (result_obj); - sarif_property_bag &props = result_obj.get_or_create_properties (); + auto &props = result_obj.get_or_create_properties (); #define PROPERTY_PREFIX "gcc/analyzer/tainted_allocation_size/" props.set (PROPERTY_PREFIX "size_in_bytes", m_size_in_bytes->to_json ()); #undef PROPERTY_PREFIX diff --git a/gcc/analyzer/varargs.cc b/gcc/analyzer/varargs.cc index 4947271..1fdfd34 100644 --- a/gcc/analyzer/varargs.cc +++ b/gcc/analyzer/varargs.cc @@ -334,17 +334,17 @@ public: return false; } - diagnostic_event::meaning + diagnostics::paths::event::meaning get_meaning_for_state_change (const evdesc::state_change &change) const final override { if (change.m_new_state == m_sm.m_started) - return diagnostic_event::meaning (diagnostic_event::verb::acquire, - diagnostic_event::noun::resource); + return diagnostics::paths::event::meaning (diagnostics::paths::event::verb::acquire, + diagnostics::paths::event::noun::resource); if (change.m_new_state == m_sm.m_ended) - return diagnostic_event::meaning (diagnostic_event::verb::release, - diagnostic_event::noun::resource); - return diagnostic_event::meaning (); + return diagnostics::paths::event::meaning (diagnostics::paths::event::verb::release, + diagnostics::paths::event::noun::resource); + return diagnostics::paths::event::meaning (); } protected: @@ -452,7 +452,7 @@ public: } private: - diagnostic_event_id_t m_va_end_event; + diagnostics::paths::event_id_t m_va_end_event; const char *m_usage_fnname; }; @@ -539,7 +539,7 @@ public: } private: - diagnostic_event_id_t m_start_event; + diagnostics::paths::event_id_t m_start_event; const char *m_start_event_fnname; std::unique_ptr<program_state> m_final_state; }; |