Line data Source code
1 : /* Paths within an exploded_graph.
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_EXPLODED_PATH_H
22 : #define GCC_ANALYZER_EXPLODED_PATH_H
23 :
24 : #include "analyzer/exploded-graph.h"
25 : #include "analyzer/checker-event.h"
26 : #include "analyzer/state-transition.h"
27 :
28 : namespace ana {
29 :
30 : /* A path within an exploded_graph: a sequence of edges. */
31 :
32 6411 : class exploded_path
33 : {
34 : public:
35 : struct element_t
36 : {
37 84091 : element_t (const exploded_edge *eedge)
38 84091 : : m_eedge (eedge)
39 : {
40 : }
41 33 : element_t (const element_t &other)
42 33 : : m_eedge (other.m_eedge),
43 33 : m_state_at_src (other.m_state_at_src),
44 33 : m_state_at_dst (other.m_state_at_dst),
45 33 : m_state_transition (nullptr)
46 : {
47 33 : if (other.m_state_transition)
48 0 : m_state_transition = other.m_state_transition->clone ();
49 33 : }
50 :
51 232103 : element_t (element_t &&other) = default;
52 :
53 80478 : element_t &operator= (const element_t &other)
54 : {
55 80478 : m_eedge = other.m_eedge;
56 80478 : m_state_at_src = other.m_state_at_src;
57 80478 : m_state_at_dst = other.m_state_at_dst;
58 80478 : m_state_transition = (other.m_state_transition
59 80478 : ? other.m_state_transition->clone ()
60 80478 : : nullptr);
61 80478 : return *this;
62 : }
63 :
64 : const exploded_edge *m_eedge;
65 : diagnostic_state m_state_at_src;
66 : diagnostic_state m_state_at_dst;
67 : std::unique_ptr<state_transition> m_state_transition;
68 : };
69 :
70 6407 : exploded_path () = default;
71 4 : exploded_path (const exploded_path &other) = default;
72 :
73 6905 : unsigned length () const { return m_elements.size (); }
74 :
75 : bool find_stmt_backwards (const gimple *search_stmt,
76 : int *out_idx) const;
77 :
78 : exploded_node *get_final_enode () const;
79 :
80 : void dump_to_pp (pretty_printer *pp,
81 : const extrinsic_state *ext_state) const;
82 : void dump (FILE *fp, const extrinsic_state *ext_state) const;
83 : void dump (const extrinsic_state *ext_state = nullptr) const;
84 : void dump_to_file (const char *filename,
85 : const extrinsic_state &ext_state) const;
86 :
87 : void maybe_log (logger *logger, const char *desc) const;
88 :
89 : bool feasible_p (logger *logger, std::unique_ptr<feasibility_problem> *out,
90 : engine *eng, const exploded_graph *eg) const;
91 :
92 : void
93 682 : append_edge (const exploded_edge *edge)
94 : {
95 682 : m_elements.push_back (edge);
96 682 : }
97 :
98 : void
99 : reverse ();
100 :
101 : std::vector<element_t> m_elements;
102 : };
103 :
104 : /* Finding the shortest exploded_path within an exploded_graph. */
105 :
106 : typedef shortest_paths<eg_traits, exploded_path> shortest_exploded_paths;
107 :
108 : } // namespace ana
109 :
110 : #endif /* GCC_ANALYZER_EXPLODED_PATH_H */
|