LCOV - code coverage report
Current view: top level - gcc/analyzer - common.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 95.5 % 66 63
Test Date: 2026-11-14 16:39:50 Functions: 95.2 % 21 20
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Base header for the analyzer, plus utility functions.
       2              :    Copyright (C) 2019-2026 Free Software Foundation, Inc.
       3              :    Contributed by David Malcolm <dmalcolm@redhat.com>.
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify it
       8              : under the terms of the GNU General Public License as published by
       9              : the Free Software Foundation; either version 3, or (at your option)
      10              : any later version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful, but
      13              : WITHOUT ANY WARRANTY; without even the implied warranty of
      14              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15              : General Public License for more details.
      16              : 
      17              : You should have received a copy of the GNU General Public License
      18              : along with GCC; see the file COPYING3.  If not see
      19              : <http://www.gnu.org/licenses/>.  */
      20              : 
      21              : #ifndef GCC_ANALYZER_COMMON_H
      22              : #define GCC_ANALYZER_COMMON_H
      23              : 
      24              : #include "config.h"
      25              : #define INCLUDE_ALGORITHM
      26              : #define INCLUDE_LIST
      27              : #define INCLUDE_MAP
      28              : #define INCLUDE_SET
      29              : #define INCLUDE_STRING
      30              : #define INCLUDE_VECTOR
      31              : #include "system.h"
      32              : #include "coretypes.h"
      33              : #include "tree.h"
      34              : #include "function.h"
      35              : #include "basic-block.h"
      36              : #include "gimple.h"
      37              : #include "options.h"
      38              : #include "bitmap.h"
      39              : #include "diagnostic-core.h"
      40              : #include "diagnostics/paths.h"
      41              : #include "rich-location.h"
      42              : #include "function.h"
      43              : #include "json.h"
      44              : #include "tristate.h"
      45              : #include "value-range.h"
      46              : 
      47              : class graphviz_out;
      48              : 
      49              : namespace diagnostics {
      50              : namespace markup {
      51              : 
      52              : class node;
      53              : class lowering_options;
      54              : 
      55              : } } // namespace diagnostics:markup
      56              : 
      57              : namespace ana {
      58              : 
      59              : /* Forward decls of common types, with indentation to show inheritance.  */
      60              : 
      61              : class supergraph;
      62              : class supernode;
      63              : class superedge;
      64              : 
      65              : class integer;
      66              : template<typename Unit> class integer_with_unit;
      67              : 
      68              : namespace units {
      69              :   struct bit;
      70              :   struct byte;
      71              : }
      72              : 
      73              : namespace symbolic
      74              : {
      75              :   template<typename ConcreteValueType>
      76              :   class range;
      77              : 
      78              :   class node_dump_state;
      79              :   template <typename NodeClass> class node_set;
      80              : 
      81              :   class node_visitor;
      82              :   class liveness_context;
      83              :   struct markup_context;
      84              : 
      85              :   class node;
      86              :     class bit_contents;
      87              :       class unfoldable_bit_contents;
      88              :         class baseline_bit_contents;
      89              :         class conjured_bit_contents;
      90              :         class offset_bit_contents;
      91              :       class uniform_bit_contents;
      92              :       class bit_overlay;
      93              :         class concrete_bit_overlay;
      94              :         class symbolic_bit_overlay;
      95              : 
      96              :     template <typename ConcreteValueType>
      97              :     class scalar;
      98              : 
      99              :     class value_node;
     100              :       class bit_vector;
     101              :         class concat_bit_vector;
     102              :         class conjured_bit_vector;
     103              :         class constant_bit_vector;
     104              :         class cropped_bit_vector;
     105              :         class repeated_bit_vector;
     106              :         class bit_vector_from_svalue;
     107              :         class bit_vector_from_ubc;
     108              :         class uniform_bit_vector;
     109              :           class empty_bit_vector;
     110              :           class poisoned_bit_vector;
     111              :           class tristate_bit_vector;
     112              : 
     113              :   /* Top-level manager class.  */
     114              :   class node_manager;
     115              : 
     116              :   /* Managers for specific kinds of symbolic::node.  */
     117              :   class bit_contents_manager;
     118              :   class bit_vector_manager;
     119              :   class scalar_managers;
     120              :   template<typename ConcreteValueType> class scalar_manager;
     121              : 
     122              : } // namespace ana::symbolic
     123              : 
     124              : using symbolic_bit_range = symbolic::range<integer_with_unit<units::bit>>;
     125              : using symbolic_byte_range = symbolic::range<integer_with_unit<units::byte>>;
     126              : 
     127              : class svalue;
     128              :   class pointer_svalue;
     129              :   class constant_svalue;
     130              :   class unknown_svalue;
     131              :   class poisoned_svalue;
     132              :   class setjmp_svalue;
     133              :   class initial_svalue;
     134              :   class unaryop_svalue;
     135              :   class binop_svalue;
     136              :   class svalue_from_bit_vector;
     137              :   class unmergeable_svalue;
     138              :   class placeholder_svalue;
     139              :   class widening_svalue;
     140              :   class asm_output_svalue;
     141              :   class const_fn_result_svalue;
     142              : class region;
     143              :   class frame_region;
     144              :   class function_region;
     145              :   class label_region;
     146              :   class decl_region;
     147              :   class symbolic_region;
     148              :   class element_region;
     149              :   class offset_region;
     150              :   class sized_region;
     151              :   class cast_region;
     152              :   class field_region;
     153              :   class string_region;
     154              :   class bit_range_region;
     155              :   class var_arg_region;
     156              : class region_model_manager;
     157              : class conjured_purge;
     158              : struct model_merger;
     159              : class store;
     160              : class region_model;
     161              : class region_model_context;
     162              :   class impl_region_model_context;
     163              : class call_details;
     164              : class rejected_constraint;
     165              : class constraint_manager;
     166              : class equiv_class;
     167              : class reachable_regions;
     168              : class bounded_ranges;
     169              : class bounded_ranges_manager;
     170              : 
     171              : class setjmp_record;
     172              : 
     173              : struct pending_location;
     174              : class pending_diagnostic;
     175              : class pending_note;
     176              : class saved_diagnostic;
     177              : struct event_loc_info;
     178              : class checker_event;
     179              :   class state_change_event;
     180              :   class warning_event;
     181              : class checker_path;
     182              : class extrinsic_state;
     183              : class sm_state_map;
     184              : class call_string;
     185              : class program_point;
     186              : class program_state;
     187              : class exploded_graph;
     188              : class exploded_node;
     189              : class exploded_edge;
     190              : class feasibility_problem;
     191              : class feasibility_state;
     192              : class exploded_cluster;
     193              : class exploded_path;
     194              : class analysis_plan;
     195              : class state_purge_map;
     196              : class state_purge_per_ssa_name;
     197              : class state_purge_per_decl;
     198              : class state_change;
     199              : class rewind_info_t;
     200              : 
     201              : class engine;
     202              : class state_machine;
     203              : class logger;
     204              : class visitor;
     205              : class known_function_manager;
     206              : class call_summary;
     207              : class call_summary_replay;
     208              : struct per_function_data;
     209              : struct interesting_t;
     210              : class state_transition;
     211              :   class state_transition_at_call;
     212              :   class state_transition_at_return;
     213              : class uncertainty_t;
     214              : 
     215              : class feasible_node;
     216              : 
     217              : class known_function;
     218              :   class builtin_known_function;
     219              :   class internal_known_function;
     220              : 
     221              : class translation_unit;
     222              : 
     223              : /* Forward decls of functions.  */
     224              : 
     225              : extern void dump_tree (pretty_printer *pp, tree t);
     226              : extern void dump_quoted_tree (pretty_printer *pp, tree t);
     227              : extern void print_quoted_type (pretty_printer *pp, tree t);
     228              : extern void print_expr_for_user (pretty_printer *pp, tree t);
     229              : extern bool printable_expr_p (const_tree expr);
     230              : extern int readability_comparator (const void *p1, const void *p2);
     231              : extern int tree_cmp (const void *p1, const void *p2);
     232              : extern int cmp_types (const_tree a, const_tree b);
     233              : extern tree fixup_tree_for_diagnostic (tree);
     234              : extern tree get_diagnostic_tree_for_gassign (const gassign *);
     235              : 
     236              : inline bool
     237       169064 : useful_location_p (location_t loc)
     238              : {
     239       169064 :   return get_pure_location (loc) != UNKNOWN_LOCATION;
     240              : }
     241              : 
     242              : /* A tree, extended with stack frame information for locals, so that
     243              :    we can distinguish between different values of locals within a potentially
     244              :    recursive callstack.  */
     245              : 
     246              : class path_var
     247              : {
     248              : public:
     249        25694 :   path_var (tree t, int stack_depth)
     250      4215280 :   : m_tree (t), m_stack_depth (stack_depth)
     251              :   {
     252              :     // TODO: ignore stack depth for globals and constants
     253              :   }
     254              : 
     255           40 :   bool operator== (const path_var &other) const
     256              :   {
     257           40 :     return (m_tree == other.m_tree
     258           40 :             && m_stack_depth == other.m_stack_depth);
     259              :   }
     260              : 
     261        10424 :   operator bool () const
     262              :   {
     263        10424 :     return m_tree != NULL_TREE;
     264              :   }
     265              : 
     266              :   void dump (pretty_printer *pp) const;
     267              : 
     268              :   tree m_tree;
     269              :   int m_stack_depth; // or -1 for globals?
     270              : };
     271              : 
     272              : typedef offset_int bit_offset_t;
     273              : typedef offset_int bit_size_t;
     274              : typedef offset_int byte_offset_t;
     275              : typedef offset_int byte_size_t;
     276              : 
     277              : extern bool int_size_in_bits (const_tree type, bit_size_t *out);
     278              : 
     279              : extern bool
     280              : compare_bit_offsets_p (bit_offset_t a,
     281              :                        enum tree_code op,
     282              :                        bit_offset_t b);
     283              : 
     284              : extern int
     285              : cmp_csts_and_types (const_tree cst1, const_tree cst2);
     286              : 
     287              : extern location_t get_stmt_location (const gimple *stmt, function *fun);
     288              : 
     289              : extern bool compat_types_p (tree src_type, tree dst_type);
     290              : 
     291              : /* Abstract base class for simulating the behavior of known functions,
     292              :    supplied by the core of the analyzer, or by plugins.
     293              :    The former are typically implemented in the various kf*.cc  */
     294              : 
     295       207234 : class known_function
     296              : {
     297              : public:
     298          482 :   virtual ~known_function () {}
     299              :   virtual bool matches_call_types_p (const call_details &cd) const = 0;
     300              : 
     301              :   /* A hook for performing additional checks on the expected state
     302              :      at a call.  */
     303              :   virtual void
     304        33237 :   check_any_preconditions (const call_details &) const
     305              :   {
     306              :     // no-op
     307        33237 :   }
     308              : 
     309        16592 :   virtual void impl_call_pre (const call_details &) const
     310              :   {
     311        16592 :     return;
     312              :   }
     313        31641 :   virtual void impl_call_post (const call_details &) const
     314              :   {
     315        31641 :     return;
     316              :   }
     317              : 
     318              :   virtual const builtin_known_function *
     319        48657 :   dyn_cast_builtin_kf () const { return nullptr; }
     320              : };
     321              : 
     322              : /* Subclass of known_function for builtin functions.  */
     323              : 
     324       182223 : class builtin_known_function : public known_function
     325              : {
     326              : public:
     327              :   virtual enum built_in_function builtin_code () const = 0;
     328        63141 :   tree builtin_decl () const {
     329        63141 :     gcc_assert (builtin_code () < END_BUILTINS);
     330        63141 :     return builtin_info[builtin_code ()].decl;
     331              :   }
     332              : 
     333              :   const builtin_known_function *
     334        63141 :   dyn_cast_builtin_kf () const final override { return this; }
     335              : };
     336              : 
     337              : /* Subclass of known_function for IFN_* functions.  */
     338              : 
     339       282267 : class internal_known_function : public known_function
     340              : {
     341              : public:
     342            0 :   bool matches_call_types_p (const call_details &) const final override
     343              :   {
     344              :     /* Types are assumed to be correct.  */
     345            0 :     return true;
     346              :   }
     347              : };
     348              : 
     349              : /* Abstract subclass of known_function that merely sets the return
     350              :    value of the function (based on function attributes), and assumes
     351              :    it has no side-effects.  */
     352              : 
     353       110763 : class pure_known_function_with_default_return : public known_function
     354              : {
     355              : public:
     356              :   void impl_call_pre (const call_details &cd) const override;
     357              : };
     358              : 
     359              : extern void register_known_functions (known_function_manager &kfm,
     360              :                                       region_model_manager &rmm);
     361              : extern void register_known_analyzer_functions (known_function_manager &kfm);
     362              : extern void register_known_fd_functions (known_function_manager &kfm);
     363              : extern void register_known_file_functions (known_function_manager &kfm);
     364              : extern void register_known_functions_lang_cp (known_function_manager &kfm);
     365              : extern void register_varargs_builtins (known_function_manager &kfm);
     366              : 
     367              : /* An enum for describing the direction of an access to memory.  */
     368              : 
     369              : enum class access_direction
     370              : {
     371              :   read,
     372              :   write
     373              : };
     374              : 
     375              : /* State tracked along an execution path that's pertinent to a specific
     376              :    diagnostic (e.g. for a divide-by-zero warning where the zero value
     377              :    comes from).  */
     378              : 
     379       465484 : struct diagnostic_state
     380              : {
     381        86129 :   diagnostic_state ()
     382        86129 :   : m_region_holding_value (nullptr)
     383              :   {
     384              :   }
     385              : 
     386         1202 :   diagnostic_state (std::string debug_desc,
     387              :                    const region *region_holding_value)
     388         1202 :   : m_debug_desc (std::move (debug_desc)),
     389         1202 :     m_region_holding_value (region_holding_value)
     390              :   {
     391              :   }
     392              : 
     393              :   void dump_to_pp (pretty_printer *) const;
     394              :   void dump () const;
     395              : 
     396              :   bool
     397              :   operator== (const diagnostic_state &other) const
     398              :   {
     399              :     return m_region_holding_value == other.m_region_holding_value;
     400              :   }
     401              :   bool
     402              :   operator!= (const diagnostic_state &other) const
     403              :   {
     404              :     return !(*this == other);
     405              :   }
     406              : 
     407              :   std::string m_debug_desc;
     408              :   const region *m_region_holding_value;
     409              : };
     410              : 
     411              : struct rewind_context;
     412              : 
     413              : /* Abstract base class for associating custom data with an
     414              :    exploded_edge, for handling non-standard edges such as
     415              :    rewinding from a longjmp, signal handlers, etc.
     416              :    Also used when "bifurcating" state: splitting the execution
     417              :    path in non-standard ways (e.g. for simulating the various
     418              :    outcomes of "realloc").  */
     419              : 
     420        33420 : class custom_edge_info
     421              : {
     422              : public:
     423           25 :   virtual ~custom_edge_info () {}
     424              : 
     425              :   /* Hook for making .dot label more readable.  */
     426              :   virtual void print (pretty_printer *pp) const = 0;
     427              : 
     428              :   virtual void
     429              :   get_dot_attrs (const char *&out_style,
     430              :                  const char *&out_color) const;
     431              : 
     432              :   /* Hook for updating STATE when handling bifurcation.  */
     433              :   virtual bool update_state (program_state *state,
     434              :                              const exploded_edge *eedge,
     435              :                              region_model_context *ctxt) const;
     436              : 
     437              :   /* Hook for updating MODEL within exploded_path::feasible_p
     438              :      and when handling bifurcation.  */
     439              :   virtual bool update_model (region_model *model,
     440              :                              const exploded_edge *eedge,
     441              :                              region_model_context *ctxt) const = 0;
     442              : 
     443              :   virtual void add_events_to_path (checker_path *emission_path,
     444              :                                    const exploded_edge &eedge,
     445              :                                    pending_diagnostic &pd,
     446              :                                    const state_transition *state_trans) const = 0;
     447              : 
     448              :   virtual exploded_node *create_enode (exploded_graph &eg,
     449              :                                        const program_point &point,
     450              :                                        program_state &&state,
     451              :                                        exploded_node *enode_for_diag,
     452              :                                        region_model_context *ctxt) const;
     453              : 
     454              :   virtual bool
     455          516 :   try_to_rewind_data_flow (rewind_context &) const
     456              :   {
     457          516 :     return false;
     458              :   }
     459              : };
     460              : 
     461              : /* Abstract base class for splitting state.
     462              : 
     463              :    Most of the state-management code in the analyzer involves
     464              :    modifying state objects in-place, which assumes a single outcome.
     465              : 
     466              :    This class provides an escape hatch to allow for multiple outcomes
     467              :    for such updates e.g. for modelling multiple outcomes from function
     468              :    calls, such as the various outcomes of "realloc".  */
     469              : 
     470       214770 : class path_context
     471              : {
     472              : public:
     473       107538 :   virtual ~path_context () {}
     474              : 
     475              :   /* Hook for clients to split state with a non-standard path.  */
     476              :   virtual void bifurcate (std::unique_ptr<custom_edge_info> info) = 0;
     477              : 
     478              :   /* Hook for clients to terminate the standard path.  */
     479              :   virtual void terminate_path () = 0;
     480              : 
     481              :   /* Hook for clients to determine if the standard path has been
     482              :      terminated.  */
     483              :   virtual bool terminate_path_p () const = 0;
     484              : };
     485              : 
     486              : extern tree get_stashed_constant_by_name (const char *name);
     487              : extern void log_stashed_constants (logger *logger);
     488              : 
     489              : extern FILE *get_or_create_any_logfile ();
     490              : 
     491              : extern std::unique_ptr<json::value>
     492              : tree_to_json (tree node);
     493              : 
     494              : extern std::unique_ptr<json::value>
     495              : diagnostic_event_id_to_json (const diagnostics::paths::event_id_t &);
     496              : 
     497              : extern std::unique_ptr<json::value>
     498              : bit_offset_to_json (const bit_offset_t &offset);
     499              : 
     500              : extern std::unique_ptr<json::value>
     501              : byte_offset_to_json (const byte_offset_t &offset);
     502              : 
     503              : extern tristate
     504              : compare_constants (tree lhs_const, enum tree_code op, tree rhs_const);
     505              : 
     506              : extern tree
     507              : get_string_cst_size (const_tree string_cst);
     508              : 
     509              : extern tree
     510              : get_ssa_default_def (const function &fun, tree var);
     511              : 
     512              : extern const svalue *
     513              : strip_types (const svalue *sval, region_model_manager &mgr);
     514              : 
     515              : extern tree remove_ssa_names (tree expr);
     516              : 
     517              : /* An enum describing a particular kind of "poisoned" value.  */
     518              : 
     519              : enum class poison_kind
     520              : {
     521              :   /* For use to describe uninitialized memory.  */
     522              :   uninit,
     523              : 
     524              :   /* For use to describe freed memory.  */
     525              :   freed,
     526              : 
     527              :   /* For use to describe deleted memory.  */
     528              :   deleted,
     529              : 
     530              :   /* For use on pointers to regions within popped stack frames.  */
     531              :   popped_stack,
     532              : 
     533              :   /* Placeholder value (e.g. for string_scan when we don't have
     534              :      a poison_kind).  */
     535              :   other
     536              : };
     537              : 
     538              : extern const char *
     539              : poison_kind_to_str (enum poison_kind);
     540              : 
     541              : /* An enum for discriminating different baseline states,
     542              :    for determining the implicit contents of base regions
     543              :    that don't have their contents explicitly tracked.  */
     544              : 
     545              : enum class baseline_state
     546              : {
     547              :   /* Analysis is on a direct path from entry to "main", so
     548              :      the implicit contents of a global variable is that of
     549              :      its initializer (or 0).  */
     550              :   main,
     551              : 
     552              :   /* Analysis is on an entrypoint that isn't on "main", so
     553              :      the implicit contents of a global variable is its initial_svalue.  */
     554              :   after_main
     555              : };
     556              : 
     557              : extern const char *
     558              : baseline_state_to_str (baseline_state);
     559              : 
     560              : /* An enum for tracking the state of an iteration.  */
     561              : 
     562              : enum class iter_result
     563              : {
     564              :   keep_going,
     565              :   stop
     566              : };
     567              : 
     568              : extern void
     569              : append_pathvar_with_type (path_var pv,
     570              :                           tree type,
     571              :                           auto_vec<path_var> *out_pvs);
     572              : 
     573              : } // namespace ana
     574              : 
     575              : extern bool is_special_named_call_p (const gcall &call, const char *funcname,
     576              :                                      unsigned int num_args,
     577              :                                      bool look_in_std = false);
     578              : extern bool is_named_call_p (const_tree fndecl, const char *funcname);
     579              : extern bool is_named_call_p (const_tree fndecl, const char *funcname,
     580              :                              const gcall &call, unsigned int num_args);
     581              : extern bool is_std_function_p (const_tree fndecl);
     582              : extern bool is_cxxabi_function_p (const_tree fndecl);
     583              : extern bool is_std_named_call_p (const_tree fndecl, const char *funcname);
     584              : extern bool is_std_named_call_p (const_tree fndecl, const char *funcname,
     585              :                                  const gcall &call, unsigned int num_args);
     586              : extern bool is_setjmp_call_p (const gcall &call);
     587              : extern bool is_longjmp_call_p (const gcall &call);
     588              : extern bool is_placement_new_p (const gcall &call);
     589              : extern bool is_cxa_throw_p (const gcall &call);
     590              : extern bool is_cxa_rethrow_p (const gcall &call);
     591              : extern bool is_cxa_end_catch_p (const gcall &call);
     592              : 
     593              : extern const char *get_user_facing_name (const gcall &call);
     594              : 
     595              : extern void register_analyzer_pass ();
     596              : 
     597              : extern label_text make_label_text (bool can_colorize, const char *fmt, ...);
     598              : extern label_text make_label_text_n (bool can_colorize,
     599              :                                      unsigned HOST_WIDE_INT n,
     600              :                                      const char *singular_fmt,
     601              :                                      const char *plural_fmt, ...);
     602              : 
     603              : extern bool fndecl_has_gimple_body_p (tree fndecl);
     604              : 
     605              : /* An RAII-style class for pushing/popping cfun within a scope.
     606              :    Doing so ensures we get "In function " announcements
     607              :    from the diagnostics subsystem.  */
     608              : 
     609              : class auto_cfun
     610              : {
     611              : public:
     612       773555 :   auto_cfun (function *fun) { push_cfun (fun); }
     613       773555 :   ~auto_cfun () { pop_cfun (); }
     614              : };
     615              : 
     616              : /* A template for creating hash traits for a POD type.  */
     617              : 
     618              : template <typename Type>
     619              : struct pod_hash_traits : typed_noop_remove<Type>
     620              : {
     621              :   typedef Type value_type;
     622              :   typedef Type compare_type;
     623              :   static inline hashval_t hash (value_type);
     624              :   static inline bool equal (const value_type &existing,
     625              :                             const value_type &candidate);
     626              :   static inline void mark_deleted (Type &);
     627              :   static inline void mark_empty (Type &);
     628              :   static inline bool is_deleted (Type);
     629              :   static inline bool is_empty (Type);
     630              : };
     631              : 
     632              : /* A hash traits class that uses member functions to implement
     633              :    the various required ops.  */
     634              : 
     635              : template <typename Type>
     636              : struct member_function_hash_traits : public typed_noop_remove<Type>
     637              : {
     638              :   typedef Type value_type;
     639              :   typedef Type compare_type;
     640      2140339 :   static inline hashval_t hash (value_type v) { return v.hash (); }
     641      2038273 :   static inline bool equal (const value_type &existing,
     642              :                             const value_type &candidate)
     643              :   {
     644      4362646 :     return existing == candidate;
     645              :   }
     646              :   static inline void mark_deleted (Type &t) { t.mark_deleted (); }
     647            0 :   static inline void mark_empty (Type &t) { t.mark_empty (); }
     648        80086 :   static inline bool is_deleted (Type t) { return t.is_deleted (); }
     649      8880985 :   static inline bool is_empty (Type t) { return t.is_empty (); }
     650              : };
     651              : 
     652              : /* A map from T::key_t to T* for use in consolidating instances of T.
     653              :    Owns all instances of T.
     654              :    T::key_t should have operator== and be hashable.  */
     655              : 
     656              : template <typename T>
     657              : class consolidation_map
     658              : {
     659              : public:
     660              :   typedef typename T::key_t key_t;
     661              :   typedef T instance_t;
     662              :   typedef hash_map<key_t, instance_t *> inner_map_t;
     663              :   typedef typename inner_map_t::iterator iterator;
     664              : 
     665              :   /* Delete all instances of T.  */
     666              : 
     667        39681 :   ~consolidation_map ()
     668              :   {
     669       111808 :     for (typename inner_map_t::iterator iter = m_inner_map.begin ();
     670       111808 :          iter != m_inner_map.end (); ++iter)
     671        72127 :       delete (*iter).second;
     672        39681 :   }
     673              : 
     674              :   /* Get the instance of T for K if one exists, or nullptr.  */
     675              : 
     676       334475 :   T *get (const key_t &k) const
     677              :   {
     678       334475 :     if (instance_t **slot = const_cast<inner_map_t &> (m_inner_map).get (k))
     679       262348 :       return *slot;
     680              :     return nullptr;
     681              :   }
     682              : 
     683              :   /* Take ownership of INSTANCE.  */
     684              : 
     685        72127 :   void put (const key_t &k, T *instance)
     686              :   {
     687        72127 :     m_inner_map.put (k, instance);
     688              :   }
     689              : 
     690           90 :   size_t elements () const { return m_inner_map.elements (); }
     691              : 
     692           68 :   iterator begin () const { return m_inner_map.begin (); }
     693          110 :   iterator end () const { return m_inner_map.end (); }
     694              : 
     695              : private:
     696              :   inner_map_t m_inner_map;
     697              : };
     698              : 
     699              : /* Disable -Wformat-diag; we want to be able to use pp_printf
     700              :    for logging/dumping without complying with the rules for diagnostics.  */
     701              : #if __GNUC__ >= 10
     702              : #pragma GCC diagnostic ignored "-Wformat-diag"
     703              : #endif
     704              : 
     705              : namespace gcc {
     706              : namespace topics {
     707              : 
     708              : /* A topic for messages relating to the analyzer.  */
     709              : 
     710              : namespace analyzer_events {
     711              : 
     712              : /* A message published by the analyzer when the frontend finishes
     713              :    parsing the TU, to allow it to look up pertinent items using the FE's
     714              :    name-resolution logic.  */
     715              : 
     716              : struct on_tu_finished
     717              : {
     718              :   ana::logger *m_logger;
     719              :   const ana::translation_unit &m_tu;
     720              : };
     721              : 
     722              : /* A message published by the analyzer as it starts up, intended for
     723              :    subsystems/plugins that want to register additional functionality
     724              :    within the analyzer.  */
     725              : 
     726           38 : struct on_ana_init
     727              : {
     728              :   virtual void
     729              :   register_state_machine (std::unique_ptr<ana::state_machine>) const = 0;
     730              : 
     731              :   virtual void
     732              :   register_known_function (const char *name,
     733              :                            std::unique_ptr<ana::known_function>) const = 0;
     734              : 
     735              :   virtual ana::logger *
     736              :   get_logger () const = 0;
     737              : };
     738              : 
     739              : /* A message published by the analyzer when it simulates popping a stack
     740              :    frame.  */
     741              : 
     742              : struct on_frame_popped
     743              : {
     744              :   const ana::region_model *m_new_model;
     745              :   const ana::region_model *m_old_model;
     746              :   const ana::svalue *m_retval;
     747              :   ana::region_model_context *m_ctxt;
     748              : };
     749              : 
     750              : /* A message published by the analyzer when it has finished and is about
     751              :    to clean up.  */
     752              : 
     753              : struct on_ana_done
     754              : {
     755              :   const ana::engine &m_engine;
     756              :   const ana::exploded_graph &m_eg;
     757              : };
     758              : 
     759            1 : struct subscriber {
     760              : 
     761              :   virtual ~subscriber () = default;
     762              : 
     763           38 :   virtual void on_message (const on_tu_finished &) {}
     764            1 :   virtual void on_message (const on_ana_init &) {}
     765          227 :   virtual void on_message (const on_frame_popped &) {}
     766           37 :   virtual void on_message (const on_ana_done &) {}
     767              : };
     768              : 
     769              : } // namespace gcc::topics::analyzer_events
     770              : } // namespace gcc::topics
     771              : } // namespace gcc
     772              : 
     773              : #if !ENABLE_ANALYZER
     774              : extern void sorry_no_analyzer ();
     775              : #endif /* #if !ENABLE_ANALYZER */
     776              : 
     777              : #endif /* GCC_ANALYZER_COMMON_H */
        

Generated by: LCOV version 2.5.0-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.