1*4c3eb207Smrg /* Call stacks at program points. 2*4c3eb207Smrg Copyright (C) 2019-2020 Free Software Foundation, Inc. 3*4c3eb207Smrg Contributed by David Malcolm <dmalcolm@redhat.com>. 4*4c3eb207Smrg 5*4c3eb207Smrg This file is part of GCC. 6*4c3eb207Smrg 7*4c3eb207Smrg GCC is free software; you can redistribute it and/or modify it 8*4c3eb207Smrg under the terms of the GNU General Public License as published by 9*4c3eb207Smrg the Free Software Foundation; either version 3, or (at your option) 10*4c3eb207Smrg any later version. 11*4c3eb207Smrg 12*4c3eb207Smrg GCC is distributed in the hope that it will be useful, but 13*4c3eb207Smrg WITHOUT ANY WARRANTY; without even the implied warranty of 14*4c3eb207Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15*4c3eb207Smrg General Public License for more details. 16*4c3eb207Smrg 17*4c3eb207Smrg You should have received a copy of the GNU General Public License 18*4c3eb207Smrg along with GCC; see the file COPYING3. If not see 19*4c3eb207Smrg <http://www.gnu.org/licenses/>. */ 20*4c3eb207Smrg 21*4c3eb207Smrg #ifndef GCC_ANALYZER_CALL_STRING_H 22*4c3eb207Smrg #define GCC_ANALYZER_CALL_STRING_H 23*4c3eb207Smrg 24*4c3eb207Smrg namespace ana { 25*4c3eb207Smrg 26*4c3eb207Smrg class supergraph; 27*4c3eb207Smrg class call_superedge; 28*4c3eb207Smrg class return_superedge; 29*4c3eb207Smrg 30*4c3eb207Smrg /* A string of return_superedge pointers, representing a call stack 31*4c3eb207Smrg at a program point. 32*4c3eb207Smrg 33*4c3eb207Smrg This is used to ensure that we generate interprocedurally valid paths 34*4c3eb207Smrg i.e. that we return to the same callsite that called us. 35*4c3eb207Smrg 36*4c3eb207Smrg The class actually stores the return edges, rather than the call edges, 37*4c3eb207Smrg since that's what we need to compare against. */ 38*4c3eb207Smrg 39*4c3eb207Smrg class call_string 40*4c3eb207Smrg { 41*4c3eb207Smrg public: call_string()42*4c3eb207Smrg call_string () : m_return_edges () {} 43*4c3eb207Smrg call_string (const call_string &other); 44*4c3eb207Smrg call_string& operator= (const call_string &other); 45*4c3eb207Smrg 46*4c3eb207Smrg bool operator== (const call_string &other) const; 47*4c3eb207Smrg 48*4c3eb207Smrg void print (pretty_printer *pp) const; 49*4c3eb207Smrg 50*4c3eb207Smrg hashval_t hash () const; 51*4c3eb207Smrg empty_p()52*4c3eb207Smrg bool empty_p () const { return m_return_edges.is_empty (); } 53*4c3eb207Smrg 54*4c3eb207Smrg void push_call (const supergraph &sg, 55*4c3eb207Smrg const call_superedge *sedge); pop()56*4c3eb207Smrg const return_superedge *pop () { return m_return_edges.pop (); } 57*4c3eb207Smrg 58*4c3eb207Smrg int calc_recursion_depth () const; 59*4c3eb207Smrg 60*4c3eb207Smrg static int cmp (const call_string &a, 61*4c3eb207Smrg const call_string &b); 62*4c3eb207Smrg length()63*4c3eb207Smrg unsigned length () const { return m_return_edges.length (); } 64*4c3eb207Smrg const return_superedge *operator[] (unsigned idx) const 65*4c3eb207Smrg { 66*4c3eb207Smrg return m_return_edges[idx]; 67*4c3eb207Smrg } 68*4c3eb207Smrg 69*4c3eb207Smrg void validate () const; 70*4c3eb207Smrg 71*4c3eb207Smrg private: 72*4c3eb207Smrg auto_vec<const return_superedge *> m_return_edges; 73*4c3eb207Smrg }; 74*4c3eb207Smrg 75*4c3eb207Smrg } // namespace ana 76*4c3eb207Smrg 77*4c3eb207Smrg #endif /* GCC_ANALYZER_CALL_STRING_H */ 78