c++: new-expression is potentially constant in C++20
[official-gcc.git] / gcc / analyzer / call-string.h
blob87d04a1c4cc06763bbc328932966009f201013f4
1 /* Call stacks at program points.
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_CALL_STRING_H
22 #define GCC_ANALYZER_CALL_STRING_H
24 namespace ana {
26 class supergraph;
27 class supernode;
28 class call_superedge;
29 class return_superedge;
32 /* A string of return_superedge pointers, representing a call stack
33 at a program point.
35 This is used to ensure that we generate interprocedurally valid paths
36 i.e. that we return to the same callsite that called us.
38 The class stores returning calls ( which may be represented by a
39 returning superedge ). We do so because this is what we need to compare
40 against. */
42 class call_string
44 public:
45 /* A struct representing an element in the call_string.
47 Each element represents a path from m_callee to m_caller which represents
48 returning from function. */
50 struct element_t
52 element_t (const supernode *caller, const supernode *callee)
53 : m_caller (caller), m_callee (callee)
57 bool operator== (const element_t &other) const;
58 bool operator!= (const element_t &other) const;
60 /* Accessors */
61 function *get_caller_function () const;
62 function *get_callee_function () const;
64 const supernode *m_caller;
65 const supernode *m_callee;
68 call_string () : m_elements () {}
69 call_string (const call_string &other);
70 call_string& operator= (const call_string &other);
72 bool operator== (const call_string &other) const;
74 void print (pretty_printer *pp) const;
76 json::value *to_json () const;
78 hashval_t hash () const;
80 bool empty_p () const { return m_elements.is_empty (); }
82 void push_call (const supergraph &sg,
83 const call_superedge *sedge);
85 void push_call (const supernode *src,
86 const supernode *dest);
88 element_t pop ();
90 int calc_recursion_depth () const;
92 static int cmp (const call_string &a,
93 const call_string &b);
95 /* Accessors */
97 const supernode *get_callee_node () const;
98 const supernode *get_caller_node () const;
99 unsigned length () const { return m_elements.length (); }
100 element_t operator[] (unsigned idx) const
102 return m_elements[idx];
105 void validate () const;
107 private:
108 auto_vec<element_t> m_elements;
111 } // namespace ana
113 #endif /* GCC_ANALYZER_CALL_STRING_H */