c++: Tweaks for -Wredundant-move [PR107363]
[official-gcc.git] / gcc / analyzer / exploded-graph.h
blob8e3c160189c4842f5f9feb5cc2cdcefbe1b25d7b
1 /* Classes for managing a directed graph of <point, state> pairs.
2 Copyright (C) 2019-2022 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
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.
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.
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/>. */
21 #ifndef GCC_ANALYZER_EXPLODED_GRAPH_H
22 #define GCC_ANALYZER_EXPLODED_GRAPH_H
24 #include "alloc-pool.h"
25 #include "fibonacci_heap.h"
26 #include "supergraph.h"
27 #include "sbitmap.h"
28 #include "shortest-paths.h"
29 #include "analyzer/sm.h"
30 #include "analyzer/program-state.h"
31 #include "analyzer/diagnostic-manager.h"
33 namespace ana {
35 /* Concrete implementation of region_model_context, wiring it up to the
36 rest of the analysis engine. */
38 class impl_region_model_context : public region_model_context
40 public:
41 impl_region_model_context (exploded_graph &eg,
42 exploded_node *enode_for_diag,
44 /* TODO: should we be getting the ECs from the
45 old state, rather than the new? */
46 const program_state *old_state,
47 program_state *new_state,
48 uncertainty_t *uncertainty,
49 path_context *path_ctxt,
51 const gimple *stmt,
52 stmt_finder *stmt_finder = NULL);
54 impl_region_model_context (program_state *state,
55 const extrinsic_state &ext_state,
56 uncertainty_t *uncertainty,
57 logger *logger = NULL);
59 bool warn (std::unique_ptr<pending_diagnostic> d) final override;
60 void add_note (std::unique_ptr<pending_note> pn) final override;
61 void on_svalue_leak (const svalue *) override;
62 void on_liveness_change (const svalue_set &live_svalues,
63 const region_model *model) final override;
64 logger *get_logger () final override
66 return m_logger.get_logger ();
69 void on_state_leak (const state_machine &sm,
70 const svalue *sval,
71 state_machine::state_t state);
73 void on_condition (const svalue *lhs,
74 enum tree_code op,
75 const svalue *rhs) final override;
77 void on_bounded_ranges (const svalue &sval,
78 const bounded_ranges &ranges) final override;
80 void on_unknown_change (const svalue *sval, bool is_mutable) final override;
82 void on_phi (const gphi *phi, tree rhs) final override;
84 void on_unexpected_tree_code (tree t,
85 const dump_location_t &loc) final override;
87 void on_escaped_function (tree fndecl) final override;
89 uncertainty_t *get_uncertainty () final override;
91 void purge_state_involving (const svalue *sval) final override;
93 void bifurcate (std::unique_ptr<custom_edge_info> info) final override;
94 void terminate_path () final override;
95 const extrinsic_state *get_ext_state () const final override
97 return &m_ext_state;
99 bool get_state_map_by_name (const char *name,
100 sm_state_map **out_smap,
101 const state_machine **out_sm,
102 unsigned *out_sm_idx) override;
104 const gimple *get_stmt () const override { return m_stmt; }
106 exploded_graph *m_eg;
107 log_user m_logger;
108 exploded_node *m_enode_for_diag;
109 const program_state *m_old_state;
110 program_state *m_new_state;
111 const gimple *m_stmt;
112 stmt_finder *m_stmt_finder;
113 const extrinsic_state &m_ext_state;
114 uncertainty_t *m_uncertainty;
115 path_context *m_path_ctxt;
118 /* A <program_point, program_state> pair, used internally by
119 exploded_node as its immutable data, and as a key for identifying
120 exploded_nodes we've already seen in the graph. */
122 class point_and_state
124 public:
125 point_and_state (const program_point &point,
126 const program_state &state)
127 : m_point (point),
128 m_state (state),
129 m_hash (m_point.hash () ^ m_state.hash ())
131 /* We shouldn't be building point_and_states and thus exploded_nodes
132 for states that aren't valid. */
133 gcc_assert (state.m_valid);
136 hashval_t hash () const
138 return m_hash;
140 bool operator== (const point_and_state &other) const
142 return m_point == other.m_point && m_state == other.m_state;
145 const program_point &get_point () const { return m_point; }
146 const program_state &get_state () const { return m_state; }
148 void set_state (const program_state &state)
150 m_state = state;
151 m_hash = m_point.hash () ^ m_state.hash ();
154 void validate (const extrinsic_state &ext_state) const;
156 private:
157 program_point m_point;
158 program_state m_state;
159 hashval_t m_hash;
162 /* A traits class for exploded graphs and their nodes and edges. */
164 struct eg_traits
166 typedef exploded_node node_t;
167 typedef exploded_edge edge_t;
168 typedef exploded_graph graph_t;
169 struct dump_args_t
171 dump_args_t (const exploded_graph &eg) : m_eg (eg) {}
173 bool show_enode_details_p (const exploded_node &enode) const;
175 virtual void
176 dump_extra_info (const exploded_node *, pretty_printer *) const {}
178 const exploded_graph &m_eg;
180 typedef exploded_cluster cluster_t;
183 /* An exploded_node is a unique, immutable <point, state> pair within the
184 exploded_graph.
185 Each exploded_node has a unique index within the graph
186 (for ease of debugging). */
188 class exploded_node : public dnode<eg_traits>
190 public:
191 /* Has this enode had exploded_graph::process_node called on it?
192 This allows us to distinguish enodes that were merged during
193 worklist-handling, and thus never had process_node called on them
194 (in favor of processing the merged node). */
195 enum status
197 /* Node is in the worklist. */
198 STATUS_WORKLIST,
200 /* Node has had exploded_graph::process_node called on it. */
201 STATUS_PROCESSED,
203 /* Node was left unprocessed due to merger; it won't have had
204 exploded_graph::process_node called on it. */
205 STATUS_MERGER,
207 /* Node was processed by maybe_process_run_of_before_supernode_enodes. */
208 STATUS_BULK_MERGED
210 static const char * status_to_str (enum status s);
212 exploded_node (const point_and_state &ps, int index);
214 hashval_t hash () const { return m_ps.hash (); }
216 const char * get_dot_fillcolor () const;
217 void dump_dot (graphviz_out *gv, const dump_args_t &args)
218 const final override;
219 void dump_dot_id (pretty_printer *pp) const;
221 void dump_to_pp (pretty_printer *pp, const extrinsic_state &ext_state) const;
222 void dump (FILE *fp, const extrinsic_state &ext_state) const;
223 void dump (const extrinsic_state &ext_state) const;
225 void dump_processed_stmts (pretty_printer *pp) const;
226 void dump_saved_diagnostics (pretty_printer *pp) const;
228 json::object *to_json (const extrinsic_state &ext_state) const;
230 /* The result of on_stmt. */
231 struct on_stmt_flags
233 on_stmt_flags () : m_terminate_path (false)
236 static on_stmt_flags terminate_path ()
238 return on_stmt_flags (true);
241 /* Should we stop analyzing this path (on_stmt may have already
242 added nodes/edges, e.g. when handling longjmp). */
243 bool m_terminate_path : 1;
245 private:
246 on_stmt_flags (bool terminate_path)
247 : m_terminate_path (terminate_path)
251 on_stmt_flags on_stmt (exploded_graph &eg,
252 const supernode *snode,
253 const gimple *stmt,
254 program_state *state,
255 uncertainty_t *uncertainty,
256 path_context *path_ctxt);
257 void on_stmt_pre (exploded_graph &eg,
258 const gimple *stmt,
259 program_state *state,
260 bool *out_terminate_path,
261 bool *out_unknown_side_effects,
262 region_model_context *ctxt);
263 void on_stmt_post (const gimple *stmt,
264 program_state *state,
265 bool unknown_side_effects,
266 region_model_context *ctxt);
268 on_stmt_flags replay_call_summaries (exploded_graph &eg,
269 const supernode *snode,
270 const gcall *call_stmt,
271 program_state *state,
272 path_context *path_ctxt,
273 function *called_fn,
274 per_function_data *called_fn_data,
275 region_model_context *ctxt);
276 void replay_call_summary (exploded_graph &eg,
277 const supernode *snode,
278 const gcall *call_stmt,
279 program_state *state,
280 path_context *path_ctxt,
281 function *called_fn,
282 call_summary *summary,
283 region_model_context *ctxt);
285 bool on_edge (exploded_graph &eg,
286 const superedge *succ,
287 program_point *next_point,
288 program_state *next_state,
289 uncertainty_t *uncertainty);
290 void on_longjmp (exploded_graph &eg,
291 const gcall *call,
292 program_state *new_state,
293 region_model_context *ctxt);
295 void detect_leaks (exploded_graph &eg);
297 const program_point &get_point () const { return m_ps.get_point (); }
298 const supernode *get_supernode () const
300 return get_point ().get_supernode ();
302 function *get_function () const
304 return get_point ().get_function ();
306 int get_stack_depth () const
308 return get_point ().get_stack_depth ();
310 const gimple *get_stmt () const { return get_point ().get_stmt (); }
311 const gimple *get_processed_stmt (unsigned idx) const;
313 const program_state &get_state () const { return m_ps.get_state (); }
315 const point_and_state *get_ps_key () const { return &m_ps; }
316 const program_point *get_point_key () const { return &m_ps.get_point (); }
318 void dump_succs_and_preds (FILE *outf) const;
320 enum status get_status () const { return m_status; }
321 void set_status (enum status status)
323 gcc_assert (m_status == STATUS_WORKLIST);
324 m_status = status;
327 void add_diagnostic (const saved_diagnostic *sd)
329 m_saved_diagnostics.safe_push (sd);
331 unsigned get_num_diagnostics () const
333 return m_saved_diagnostics.length ();
335 const saved_diagnostic *get_saved_diagnostic (unsigned idx) const
337 return m_saved_diagnostics[idx];
340 private:
341 DISABLE_COPY_AND_ASSIGN (exploded_node);
343 /* The <program_point, program_state> pair. This is const, as it
344 is immutable once the exploded_node has been created. */
345 const point_and_state m_ps;
347 enum status m_status;
349 /* The saved_diagnostics at this enode, borrowed from the
350 diagnostic_manager. */
351 auto_vec <const saved_diagnostic *> m_saved_diagnostics;
353 public:
354 /* The index of this exploded_node. */
355 const int m_index;
357 /* The number of stmts that were processed when process_node was
358 called on this enode. */
359 unsigned m_num_processed_stmts;
362 /* An edge within the exploded graph.
363 Some exploded_edges have an underlying superedge; others don't. */
365 class exploded_edge : public dedge<eg_traits>
367 public:
368 exploded_edge (exploded_node *src, exploded_node *dest,
369 const superedge *sedge,
370 std::unique_ptr<custom_edge_info> custom_info);
371 void dump_dot (graphviz_out *gv, const dump_args_t &args)
372 const final override;
373 void dump_dot_label (pretty_printer *pp) const;
375 json::object *to_json () const;
377 //private:
378 const superedge *const m_sedge;
380 /* NULL for most edges; will be non-NULL for special cases
381 such as an unwind from a longjmp to a setjmp, or when
382 a signal is delivered to a signal-handler. */
383 std::unique_ptr<custom_edge_info> m_custom_info;
385 private:
386 DISABLE_COPY_AND_ASSIGN (exploded_edge);
389 /* Extra data for an exploded_edge that represents dynamic call info ( calls
390 that doesn't have an underlying superedge representing the call ). */
392 class dynamic_call_info_t : public custom_edge_info
394 public:
395 dynamic_call_info_t (const gcall *dynamic_call,
396 const bool is_returning_call = false)
397 : m_dynamic_call (dynamic_call),
398 m_is_returning_call (is_returning_call)
401 void print (pretty_printer *pp) const final override
403 if (m_is_returning_call)
404 pp_string (pp, "dynamic_return");
405 else
406 pp_string (pp, "dynamic_call");
409 bool update_model (region_model *model,
410 const exploded_edge *eedge,
411 region_model_context *ctxt) const final override;
413 void add_events_to_path (checker_path *emission_path,
414 const exploded_edge &eedge) const final override;
415 private:
416 const gcall *m_dynamic_call;
417 const bool m_is_returning_call;
421 /* Extra data for an exploded_edge that represents a rewind from a
422 longjmp to a setjmp (or from a siglongjmp to a sigsetjmp). */
424 class rewind_info_t : public custom_edge_info
426 public:
427 rewind_info_t (const setjmp_record &setjmp_record,
428 const gcall *longjmp_call)
429 : m_setjmp_record (setjmp_record),
430 m_longjmp_call (longjmp_call)
433 void print (pretty_printer *pp) const final override
435 pp_string (pp, "rewind");
438 bool update_model (region_model *model,
439 const exploded_edge *eedge,
440 region_model_context *ctxt) const final override;
442 void add_events_to_path (checker_path *emission_path,
443 const exploded_edge &eedge) const final override;
445 const program_point &get_setjmp_point () const
447 const program_point &origin_point = get_enode_origin ()->get_point ();
449 /* "origin_point" ought to be before the call to "setjmp". */
450 gcc_assert (origin_point.get_kind () == PK_BEFORE_STMT);
452 /* TODO: assert that it's the final stmt in its supernode. */
454 return origin_point;
457 const gcall *get_setjmp_call () const
459 return m_setjmp_record.m_setjmp_call;
462 const gcall *get_longjmp_call () const
464 return m_longjmp_call;
467 const exploded_node *get_enode_origin () const
469 return m_setjmp_record.m_enode;
472 private:
473 setjmp_record m_setjmp_record;
474 const gcall *m_longjmp_call;
477 /* Statistics about aspects of an exploded_graph. */
479 struct stats
481 stats (int num_supernodes);
482 void log (logger *logger) const;
483 void dump (FILE *out) const;
485 int get_total_enodes () const;
487 int m_num_nodes[NUM_POINT_KINDS];
488 int m_node_reuse_count;
489 int m_node_reuse_after_merge_count;
490 int m_num_supernodes;
493 /* Traits class for ensuring uniqueness of point_and_state data within
494 an exploded_graph. */
496 struct eg_hash_map_traits
498 typedef const point_and_state *key_type;
499 typedef exploded_node *value_type;
500 typedef exploded_node *compare_type;
502 static inline hashval_t hash (const key_type &k)
504 gcc_assert (k != NULL);
505 gcc_assert (k != reinterpret_cast<key_type> (1));
506 return k->hash ();
508 static inline bool equal_keys (const key_type &k1, const key_type &k2)
510 gcc_assert (k1 != NULL);
511 gcc_assert (k2 != NULL);
512 gcc_assert (k1 != reinterpret_cast<key_type> (1));
513 gcc_assert (k2 != reinterpret_cast<key_type> (1));
514 if (k1 && k2)
515 return *k1 == *k2;
516 else
517 /* Otherwise they must both be non-NULL. */
518 return k1 == k2;
520 template <typename T>
521 static inline void remove (T &)
523 /* empty; the nodes are handled elsewhere. */
525 template <typename T>
526 static inline void mark_deleted (T &entry)
528 entry.m_key = reinterpret_cast<key_type> (1);
530 template <typename T>
531 static inline void mark_empty (T &entry)
533 entry.m_key = NULL;
535 template <typename T>
536 static inline bool is_deleted (const T &entry)
538 return entry.m_key == reinterpret_cast<key_type> (1);
540 template <typename T>
541 static inline bool is_empty (const T &entry)
543 return entry.m_key == NULL;
545 static const bool empty_zero_p = false;
548 /* Per-program_point data for an exploded_graph. */
550 struct per_program_point_data
552 per_program_point_data (const program_point &key)
553 : m_key (key), m_excess_enodes (0)
556 const program_point m_key;
557 auto_vec<exploded_node *> m_enodes;
558 /* The number of attempts to create an enode for this point
559 after exceeding --param=analyzer-max-enodes-per-program-point. */
560 int m_excess_enodes;
563 /* Traits class for storing per-program_point data within
564 an exploded_graph. */
566 struct eg_point_hash_map_traits
568 typedef const program_point *key_type;
569 typedef per_program_point_data *value_type;
570 typedef per_program_point_data *compare_type;
572 static inline hashval_t hash (const key_type &k)
574 gcc_assert (k != NULL);
575 gcc_assert (k != reinterpret_cast<key_type> (1));
576 return k->hash ();
578 static inline bool equal_keys (const key_type &k1, const key_type &k2)
580 gcc_assert (k1 != NULL);
581 gcc_assert (k2 != NULL);
582 gcc_assert (k1 != reinterpret_cast<key_type> (1));
583 gcc_assert (k2 != reinterpret_cast<key_type> (1));
584 if (k1 && k2)
585 return *k1 == *k2;
586 else
587 /* Otherwise they must both be non-NULL. */
588 return k1 == k2;
590 template <typename T>
591 static inline void remove (T &)
593 /* empty; the nodes are handled elsewhere. */
595 template <typename T>
596 static inline void mark_deleted (T &entry)
598 entry.m_key = reinterpret_cast<key_type> (1);
600 template <typename T>
601 static inline void mark_empty (T &entry)
603 entry.m_key = NULL;
605 template <typename T>
606 static inline bool is_deleted (const T &entry)
608 return entry.m_key == reinterpret_cast<key_type> (1);
610 template <typename T>
611 static inline bool is_empty (const T &entry)
613 return entry.m_key == NULL;
615 static const bool empty_zero_p = false;
618 /* Data about a particular call_string within an exploded_graph. */
620 struct per_call_string_data
622 per_call_string_data (const call_string &key, int num_supernodes)
623 : m_key (key), m_stats (num_supernodes)
626 const call_string &m_key;
627 stats m_stats;
630 /* Data about a particular function within an exploded_graph. */
632 struct per_function_data
634 per_function_data () {}
635 ~per_function_data ();
637 void add_call_summary (exploded_node *node);
639 auto_vec<call_summary *> m_summaries;
643 /* The strongly connected components of a supergraph.
644 In particular, this allows us to compute a partial ordering
645 of supernodes. */
647 class strongly_connected_components
649 public:
650 strongly_connected_components (const supergraph &sg, logger *logger);
652 int get_scc_id (int node_index) const
654 return m_per_node[node_index].m_lowlink;
657 void dump () const;
659 json::array *to_json () const;
661 private:
662 struct per_node_data
664 per_node_data ()
665 : m_index (-1), m_lowlink (-1), m_on_stack (false)
668 int m_index;
669 int m_lowlink;
670 bool m_on_stack;
673 void strong_connect (unsigned index);
675 const supergraph &m_sg;
676 auto_vec<unsigned> m_stack;
677 auto_vec<per_node_data> m_per_node;
680 /* The worklist of exploded_node instances that have been added to
681 an exploded_graph, but that haven't yet been processed to find
682 their successors (or warnings).
684 The enodes are stored in a priority queue, ordered by a topological
685 sort of the SCCs in the supergraph, so that enodes for the same
686 program_point should appear at the front of the queue together.
687 This allows for state-merging at CFG join-points, so that
688 sufficiently-similar enodes can be merged into one. */
690 class worklist
692 public:
693 worklist (const exploded_graph &eg, const analysis_plan &plan);
694 unsigned length () const;
695 exploded_node *take_next ();
696 exploded_node *peek_next ();
697 void add_node (exploded_node *enode);
698 int get_scc_id (const supernode &snode) const
700 return m_scc.get_scc_id (snode.m_index);
703 json::object *to_json () const;
705 private:
706 class key_t
708 public:
709 key_t (const worklist &w, exploded_node *enode)
710 : m_worklist (w), m_enode (enode)
713 bool operator< (const key_t &other) const
715 return cmp (*this, other) < 0;
718 bool operator== (const key_t &other) const
720 return cmp (*this, other) == 0;
723 bool operator> (const key_t &other) const
725 return !(*this == other || *this < other);
728 private:
729 static int cmp (const key_t &ka, const key_t &kb);
731 int get_scc_id (const exploded_node *enode) const
733 const supernode *snode = enode->get_supernode ();
734 if (snode == NULL)
735 return 0;
736 return m_worklist.m_scc.get_scc_id (snode->m_index);
739 const worklist &m_worklist;
740 exploded_node *m_enode;
743 /* The order is important here: m_scc needs to stick around
744 until after m_queue has finished being cleaned up (the dtor
745 calls the ordering fns). */
746 strongly_connected_components m_scc;
747 const analysis_plan &m_plan;
749 /* Priority queue, backed by a fibonacci_heap. */
750 typedef fibonacci_heap<key_t, exploded_node> queue_t;
751 queue_t m_queue;
754 /* An exploded_graph is a directed graph of unique <point, state> pairs.
755 It also has a worklist of nodes that are waiting for their successors
756 to be added to the graph. */
758 class exploded_graph : public digraph<eg_traits>
760 public:
761 typedef hash_map <const call_string *,
762 per_call_string_data *> call_string_data_map_t;
764 exploded_graph (const supergraph &sg, logger *logger,
765 const extrinsic_state &ext_state,
766 const state_purge_map *purge_map,
767 const analysis_plan &plan,
768 int verbosity);
769 ~exploded_graph ();
771 logger *get_logger () const { return m_logger.get_logger (); }
773 const supergraph &get_supergraph () const { return m_sg; }
774 const extrinsic_state &get_ext_state () const { return m_ext_state; }
775 engine *get_engine () const { return m_ext_state.get_engine (); }
776 const state_purge_map *get_purge_map () const { return m_purge_map; }
777 const analysis_plan &get_analysis_plan () const { return m_plan; }
779 exploded_node *get_origin () const { return m_origin; }
781 exploded_node *add_function_entry (function *fun);
783 void build_initial_worklist ();
784 void process_worklist ();
785 bool maybe_process_run_of_before_supernode_enodes (exploded_node *node);
786 void process_node (exploded_node *node);
788 bool maybe_create_dynamic_call (const gcall *call,
789 tree fn_decl,
790 exploded_node *node,
791 program_state next_state,
792 program_point &next_point,
793 uncertainty_t *uncertainty,
794 logger *logger);
796 exploded_node *get_or_create_node (const program_point &point,
797 const program_state &state,
798 exploded_node *enode_for_diag);
799 exploded_edge *add_edge (exploded_node *src, exploded_node *dest,
800 const superedge *sedge,
801 std::unique_ptr<custom_edge_info> custom = NULL);
803 per_program_point_data *
804 get_or_create_per_program_point_data (const program_point &);
805 per_program_point_data *
806 get_per_program_point_data (const program_point &) const;
808 per_call_string_data *
809 get_or_create_per_call_string_data (const call_string &);
811 per_function_data *
812 get_or_create_per_function_data (function *);
813 per_function_data *get_per_function_data (function *) const;
815 void save_diagnostic (const state_machine &sm,
816 const exploded_node *enode,
817 const supernode *node, const gimple *stmt,
818 stmt_finder *finder,
819 tree var, state_machine::state_t state,
820 pending_diagnostic *d);
822 diagnostic_manager &get_diagnostic_manager ()
824 return m_diagnostic_manager;
826 const diagnostic_manager &get_diagnostic_manager () const
828 return m_diagnostic_manager;
831 stats *get_global_stats () { return &m_global_stats; }
832 stats *get_or_create_function_stats (function *fn);
833 void log_stats () const;
834 void dump_stats (FILE *) const;
835 void dump_states_for_supernode (FILE *, const supernode *snode) const;
836 void dump_exploded_nodes () const;
838 json::object *to_json () const;
840 exploded_node *get_node_by_index (int idx) const;
842 const call_string_data_map_t *get_per_call_string_data () const
843 { return &m_per_call_string_data; }
845 int get_scc_id (const supernode &node) const
847 return m_worklist.get_scc_id (node);
850 void on_escaped_function (tree fndecl);
852 private:
853 void print_bar_charts (pretty_printer *pp) const;
855 DISABLE_COPY_AND_ASSIGN (exploded_graph);
857 const supergraph &m_sg;
859 log_user m_logger;
861 /* Map from point/state to exploded node.
862 To avoid duplication we store point_and_state
863 *pointers* as keys, rather than point_and_state, using the
864 instance from within the exploded_node, with a custom hasher. */
865 typedef hash_map <const point_and_state *, exploded_node *,
866 eg_hash_map_traits> map_t;
867 map_t m_point_and_state_to_node;
869 /* Map from program_point to per-program_point data. */
870 typedef hash_map <const program_point *, per_program_point_data *,
871 eg_point_hash_map_traits> point_map_t;
872 point_map_t m_per_point_data;
874 worklist m_worklist;
876 exploded_node *m_origin;
878 const extrinsic_state &m_ext_state;
880 const state_purge_map *const m_purge_map;
882 const analysis_plan &m_plan;
884 typedef hash_map<function *, per_function_data *> per_function_data_t;
885 per_function_data_t m_per_function_data;
887 diagnostic_manager m_diagnostic_manager;
889 /* Stats. */
890 stats m_global_stats;
891 typedef ordered_hash_map<function *, stats *> function_stat_map_t;
892 function_stat_map_t m_per_function_stats;
893 stats m_functionless_stats;
895 call_string_data_map_t m_per_call_string_data;
897 auto_vec<int> m_PK_AFTER_SUPERNODE_per_snode;
899 /* Functions with a top-level enode, to make add_function_entry
900 be idempotent, for use in handling callbacks. */
901 hash_set<function *> m_functions_with_enodes;
904 /* A path within an exploded_graph: a sequence of edges. */
906 class exploded_path
908 public:
909 exploded_path () : m_edges () {}
910 exploded_path (const exploded_path &other);
912 unsigned length () const { return m_edges.length (); }
914 bool find_stmt_backwards (const gimple *search_stmt,
915 int *out_idx) const;
917 exploded_node *get_final_enode () const;
919 void dump_to_pp (pretty_printer *pp,
920 const extrinsic_state *ext_state) const;
921 void dump (FILE *fp, const extrinsic_state *ext_state) const;
922 void dump (const extrinsic_state *ext_state = NULL) const;
923 void dump_to_file (const char *filename,
924 const extrinsic_state &ext_state) const;
926 bool feasible_p (logger *logger, std::unique_ptr<feasibility_problem> *out,
927 engine *eng, const exploded_graph *eg) const;
929 auto_vec<const exploded_edge *> m_edges;
932 /* A reason why a particular exploded_path is infeasible. */
934 class feasibility_problem
936 public:
937 feasibility_problem (unsigned eedge_idx,
938 const exploded_edge &eedge,
939 const gimple *last_stmt,
940 rejected_constraint *rc)
941 : m_eedge_idx (eedge_idx), m_eedge (eedge),
942 m_last_stmt (last_stmt), m_rc (rc)
944 ~feasibility_problem () { delete m_rc; }
946 void dump_to_pp (pretty_printer *pp) const;
948 unsigned m_eedge_idx;
949 const exploded_edge &m_eedge;
950 const gimple *m_last_stmt;
951 rejected_constraint *m_rc;
954 /* A class for capturing the state of a node when checking a path
955 through the exploded_graph for feasibility. */
957 class feasibility_state
959 public:
960 feasibility_state (region_model_manager *manager,
961 const supergraph &sg);
962 feasibility_state (const feasibility_state &other);
964 bool maybe_update_for_edge (logger *logger,
965 const exploded_edge *eedge,
966 rejected_constraint **out_rc);
968 const region_model &get_model () const { return m_model; }
969 const auto_sbitmap &get_snodes_visited () const { return m_snodes_visited; }
971 void dump_to_pp (pretty_printer *pp, bool simple, bool multiline) const;
973 private:
974 region_model m_model;
975 auto_sbitmap m_snodes_visited;
978 /* Finding the shortest exploded_path within an exploded_graph. */
980 typedef shortest_paths<eg_traits, exploded_path> shortest_exploded_paths;
982 /* Abstract base class for use when passing NULL as the stmt for
983 a possible warning, allowing the choice of stmt to be deferred
984 until after we have an emission path (and know we're emitting a
985 warning). */
987 class stmt_finder
989 public:
990 virtual ~stmt_finder () {}
991 virtual std::unique_ptr<stmt_finder> clone () const = 0;
992 virtual const gimple *find_stmt (const exploded_path &epath) = 0;
995 // TODO: split the above up?
997 } // namespace ana
999 #endif /* GCC_ANALYZER_EXPLODED_GRAPH_H */