GCC Middle and Back End API Reference
program-point.h
Go to the documentation of this file.
1/* Classes for representing locations within the program.
2 Copyright (C) 2019-2026 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_ANALYZER_PROGRAM_POINT_H
22#define GCC_ANALYZER_PROGRAM_POINT_H
23
24#include "pretty-print.h"
26#include "analyzer/supergraph.h"
27
28namespace ana {
29
30class format
31{
32public:
33 format (bool newlines) : m_newlines (newlines) {}
34
35 void spacer (pretty_printer *pp) const
36 {
37 if (m_newlines)
38 pp_newline (pp);
39 else
40 pp_space (pp);
41 }
42
44};
45
46/* A class for representing a location within the program, including
47 interprocedural information.
48
49 This represents a fine-grained location within the supergraph (or
50 within one of its nodes), along with a call string giving the
51 interprocedural context. */
52
54{
55public:
56 program_point (const supernode *snode,
58 : m_snode (snode),
60 {
61 }
62
63 void print (pretty_printer *pp, const format &f) const;
64 void dump () const;
66
67 std::unique_ptr<json::object> to_json () const;
68
69 hashval_t hash () const;
70 bool operator== (const program_point &other) const
71 {
72 return (m_snode == other.m_snode
73 && m_call_string == other.m_call_string);
74 }
75 bool operator!= (const program_point &other) const
76 {
77 return !(*this == other);
78 }
79
80 /* Accessors. */
81
82 const supernode *get_supernode () const
83 {
84 return m_snode;
85 }
86 const call_string &get_call_string () const { return *m_call_string; }
87
89 {
90 return m_snode ? m_snode->get_function () : nullptr;
91 }
92 function *get_function_at_depth (unsigned depth) const;
94 {
95 function *fn = get_function ();
96 return fn ? fn->decl : nullptr;
97 }
98 location_t get_location () const
99 {
100 return m_snode ? m_snode->get_location () : UNKNOWN_LOCATION;
101 }
102
103 /* Get the number of frames we expect at this program point.
104 This will be one more than the length of the call_string
105 (which stores the parent callsites), apart from the origin
106 node, which doesn't have any frames. */
107 int get_stack_depth () const
108 {
109 if (m_snode == nullptr)
110 // Origin
111 return 0;
112 return get_call_string ().length () + 1;
113 }
114
115 bool state_merge_at_p () const
116 {
117 if (m_snode)
118 return m_snode->m_state_merger_node;
119 return false;
120 }
121
122 /* Factory functions for making various kinds of program_point. */
125 const supergraph &sg,
126 const function &fun);
127
129 void validate () const;
130
131 static bool effectively_intraprocedural_p (const program_point &point_a,
132 const program_point &point_b);
133
134 private:
137};
138
139} // namespace ana
140
141#endif /* GCC_ANALYZER_PROGRAM_POINT_H */
Definition call-string.h:41
unsigned length() const
Definition call-string.h:98
Definition program-point.h:31
void spacer(pretty_printer *pp) const
Definition program-point.h:35
format(bool newlines)
Definition program-point.h:33
bool m_newlines
Definition program-point.h:43
location_t get_location() const
Definition program-point.h:98
const supernode * m_snode
Definition program-point.h:135
function * get_function() const
Definition program-point.h:88
bool operator!=(const program_point &other) const
Definition program-point.h:75
void print(pretty_printer *pp, const format &f) const
std::unique_ptr< json::object > to_json() const
bool operator==(const program_point &other) const
Definition program-point.h:70
bool state_merge_at_p() const
Definition program-point.h:115
program_point(const supernode *snode, const call_string &call_string)
Definition program-point.h:56
const supernode * get_supernode() const
Definition program-point.h:82
static program_point from_function_entry(const region_model_manager &mgr, const supergraph &sg, const function &fun)
void dump() const
int get_stack_depth() const
Definition program-point.h:107
const call_string & get_call_string() const
Definition program-point.h:86
void print_source_line(pretty_printer *pp) const
function * get_function_at_depth(unsigned depth) const
void pop_from_call_stack()
static bool effectively_intraprocedural_p(const program_point &point_a, const program_point &point_b)
void validate() const
static program_point origin(const region_model_manager &mgr)
tree get_fndecl() const
Definition program-point.h:93
hashval_t hash() const
const call_string * m_call_string
Definition program-point.h:136
Definition region-model-manager.h:32
Definition supergraph.h:105
Definition supergraph.h:224
Definition pretty-print.h:241
union tree_node * tree
Definition coretypes.h:97
#define UNKNOWN_LOCATION
Definition input.h:32
Definition access-diagram.h:30
void pp_newline(pretty_printer *pp)
Definition pretty-print.cc:2737
#define pp_space(PP)
Definition pretty-print.h:490
Definition function.h:249
tree decl
Definition function.h:285