LCOV - code coverage report
Current view: top level - gcc/analyzer - region-model-manager.h Coverage Total Hit
Test: gcc.info Lines: 100.0 % 18 18
Test Date: 2026-11-14 16:39:50 Functions: - 0 0
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Consolidation of svalues and regions.
       2              :    Copyright (C) 2020-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_REGION_MODEL_MANAGER_H
      22              : #define GCC_ANALYZER_REGION_MODEL_MANAGER_H
      23              : 
      24              : #include "svalue.h"
      25              : #include "region.h"
      26              : #include "known-function-manager.h"
      27              : 
      28              : namespace ana {
      29              : 
      30              : /* A class responsible for owning and consolidating region and svalue
      31              :    instances.
      32              :    region and svalue instances are immutable as far as clients are
      33              :    concerned, so they are provided as "const" ptrs.  */
      34              : 
      35              : class region_model_manager
      36              : {
      37              : public:
      38              :   region_model_manager (symbolic::node_manager &node_mgr,
      39              :                         logger *logger = nullptr);
      40              :   ~region_model_manager ();
      41              : 
      42              :   unsigned
      43      1543141 :   alloc_node_id () { return m_node_mgr.alloc_node_id (); }
      44              : 
      45              :   /* call_string consolidation.  */
      46        15155 :   const call_string &get_empty_call_string () const
      47              :   {
      48        11534 :     return m_empty_call_string;
      49              :   }
      50              : 
      51              :   /* svalue consolidation.  */
      52              :   const svalue *get_or_create_constant_svalue (tree type, tree cst_expr);
      53              :   const svalue *get_or_create_constant_svalue (tree cst_expr);
      54              :   const svalue *get_or_create_int_cst (tree type, const poly_wide_int_ref &cst);
      55              :   const svalue *get_or_create_null_ptr (tree pointer_type);
      56              :   const svalue *get_or_create_unknown_svalue (tree type);
      57              :   const svalue *get_or_create_setjmp_svalue (const setjmp_record &r,
      58              :                                              tree type);
      59              :   const svalue *get_or_create_poisoned_svalue (enum poison_kind kind,
      60              :                                                tree type);
      61              :   const svalue *get_or_create_initial_value (const region *reg,
      62              :                                              bool check_poisoned = true);
      63              :   const svalue *get_ptr_svalue (tree ptr_type, const region *pointee);
      64              :   const svalue *get_ptr_svalue (tree ptr_type, symbolic::pointer ptr);
      65              :   const svalue *get_or_create_unaryop (tree type, enum tree_code op,
      66              :                                        const svalue *arg);
      67              :   const svalue *get_or_create_cast (tree type, const svalue *arg);
      68              :   const svalue *get_or_create_binop (tree type,
      69              :                                      enum tree_code op,
      70              :                                      const svalue *arg0, const svalue *arg1);
      71              :   const svalue *get_svalue_from_bit_vector (tree type,
      72              :                                             const symbolic::bit_vector &bv);
      73              :   template <typename ConcreteValueType>
      74              :   const svalue *get_svalue_from_scalar (tree type,
      75              :                                         const symbolic::scalar<ConcreteValueType> &scalar);
      76              :   const svalue *get_or_create_unmergeable (const svalue *arg);
      77              :   const svalue *get_or_create_widening_svalue (tree type,
      78              :                                                const supernode *snode,
      79              :                                                const svalue *base_svalue,
      80              :                                                const svalue *iter_svalue);
      81              :   const svalue *get_or_create_conjured_svalue (tree type, const gimple *stmt,
      82              :                                                const region *id_reg,
      83              :                                                const conjured_purge &p,
      84              :                                                unsigned idx = 0);
      85              :   const svalue *
      86              :   get_or_create_asm_output_svalue (tree type,
      87              :                                    const gasm *asm_stmt,
      88              :                                    unsigned output_idx,
      89              :                                    const vec<const svalue *> &inputs);
      90              :   const svalue *
      91              :   get_or_create_asm_output_svalue (tree type,
      92              :                                    const char *asm_string,
      93              :                                    unsigned output_idx,
      94              :                                    unsigned num_outputs,
      95              :                                    const vec<const svalue *> &inputs);
      96              :   const svalue *
      97              :   get_or_create_const_fn_result_svalue (tree type,
      98              :                                         tree fndecl,
      99              :                                         const vec<const svalue *> &inputs);
     100              : 
     101              :   /* Dynamically-allocated svalue instances.
     102              :      The number of these within the analysis can grow arbitrarily.
     103              :      They are still owned by the manager.  */
     104              :   const svalue *create_unique_svalue (tree type);
     105              : 
     106              :   /* region consolidation.  */
     107         7146 :   const root_region *get_root_region () const { return &m_root_region; }
     108            4 :   const stack_region * get_stack_region () const { return &m_stack_region; }
     109            4 :   const heap_region *get_heap_region () const { return &m_heap_region; }
     110            4 :   const code_region *get_code_region () const { return &m_code_region; }
     111            4 :   const globals_region *get_globals_region () const
     112              :   {
     113            4 :     return &m_globals_region;
     114              :   }
     115          844 :   const errno_region *get_errno_region () const { return &m_errno_region; }
     116              :   const function_region *get_region_for_fndecl (tree fndecl);
     117              :   const label_region *get_region_for_label (tree label);
     118              :   const decl_region *get_region_for_global (tree expr);
     119              :   const region *get_field_region (const region *parent, tree field);
     120              :   const region *get_element_region (const region *parent,
     121              :                                     tree element_type,
     122              :                                     const svalue *index);
     123              :   const region *get_offset_region (const region *parent,
     124              :                                    tree type,
     125              :                                    const svalue *byte_offset);
     126              :   const region *get_sized_region (const region *parent,
     127              :                                   tree type,
     128              :                                   const svalue *byte_size_sval);
     129              :   const region *get_cast_region (const region *original_region,
     130              :                                  tree type);
     131              :   const frame_region *get_frame_region (const frame_region *calling_frame,
     132              :                                         const function &fun);
     133              :   const region *get_symbolic_region (const svalue *sval);
     134              :   const string_region *get_region_for_string (tree string_cst);
     135              :   const region *get_bit_range (const region *parent, tree type,
     136              :                                const concrete_bit_range &bits);
     137              :   const var_arg_region *get_var_arg_region (const frame_region *parent,
     138              :                                             unsigned idx);
     139              : 
     140              :   const region *get_unknown_symbolic_region (tree region_type);
     141              : 
     142              :   const region *
     143              :   get_region_for_unexpected_tree_code (region_model_context *ctxt,
     144              :                                        tree t,
     145              :                                        const dump_location_t &loc);
     146              : 
     147              :   symbolic::node_manager &
     148      4010577 :   get_node_manager () const
     149              :   {
     150      4009878 :     return m_node_mgr;
     151              :   }
     152              : 
     153        17539 :   bounded_ranges_manager *get_range_manager () const { return m_range_mgr; }
     154              : 
     155       361135 :   known_function_manager *get_known_function_manager ()
     156              :   {
     157       361135 :     return &m_known_fn_mgr;
     158              :   }
     159              : 
     160              :   /* Dynamically-allocated region instances.
     161              :      The number of these within the analysis can grow arbitrarily.
     162              :      They are still owned by the manager.  */
     163              :   const region *
     164              :   get_or_create_region_for_heap_alloc (const bitmap &base_regs_in_use);
     165              :   const region *create_region_for_alloca (const frame_region *frame);
     166              : 
     167              :   void log_stats (logger *logger, bool show_objs) const;
     168              : 
     169         6667 :   void begin_checking_feasibility (void) { m_checking_feasibility = true; }
     170         6667 :   void end_checking_feasibility (void) { m_checking_feasibility = false; }
     171              : 
     172       287779 :   logger *get_logger () const { return m_logger; }
     173              : 
     174              :   void dump_untracked_regions () const;
     175              : 
     176              :   const svalue *maybe_fold_binop (tree type, enum tree_code op,
     177              :                                   const svalue *arg0, const svalue *arg1);
     178              : 
     179              : private:
     180              :   bool too_complex_p (const complexity &c) const;
     181              :   bool reject_if_too_complex (svalue *sval);
     182              : 
     183              :   const svalue *
     184              :   maybe_invert_comparison_in_unaryop (tree type,
     185              :                                       const binop_svalue *binop);
     186              :   const svalue *maybe_fold_unaryop (tree type, enum tree_code op,
     187              :                                     const svalue *arg);
     188              :   const svalue *maybe_fold_svalue_from_bit_vector (tree type,
     189              :                                                    const symbolic::bit_vector &bv);
     190              :   const svalue *maybe_fold_asm_output_svalue (tree type,
     191              :                                               const vec<const svalue *> &inputs);
     192              : 
     193              :   const region *
     194              :   maybe_fold_sized_region_to_initial_field (const region *parent,
     195              :                                             tree type,
     196              :                                             const svalue *byte_size_sval);
     197              :   const region *
     198              :   maybe_fold_symbolic_region (const svalue *sval);
     199              : 
     200              :   symbolic::node_manager &m_node_mgr;
     201              :   logger *m_logger;
     202              : 
     203              :   const call_string m_empty_call_string;
     204              : 
     205              :   root_region m_root_region;
     206              :   stack_region m_stack_region;
     207              :   heap_region m_heap_region;
     208              : 
     209              :   /* svalue consolidation.  */
     210              :   typedef std::map<constant_svalue::key_t, constant_svalue *> constants_map_t;
     211              :   constants_map_t m_constants_map;
     212              : 
     213              :   typedef std::map<tree, unknown_svalue *> unknowns_map_t;
     214              :   unknowns_map_t m_unknowns_map;
     215              :   const unknown_svalue *m_unknown_NULL;
     216              : 
     217              :   typedef std::map<poisoned_svalue::key_t,
     218              :                    poisoned_svalue *> poisoned_values_map_t;
     219              :   poisoned_values_map_t m_poisoned_values_map;
     220              : 
     221              :   typedef std::map<setjmp_svalue::key_t,
     222              :                    setjmp_svalue *> setjmp_values_map_t;
     223              :   setjmp_values_map_t m_setjmp_values_map;
     224              : 
     225              :   typedef std::map<const region *, initial_svalue *> initial_values_map_t;
     226              :   initial_values_map_t m_initial_values_map;
     227              : 
     228              :   typedef std::map<pointer_svalue::key_t, pointer_svalue *> pointer_values_map_t;
     229              :   pointer_values_map_t m_pointer_values_map;
     230              : 
     231              :   typedef std::map<unaryop_svalue::key_t,
     232              :                    unaryop_svalue *> unaryop_values_map_t;
     233              :   unaryop_values_map_t m_unaryop_values_map;
     234              : 
     235              :   typedef std::map<binop_svalue::key_t, binop_svalue *> binop_values_map_t;
     236              :   binop_values_map_t m_binop_values_map;
     237              : 
     238              :   typedef std::map<svalue_from_bit_vector::key_t,
     239              :                    svalue_from_bit_vector *> bit_vector_to_svalue_map_t;
     240              :   bit_vector_to_svalue_map_t m_bit_vector_to_svalue_map;
     241              : 
     242              :   typedef std::map<const svalue *,
     243              :                    unmergeable_svalue *> unmergeable_values_map_t;
     244              :   unmergeable_values_map_t m_unmergeable_values_map;
     245              : 
     246              :   typedef std::map<widening_svalue::key_t,
     247              :                    widening_svalue *> widening_values_map_t;
     248              :   widening_values_map_t m_widening_values_map;
     249              : 
     250              :   typedef std::map<asm_output_svalue::key_t,
     251              :                    asm_output_svalue *> asm_output_values_map_t;
     252              :   asm_output_values_map_t m_asm_output_values_map;
     253              : 
     254              :   typedef std::map<const_fn_result_svalue::key_t,
     255              :                    const_fn_result_svalue *> const_fn_result_values_map_t;
     256              :   const_fn_result_values_map_t m_const_fn_result_values_map;
     257              : 
     258              :   bool m_checking_feasibility;
     259              : 
     260              :   /* "Dynamically-allocated" svalue instances.
     261              :      The number of these within the analysis can grow arbitrarily.
     262              :      They are still owned by the manager.  */
     263              :   auto_delete_vec<svalue> m_managed_dynamic_svalues;
     264              : 
     265              :   /* Maximum complexity of svalues that weren't rejected.  */
     266              :   complexity m_max_complexity;
     267              : 
     268              :   /* region consolidation.  */
     269              : 
     270              :   code_region m_code_region;
     271              :   typedef std::map<tree, function_region *> fndecls_map_t;
     272              :   typedef fndecls_map_t::iterator fndecls_iterator_t;
     273              :   fndecls_map_t m_fndecls_map;
     274              : 
     275              :   typedef std::map<tree, label_region *> labels_map_t;
     276              :   typedef labels_map_t::iterator labels_iterator_t;
     277              :   labels_map_t m_labels_map;
     278              : 
     279              :   globals_region m_globals_region;
     280              :   typedef std::map<tree, decl_region *> globals_map_t;
     281              :   typedef globals_map_t::iterator globals_iterator_t;
     282              :   globals_map_t m_globals_map;
     283              : 
     284              :   thread_local_region m_thread_local_region;
     285              :   errno_region m_errno_region;
     286              : 
     287              :   consolidation_map<field_region> m_field_regions;
     288              :   consolidation_map<element_region> m_element_regions;
     289              :   consolidation_map<offset_region> m_offset_regions;
     290              :   consolidation_map<sized_region> m_sized_regions;
     291              :   consolidation_map<cast_region> m_cast_regions;
     292              :   consolidation_map<frame_region> m_frame_regions;
     293              :   consolidation_map<symbolic_region> m_symbolic_regions;
     294              : 
     295              :   typedef std::map<tree, string_region *> string_map_t;
     296              :   string_map_t m_string_map;
     297              : 
     298              :   consolidation_map<bit_range_region> m_bit_range_regions;
     299              :   consolidation_map<var_arg_region> m_var_arg_regions;
     300              : 
     301              :   bounded_ranges_manager *m_range_mgr;
     302              : 
     303              :   known_function_manager m_known_fn_mgr;
     304              : 
     305              :   /* "Dynamically-allocated" region instances.
     306              :      The number of these within the analysis can grow arbitrarily.
     307              :      They are still owned by the manager.  */
     308              :   auto_delete_vec<region> m_managed_dynamic_regions;
     309              : };
     310              : 
     311              : } // namespace ana
     312              : 
     313              : #endif /* GCC_ANALYZER_REGION_MODEL_MANAGER_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.