Home | History | Annotate | Line # | Download | only in analyzer
      1 /* Subclasses of custom_edge_info for describing outcomes of function calls.
      2    Copyright (C) 2021-2022 Free Software Foundation, Inc.
      3    Contributed by David Malcolm <dmalcolm (at) 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 #include "config.h"
     22 #include "system.h"
     23 #include "coretypes.h"
     24 #include "tree.h"
     25 #include "function.h"
     26 #include "basic-block.h"
     27 #include "gimple.h"
     28 #include "gimple-iterator.h"
     29 #include "diagnostic-core.h"
     30 #include "options.h"
     31 #include "cgraph.h"
     32 #include "tree-pretty-print.h"
     33 #include "tristate.h"
     34 #include "bitmap.h"
     35 #include "selftest.h"
     36 #include "function.h"
     37 #include "json.h"
     38 #include "analyzer/analyzer.h"
     39 #include "analyzer/analyzer-logging.h"
     40 #include "ordered-hash-map.h"
     41 #include "cfg.h"
     42 #include "digraph.h"
     43 #include "analyzer/supergraph.h"
     44 #include "sbitmap.h"
     45 #include "analyzer/call-string.h"
     46 #include "analyzer/program-point.h"
     47 #include "analyzer/store.h"
     48 #include "analyzer/region-model.h"
     49 #include "analyzer/constraint-manager.h"
     50 #include "diagnostic-event-id.h"
     51 #include "analyzer/sm.h"
     52 #include "analyzer/pending-diagnostic.h"
     53 #include "analyzer/region-model-reachability.h"
     54 #include "analyzer/analyzer-selftests.h"
     55 #include "analyzer/program-state.h"
     56 #include "diagnostic-path.h"
     57 #include "analyzer/checker-path.h"
     58 #include "analyzer/diagnostic-manager.h"
     59 #include "alloc-pool.h"
     60 #include "fibonacci_heap.h"
     61 #include "shortest-paths.h"
     62 #include "analyzer/exploded-graph.h"
     63 #include "analyzer/call-info.h"
     64 
     65 #if ENABLE_ANALYZER
     66 
     67 namespace ana {
     68 
     69 /* class call_info : public custom_eedge_info_t.  */
     70 
     71 /* Implementation of custom_edge_info::print vfunc for call_info:
     72    use get_desc to get a label_text, and print it to PP.  */
     73 
     74 void
     75 call_info::print (pretty_printer *pp) const
     76 {
     77   label_text desc (get_desc (pp_show_color (pp)));
     78   pp_string (pp, desc.m_buffer);
     79   desc.maybe_free ();
     80 }
     81 
     82 /* Implementation of custom_edge_info::add_events_to_path vfunc for
     83    call_info: add a custom_event using call_info::get_desc as its
     84    description.  */
     85 
     86 void
     87 call_info::add_events_to_path (checker_path *emission_path,
     88 			       const exploded_edge &eedge) const
     89 {
     90   class call_event : public custom_event
     91   {
     92   public:
     93     call_event (location_t loc, tree fndecl, int depth,
     94 		const call_info *call_info)
     95       : custom_event (loc, fndecl, depth),
     96 	m_call_info (call_info)
     97     {}
     98 
     99     label_text get_desc (bool can_colorize) const
    100     {
    101       return m_call_info->get_desc (can_colorize);
    102     }
    103 
    104   private:
    105     const call_info *m_call_info;
    106   };
    107 
    108   const exploded_node *src_node = eedge.m_src;
    109   const program_point &src_point = src_node->get_point ();
    110   tree caller_fndecl = src_point.get_fndecl ();
    111   const int stack_depth = src_point.get_stack_depth ();
    112 
    113   emission_path->add_event (new call_event (get_call_stmt ()->location,
    114 					    caller_fndecl,
    115 					    stack_depth,
    116 					    this));
    117 }
    118 
    119 /* Recreate a call_details instance from this call_info.  */
    120 
    121 call_details
    122 call_info::get_call_details (region_model *model,
    123 			     region_model_context *ctxt) const
    124 {
    125   return call_details (m_call_stmt, model, ctxt);
    126 }
    127 
    128 /* call_info's ctor.
    129 
    130    The call_info instance will outlive the call_details instance;
    131    call_details instances are typically created on the stack.  */
    132 
    133 call_info::call_info (const call_details &cd)
    134 : m_call_stmt (cd.get_call_stmt ()),
    135   m_fndecl (cd.get_fndecl_for_call ())
    136 {
    137   gcc_assert (m_fndecl);
    138 }
    139 
    140 /* class success_call_info : public call_info.  */
    141 
    142 /* Implementation of call_info::get_desc vfunc for success_call_info.  */
    143 
    144 label_text
    145 success_call_info::get_desc (bool can_colorize) const
    146 {
    147   return make_label_text (can_colorize, "when %qE succeeds", get_fndecl ());
    148 }
    149 
    150 /* class failed_call_info : public call_info.  */
    151 
    152 /* Implementation of call_info::get_desc vfunc for failed_call_info.  */
    153 
    154 label_text
    155 failed_call_info::get_desc (bool can_colorize) const
    156 {
    157   return make_label_text (can_colorize, "when %qE fails", get_fndecl ());
    158 }
    159 
    160 } // namespace ana
    161 
    162 #endif /* #if ENABLE_ANALYZER */
    163