LCOV - code coverage report
Current view: top level - gcc/analyzer - region-model-manager.h Coverage Total Hit
Test: gcc.info Lines: 100.0 % 17 17
Test Date: 2026-12-05 16:10:02 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      1568217 :   alloc_node_id () { return m_node_mgr.alloc_node_id (); }
      44              : 
      45              :   /* call_string consolidation.  */
      46        15387 :   const call_string &get_empty_call_string () const
      47              :   {
      48        11680 :     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              :   const root_region *get_root_region () const { return &m_root_region; }
     108              : 
     109              :   const memory_space_region *
     110            4 :   get_stack_region () const { return &m_stack_region; }
     111              : 
     112              :   const memory_space_region *
     113            4 :   get_heap_region () const { return &m_heap_region; }
     114              : 
     115              :   const memory_space_region *
     116            4 :   get_code_region () const { return &m_code_region; }
     117              : 
     118              :   const memory_space_region *
     119            4 :   get_globals_region () const { return &m_globals_region; }
     120              : 
     121              :   const memory_space_region *
     122         7318 :   get_private_region () const { return &m_private_region; }
     123              : 
     124          937 :   const errno_region *get_errno_region () const { return &m_errno_region; }
     125              :   const function_region *get_region_for_fndecl (tree fndecl);
     126              :   const label_region *get_region_for_label (tree label);
     127              :   const decl_region *get_region_for_global (tree expr);
     128              :   const region *get_field_region (const region *parent, tree field);
     129              :   const region *get_element_region (const region *parent,
     130              :                                     tree element_type,
     131              :                                     const svalue *index);
     132              :   const region *get_offset_region (const region *parent,
     133              :                                    tree type,
     134              :                                    const svalue *byte_offset);
     135              :   const region *get_sized_region (const region *parent,
     136              :                                   tree type,
     137              :                                   const svalue *byte_size_sval);
     138              :   const region *get_cast_region (const region *original_region,
     139              :                                  tree type);
     140              :   const frame_region *get_frame_region (const frame_region *calling_frame,
     141              :                                         const function &fun);
     142              :   const region *get_symbolic_region (const svalue *sval);
     143              :   const string_region *get_region_for_string (tree string_cst);
     144              :   const region *get_bit_range (const region *parent, tree type,
     145              :                                const concrete_bit_range &bits);
     146              :   const var_arg_region *get_var_arg_region (const frame_region *parent,
     147              :                                             unsigned idx);
     148              : 
     149              :   const region *get_unknown_symbolic_region (tree region_type);
     150              : 
     151              :   const region *
     152              :   get_region_for_unexpected_tree_code (region_model_context *ctxt,
     153              :                                        tree t,
     154              :                                        const dump_location_t &loc);
     155              : 
     156              :   symbolic::node_manager &
     157      4029862 :   get_node_manager () const
     158              :   {
     159      4029159 :     return m_node_mgr;
     160              :   }
     161              : 
     162        18311 :   bounded_ranges_manager *get_range_manager () const { return m_range_mgr; }
     163              : 
     164       363159 :   known_function_manager *get_known_function_manager ()
     165              :   {
     166       363159 :     return &m_known_fn_mgr;
     167              :   }
     168              : 
     169              :   /* Dynamically-allocated region instances.
     170              :      The number of these within the analysis can grow arbitrarily.
     171              :      They are still owned by the manager.  */
     172              :   const region *
     173              :   get_or_create_region_for_heap_alloc (const bitmap &base_regs_in_use);
     174              :   const region *create_region_for_alloca (const frame_region *frame);
     175              : 
     176              :   void log_stats (logger *logger, bool show_objs) const;
     177              : 
     178         6709 :   void begin_checking_feasibility (void) { m_checking_feasibility = true; }
     179         6709 :   void end_checking_feasibility (void) { m_checking_feasibility = false; }
     180              : 
     181       288994 :   logger *get_logger () const { return m_logger; }
     182              : 
     183              :   void dump_untracked_regions () const;
     184              : 
     185              :   const svalue *maybe_fold_binop (tree type, enum tree_code op,
     186              :                                   const svalue *arg0, const svalue *arg1);
     187              : 
     188              : private:
     189              :   bool too_complex_p (const complexity &c) const;
     190              :   bool reject_if_too_complex (svalue *sval);
     191              : 
     192              :   const svalue *
     193              :   maybe_invert_comparison_in_unaryop (tree type,
     194              :                                       const binop_svalue *binop);
     195              :   const svalue *maybe_fold_unaryop (tree type, enum tree_code op,
     196              :                                     const svalue *arg);
     197              :   const svalue *maybe_fold_svalue_from_bit_vector (tree type,
     198              :                                                    const symbolic::bit_vector &bv);
     199              :   const svalue *maybe_fold_asm_output_svalue (tree type,
     200              :                                               const vec<const svalue *> &inputs);
     201              : 
     202              :   const region *
     203              :   maybe_fold_sized_region_to_initial_field (const region *parent,
     204              :                                             tree type,
     205              :                                             const svalue *byte_size_sval);
     206              :   const region *
     207              :   maybe_fold_symbolic_region (const svalue *sval);
     208              : 
     209              :   symbolic::node_manager &m_node_mgr;
     210              :   logger *m_logger;
     211              : 
     212              :   const call_string m_empty_call_string;
     213              : 
     214              :   root_region m_root_region;
     215              :   memory_space_region m_stack_region;
     216              :   memory_space_region m_heap_region;
     217              :   memory_space_region m_read_only_region;
     218              :   memory_space_region m_private_region;
     219              : 
     220              :   /* svalue consolidation.  */
     221              :   typedef std::map<constant_svalue::key_t, constant_svalue *> constants_map_t;
     222              :   constants_map_t m_constants_map;
     223              : 
     224              :   typedef std::map<tree, unknown_svalue *> unknowns_map_t;
     225              :   unknowns_map_t m_unknowns_map;
     226              :   const unknown_svalue *m_unknown_NULL;
     227              : 
     228              :   typedef std::map<poisoned_svalue::key_t,
     229              :                    poisoned_svalue *> poisoned_values_map_t;
     230              :   poisoned_values_map_t m_poisoned_values_map;
     231              : 
     232              :   typedef std::map<setjmp_svalue::key_t,
     233              :                    setjmp_svalue *> setjmp_values_map_t;
     234              :   setjmp_values_map_t m_setjmp_values_map;
     235              : 
     236              :   typedef std::map<const region *, initial_svalue *> initial_values_map_t;
     237              :   initial_values_map_t m_initial_values_map;
     238              : 
     239              :   typedef std::map<pointer_svalue::key_t, pointer_svalue *> pointer_values_map_t;
     240              :   pointer_values_map_t m_pointer_values_map;
     241              : 
     242              :   typedef std::map<unaryop_svalue::key_t,
     243              :                    unaryop_svalue *> unaryop_values_map_t;
     244              :   unaryop_values_map_t m_unaryop_values_map;
     245              : 
     246              :   typedef std::map<binop_svalue::key_t, binop_svalue *> binop_values_map_t;
     247              :   binop_values_map_t m_binop_values_map;
     248              : 
     249              :   typedef std::map<svalue_from_bit_vector::key_t,
     250              :                    svalue_from_bit_vector *> bit_vector_to_svalue_map_t;
     251              :   bit_vector_to_svalue_map_t m_bit_vector_to_svalue_map;
     252              : 
     253              :   typedef std::map<const svalue *,
     254              :                    unmergeable_svalue *> unmergeable_values_map_t;
     255              :   unmergeable_values_map_t m_unmergeable_values_map;
     256              : 
     257              :   typedef std::map<widening_svalue::key_t,
     258              :                    widening_svalue *> widening_values_map_t;
     259              :   widening_values_map_t m_widening_values_map;
     260              : 
     261              :   typedef std::map<asm_output_svalue::key_t,
     262              :                    asm_output_svalue *> asm_output_values_map_t;
     263              :   asm_output_values_map_t m_asm_output_values_map;
     264              : 
     265              :   typedef std::map<const_fn_result_svalue::key_t,
     266              :                    const_fn_result_svalue *> const_fn_result_values_map_t;
     267              :   const_fn_result_values_map_t m_const_fn_result_values_map;
     268              : 
     269              :   bool m_checking_feasibility;
     270              : 
     271              :   /* "Dynamically-allocated" svalue instances.
     272              :      The number of these within the analysis can grow arbitrarily.
     273              :      They are still owned by the manager.  */
     274              :   auto_delete_vec<svalue> m_managed_dynamic_svalues;
     275              : 
     276              :   /* Maximum complexity of svalues that weren't rejected.  */
     277              :   complexity m_max_complexity;
     278              : 
     279              :   /* region consolidation.  */
     280              : 
     281              :   memory_space_region m_code_region;
     282              :   typedef std::map<tree, function_region *> fndecls_map_t;
     283              :   typedef fndecls_map_t::iterator fndecls_iterator_t;
     284              :   fndecls_map_t m_fndecls_map;
     285              : 
     286              :   typedef std::map<tree, label_region *> labels_map_t;
     287              :   typedef labels_map_t::iterator labels_iterator_t;
     288              :   labels_map_t m_labels_map;
     289              : 
     290              :   memory_space_region m_globals_region;
     291              :   typedef std::map<tree, decl_region *> globals_map_t;
     292              :   typedef globals_map_t::iterator globals_iterator_t;
     293              :   globals_map_t m_globals_map;
     294              : 
     295              :   memory_space_region m_thread_local_region;
     296              :   errno_region m_errno_region;
     297              : 
     298              :   consolidation_map<field_region> m_field_regions;
     299              :   consolidation_map<element_region> m_element_regions;
     300              :   consolidation_map<offset_region> m_offset_regions;
     301              :   consolidation_map<sized_region> m_sized_regions;
     302              :   consolidation_map<cast_region> m_cast_regions;
     303              :   consolidation_map<frame_region> m_frame_regions;
     304              :   consolidation_map<symbolic_region> m_symbolic_regions;
     305              : 
     306              :   typedef std::map<tree, string_region *> string_map_t;
     307              :   string_map_t m_string_map;
     308              : 
     309              :   consolidation_map<bit_range_region> m_bit_range_regions;
     310              :   consolidation_map<var_arg_region> m_var_arg_regions;
     311              : 
     312              :   bounded_ranges_manager *m_range_mgr;
     313              : 
     314              :   known_function_manager m_known_fn_mgr;
     315              : 
     316              :   /* "Dynamically-allocated" region instances.
     317              :      The number of these within the analysis can grow arbitrarily.
     318              :      They are still owned by the manager.  */
     319              :   auto_delete_vec<region> m_managed_dynamic_regions;
     320              : };
     321              : 
     322              : } // namespace ana
     323              : 
     324              : #endif /* GCC_ANALYZER_REGION_MODEL_MANAGER_H */
        

Generated by: LCOV version 2.6-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.