GCC Middle and Back End API Reference
checker-event.h
Go to the documentation of this file.
1/* Subclasses of diagnostic_event for analyzer diagnostics.
2 Copyright (C) 2019-2024 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_CHECKER_EVENT_H
22#define GCC_ANALYZER_CHECKER_EVENT_H
23
26
27namespace ana {
28
29/* A bundle of location information for a checker_event. */
30
32{
33 event_loc_info (location_t loc, tree fndecl, int depth)
34 : m_loc (loc), m_fndecl (fndecl), m_depth (depth)
35 {}
36
40};
41
42/* An enum for discriminating between the concrete subclasses of
43 checker_event. */
44
65
66extern const char *event_kind_to_string (enum event_kind ek);
67
68/* Event subclasses.
69
70 The class hierarchy looks like this (using indentation to show
71 inheritance, and with event_kinds shown for the concrete subclasses):
72
73 diagnostic_event
74 checker_event
75 debug_event (EK_DEBUG)
76 custom_event (EK_CUSTOM)
77 precanned_custom_event
78 statement_event (EK_STMT)
79 region_creation_event (EK_REGION_CREATION)
80 function_entry_event (EK_FUNCTION_ENTRY)
81 state_change_event (EK_STATE_CHANGE)
82 superedge_event
83 cfg_edge_event
84 start_cfg_edge_event (EK_START_CFG_EDGE)
85 end_cfg_edge_event (EK_END_CFG_EDGE)
86 call_event (EK_CALL_EDGE)
87 return_edge (EK_RETURN_EDGE)
88 start_consolidated_cfg_edges_event (EK_START_CONSOLIDATED_CFG_EDGES)
89 end_consolidated_cfg_edges_event (EK_END_CONSOLIDATED_CFG_EDGES)
90 inlined_call_event (EK_INLINED_CALL)
91 setjmp_event (EK_SETJMP)
92 rewind_event
93 rewind_from_longjmp_event (EK_REWIND_FROM_LONGJMP)
94 rewind_to_setjmp_event (EK_REWIND_TO_SETJMP)
95 warning_event (EK_WARNING). */
96
97/* Abstract subclass of diagnostic_event; the base class for use in
98 checker_path (the analyzer's diagnostic_path subclass). */
99
101{
102public:
103 /* Implementation of diagnostic_event. */
104
105 location_t get_location () const final override { return m_loc; }
107 int get_stack_depth () const final override { return m_effective_depth; }
109 {
111 return &m_logical_loc;
112 else
113 return NULL;
114 }
115 meaning get_meaning () const override;
117 {
118 return 0;
119 }
120
121 void
123
124 /* Additional functionality. */
125
127
131 virtual bool is_call_p () const { return false; }
132 virtual bool is_function_entry_p () const { return false; }
133 virtual bool is_return_p () const { return false; }
134
135 /* For use with %@. */
137 {
138 return &m_emission_id;
139 }
140
141 void dump (pretty_printer *pp) const;
142 void debug () const;
143
144 void set_location (location_t loc) { m_loc = loc; }
145
146protected:
148 const event_loc_info &loc_info);
149
150 public:
151 const enum event_kind m_kind;
152 protected:
159 diagnostic_event_id_t m_emission_id; // only set once all pruning has occurred
161};
162
163/* A concrete event subclass for a purely textual event, for use in
164 debugging path creation and filtering. */
165
167{
168public:
169
171 const char *desc)
173 m_desc (xstrdup (desc))
174 {
175 }
177 {
178 free (m_desc);
179 }
180
181 label_text get_desc (bool) const final override;
182
183private:
184 char *m_desc;
185};
186
187/* An abstract event subclass for custom events. These are not filtered,
188 as they are likely to be pertinent to the diagnostic. */
189
191{
192protected:
197};
198
199/* A concrete custom_event subclass with a precanned message. */
200
202{
203public:
205 const char *desc)
207 m_desc (xstrdup (desc))
208 {
209 }
211 {
212 free (m_desc);
213 }
214
215 label_text get_desc (bool) const final override;
216
217private:
218 char *m_desc;
219};
220
221/* A concrete event subclass describing the execution of a gimple statement,
222 for use at high verbosity levels when debugging paths. */
223
225{
226public:
227 statement_event (const gimple *stmt, tree fndecl, int depth,
228 const program_state &dst_state);
229
230 label_text get_desc (bool) const final override;
231
232 const gimple * const m_stmt;
234};
235
236/* An abstract event subclass describing the creation of a region that
237 is significant for a diagnostic.
238
239 There are too many combinations to express region creation in one message,
240 so we emit multiple region_creation_event instances when each pertinent
241 region is created.
242
243 The events are created by pending_diagnostic's add_region_creation_events
244 vfunc, which by default creates a region_creation_event_memory_space, and
245 if a capacity is known, a region_creation_event_capacity, giving e.g.:
246 (1) region created on stack here
247 (2) capacity: 100 bytes
248 but this vfunc can be overridden to create other events if other wordings
249 are more appropriate foa a given pending_diagnostic. */
250
256
257/* Concrete subclass of region_creation_event.
258 Generates a message based on the memory space of the region
259 e.g. "region created on stack here". */
260
276
277/* Concrete subclass of region_creation_event.
278 Generates a message based on the capacity of the region
279 e.g. "capacity: 100 bytes". */
280
282{
283public:
291
292 label_text get_desc (bool can_colorize) const final override;
293
294private:
296};
297
298/* Concrete subclass of region_creation_event.
299 Generates a message based on the capacity of the region
300 e.g. "allocated 100 bytes here". */
301
303{
304public:
310
311 label_text get_desc (bool can_colorize) const final override;
312
313private:
315};
316
317/* Concrete subclass of region_creation_event.
318 Generates a debug message intended for analyzer developers. */
319
321{
322public:
326 m_reg (reg), m_capacity (capacity)
327 {
328 }
329
330 label_text get_desc (bool can_colorize) const final override;
331
332private:
333 const region *m_reg;
335};
336
337/* An event subclass describing the entry to a function. */
338
340{
341public:
346
348
349 label_text get_desc (bool can_colorize) const override;
350 meaning get_meaning () const override;
351
352 bool is_function_entry_p () const final override { return true; }
353};
354
355/* Subclass of checker_event describing a state change. */
356
358{
359public:
360 state_change_event (const supernode *node, const gimple *stmt,
361 int stack_depth,
362 const state_machine &sm,
363 const svalue *sval,
366 const svalue *origin,
368 const exploded_node *enode);
369
370 label_text get_desc (bool can_colorize) const final override;
371 meaning get_meaning () const override;
372
374 {
376 }
377
378 const exploded_node *get_exploded_node () const { return m_enode; }
379
389};
390
391/* Subclass of checker_event; parent class for subclasses that relate to
392 a superedge. */
393
395{
396public:
398 const override;
399
400 /* Mark this edge event as being either an interprocedural call or
401 return in which VAR is in STATE, and that this is critical to the
402 diagnostic (so that get_desc can attempt to get a better description
403 from any pending_diagnostic). */
409
411
412 bool should_filter_p (int verbosity) const;
413
414 protected:
416 const event_loc_info &loc_info);
417
418 public:
423};
424
425/* An abstract event subclass for when a CFG edge is followed; it has two
426 subclasses, representing the start of the edge and the end of the
427 edge, which come in pairs. */
428
430{
431public:
432 meaning get_meaning () const override;
433
435
436 protected:
438 const event_loc_info &loc_info);
439};
440
441/* A concrete event subclass for the start of a CFG edge
442 e.g. "following 'false' branch...'. */
443
445{
446public:
452
453 label_text get_desc (bool can_colorize) const override;
454
455protected:
457
458private:
460 tree lhs,
461 enum tree_code op,
462 tree rhs);
464};
465
466/* A concrete event subclass for the end of a CFG edge
467 e.g. "...to here'. */
468
470{
471public:
477
478 label_text get_desc (bool /*can_colorize*/) const final override
479 {
480 return label_text::borrow ("...to here");
481 }
482};
483
484/* A concrete event subclass for an interprocedural call. */
485
504
505/* A concrete event subclass for an interprocedural return. */
506
521
522/* A concrete event subclass for the start of a consolidated run of CFG
523 edges all either TRUE or FALSE e.g. "following 'false' branch...'. */
524
541
542/* A concrete event subclass for the end of a consolidated run of
543 CFG edges e.g. "...to here'. */
544
546{
547public:
552
553 label_text get_desc (bool /*can_colorize*/) const final override
554 {
555 return label_text::borrow ("...to here");
556 }
557};
558
559/* A concrete event subclass for describing an inlined call event
560 e.g. "inlined call to 'callee' from 'caller'". */
561
563{
564public:
579
580 label_text get_desc (bool /*can_colorize*/) const final override;
581 meaning get_meaning () const override;
582
583private:
586};
587
588/* A concrete event subclass for a setjmp or sigsetjmp call. */
589
591{
592public:
594 const exploded_node *enode,
595 const gcall *setjmp_call)
597 m_enode (enode), m_setjmp_call (setjmp_call)
598 {
599 }
600
601 label_text get_desc (bool can_colorize) const final override;
602
605 diagnostic_event_id_t emission_id) final override;
606
607private:
610};
611
612/* An abstract event subclass for rewinding from a longjmp to a setjmp
613 (or siglongjmp to sigsetjmp).
614
615 Base class for two from/to subclasses, showing the two halves of the
616 rewind. */
617
619{
620public:
623 const exploded_edge *get_eedge () const { return m_eedge; }
624
625 protected:
627 enum event_kind kind,
631
632 private:
634};
635
636/* A concrete event subclass for rewinding from a longjmp to a setjmp,
637 showing the longjmp (or siglongjmp). */
638
652
653/* A concrete event subclass for rewinding from a longjmp to a setjmp,
654 showing the setjmp (or sigsetjmp). */
655
676
677/* Concrete subclass of checker_event for use at the end of a path:
678 a repeat of the warning message at the end of the path (perhaps with
679 references to pertinent events that occurred on the way), at the point
680 where the problem occurs. */
681
683{
684public:
686 const exploded_node *enode,
687 const state_machine *sm,
690 m_enode (enode),
691 m_sm (sm), m_var (var), m_state (state)
692 {
693 }
694
695 label_text get_desc (bool can_colorize) const final override;
696 meaning get_meaning () const override;
697
698 const exploded_node *get_exploded_node () const { return m_enode; }
699
700private:
705};
706
707} // namespace ana
708
709#endif /* GCC_ANALYZER_CHECKER_EVENT_H */
state
Definition cfgbuild.cc:168
Definition checker-event.h:487
label_text get_desc(bool can_colorize) const override
meaning get_meaning() const override
call_event(const exploded_edge &eedge, const event_loc_info &loc_info)
bool is_call_p() const final override
tree get_callee_fndecl() const
const supernode * m_dest_snode
Definition checker-event.h:502
tree get_caller_fndecl() const
const supernode * m_src_snode
Definition checker-event.h:501
Definition supergraph.h:393
Definition checker-event.h:430
meaning get_meaning() const override
cfg_edge_event(enum event_kind kind, const exploded_edge &eedge, const event_loc_info &loc_info)
const cfg_superedge & get_cfg_superedge() const
Definition supergraph.h:515
Definition checker-event.h:101
virtual void prepare_for_emission(checker_path *, pending_diagnostic *pd, diagnostic_event_id_t emission_id)
checker_event(enum event_kind kind, const event_loc_info &loc_info)
void debug() const
virtual bool is_return_p() const
Definition checker-event.h:133
tree m_effective_fndecl
Definition checker-event.h:155
diagnostic_event_id_t m_emission_id
Definition checker-event.h:159
int get_stack_depth() const final override
Definition checker-event.h:107
location_t m_loc
Definition checker-event.h:153
const diagnostic_event_id_t * get_id_ptr() const
Definition checker-event.h:136
enum event_kind m_kind
Definition checker-event.h:151
tree m_original_fndecl
Definition checker-event.h:154
virtual bool is_function_entry_p() const
Definition checker-event.h:132
const logical_location * get_logical_location() const final override
Definition checker-event.h:108
tree get_fndecl() const final override
Definition checker-event.h:106
tree_logical_location m_logical_loc
Definition checker-event.h:160
void set_location(location_t loc)
Definition checker-event.h:144
pending_diagnostic * m_pending_diagnostic
Definition checker-event.h:158
int get_original_stack_depth() const
Definition checker-event.h:126
location_t get_location() const final override
Definition checker-event.h:105
void maybe_add_sarif_properties(sarif_object &thread_flow_loc_obj) const override
virtual bool is_call_p() const
Definition checker-event.h:131
int m_effective_depth
Definition checker-event.h:157
int m_original_depth
Definition checker-event.h:156
diagnostic_thread_id_t get_thread_id() const final override
Definition checker-event.h:116
meaning get_meaning() const override
void dump(pretty_printer *pp) const
Definition checker-path.h:31
Definition checker-event.h:191
custom_event(const event_loc_info &loc_info)
Definition checker-event.h:193
Definition checker-event.h:167
label_text get_desc(bool) const final override
char * m_desc
Definition checker-event.h:184
~debug_event()
Definition checker-event.h:176
debug_event(const event_loc_info &loc_info, const char *desc)
Definition checker-event.h:170
Definition checker-event.h:470
label_text get_desc(bool) const final override
Definition checker-event.h:478
end_cfg_edge_event(const exploded_edge &eedge, const event_loc_info &loc_info)
Definition checker-event.h:472
Definition checker-event.h:546
label_text get_desc(bool) const final override
Definition checker-event.h:553
end_consolidated_cfg_edges_event(const event_loc_info &loc_info)
Definition checker-event.h:548
Definition exploded-graph.h:381
Definition exploded-graph.h:203
Definition checker-event.h:340
function_entry_event(const program_point &dst_point)
meaning get_meaning() const override
label_text get_desc(bool can_colorize) const override
bool is_function_entry_p() const final override
Definition checker-event.h:352
function_entry_event(const event_loc_info &loc_info)
Definition checker-event.h:342
Definition checker-event.h:563
label_text get_desc(bool) const final override
meaning get_meaning() const override
inlined_call_event(location_t loc, tree apparent_callee_fndecl, tree apparent_caller_fndecl, int actual_depth, int stack_depth_adjustment)
Definition checker-event.h:565
tree m_apparent_callee_fndecl
Definition checker-event.h:584
tree m_apparent_caller_fndecl
Definition checker-event.h:585
Definition pending-diagnostic.h:208
Definition checker-event.h:202
label_text get_desc(bool) const final override
~precanned_custom_event()
Definition checker-event.h:210
char * m_desc
Definition checker-event.h:218
precanned_custom_event(const event_loc_info &loc_info, const char *desc)
Definition checker-event.h:204
Definition program-point.h:175
Definition program-state.h:203
const function * get_current_function() const
Definition checker-event.h:303
tree m_capacity
Definition checker-event.h:314
region_creation_event_allocation_size(tree capacity, const event_loc_info &loc_info)
Definition checker-event.h:305
label_text get_desc(bool can_colorize) const final override
Definition checker-event.h:282
region_creation_event_capacity(tree capacity, const event_loc_info &loc_info)
Definition checker-event.h:284
label_text get_desc(bool can_colorize) const final override
tree m_capacity
Definition checker-event.h:295
Definition checker-event.h:321
region_creation_event_debug(const region *reg, tree capacity, const event_loc_info &loc_info)
Definition checker-event.h:323
tree m_capacity
Definition checker-event.h:334
const region * m_reg
Definition checker-event.h:333
label_text get_desc(bool can_colorize) const final override
Definition checker-event.h:262
enum memory_space m_mem_space
Definition checker-event.h:274
region_creation_event_memory_space(enum memory_space mem_space, const event_loc_info &loc_info)
Definition checker-event.h:264
label_text get_desc(bool can_colorize) const final override
Definition checker-event.h:252
region_creation_event(const event_loc_info &loc_info)
Definition region.h:125
Definition checker-event.h:508
return_event(const exploded_edge &eedge, const event_loc_info &loc_info)
bool is_return_p() const final override
label_text get_desc(bool can_colorize) const final override
meaning get_meaning() const override
Definition checker-event.h:619
tree get_longjmp_caller() const
rewind_event(const exploded_edge *eedge, enum event_kind kind, const event_loc_info &loc_info, const rewind_info_t *rewind_info)
tree get_setjmp_caller() const
const exploded_edge * m_eedge
Definition checker-event.h:633
const rewind_info_t * m_rewind_info
Definition checker-event.h:630
const exploded_edge * get_eedge() const
Definition checker-event.h:623
Definition checker-event.h:640
rewind_from_longjmp_event(const exploded_edge *eedge, const event_loc_info &loc_info, const rewind_info_t *rewind_info)
Definition checker-event.h:642
label_text get_desc(bool can_colorize) const final override
Definition exploded-graph.h:457
Definition checker-event.h:657
void prepare_for_emission(checker_path *path, pending_diagnostic *pd, diagnostic_event_id_t emission_id) final override
label_text get_desc(bool can_colorize) const final override
rewind_to_setjmp_event(const exploded_edge *eedge, const event_loc_info &loc_info, const rewind_info_t *rewind_info)
Definition checker-event.h:659
diagnostic_event_id_t m_original_setjmp_event_id
Definition checker-event.h:674
Definition checker-event.h:591
setjmp_event(const event_loc_info &loc_info, const exploded_node *enode, const gcall *setjmp_call)
Definition checker-event.h:593
const gcall * m_setjmp_call
Definition checker-event.h:609
void prepare_for_emission(checker_path *path, pending_diagnostic *pd, diagnostic_event_id_t emission_id) final override
const exploded_node * m_enode
Definition checker-event.h:608
label_text get_desc(bool can_colorize) const final override
Definition checker-event.h:445
static label_text maybe_describe_condition(bool can_colorize, tree lhs, enum tree_code op, tree rhs)
start_cfg_edge_event(const exploded_edge &eedge, const event_loc_info &loc_info)
Definition checker-event.h:447
label_text get_desc(bool can_colorize) const override
label_text maybe_describe_condition(bool can_colorize) const
static bool should_print_expr_p(tree)
Definition checker-event.h:526
label_text get_desc(bool can_colorize) const final override
meaning get_meaning() const override
start_consolidated_cfg_edges_event(const event_loc_info &loc_info, bool edge_sense)
Definition checker-event.h:528
bool m_edge_sense
Definition checker-event.h:539
Definition checker-event.h:358
state_machine::state_t m_to
Definition checker-event.h:385
state_machine::state_t m_from
Definition checker-event.h:384
const svalue * m_origin
Definition checker-event.h:386
label_text get_desc(bool can_colorize) const final override
state_change_event(const supernode *node, const gimple *stmt, int stack_depth, const state_machine &sm, const svalue *sval, state_machine::state_t from, state_machine::state_t to, const svalue *origin, const program_state &dst_state, const exploded_node *enode)
const exploded_node * get_exploded_node() const
Definition checker-event.h:378
meaning get_meaning() const override
const supernode * m_node
Definition checker-event.h:380
program_state m_dst_state
Definition checker-event.h:387
const state_machine & m_sm
Definition checker-event.h:382
const svalue * m_sval
Definition checker-event.h:383
const exploded_node * m_enode
Definition checker-event.h:388
const gimple * m_stmt
Definition checker-event.h:381
const function * get_dest_function() const
Definition checker-event.h:373
Definition sm.h:45
Definition sm.h:40
Definition checker-event.h:225
statement_event(const gimple *stmt, tree fndecl, int depth, const program_state &dst_state)
label_text get_desc(bool) const final override
const gimple *const m_stmt
Definition checker-event.h:232
const program_state m_dst_state
Definition checker-event.h:233
Definition checker-event.h:395
state_machine::state_t m_critical_state
Definition checker-event.h:422
superedge_event(enum event_kind kind, const exploded_edge &eedge, const event_loc_info &loc_info)
const callgraph_superedge & get_callgraph_superedge() const
tree m_var
Definition checker-event.h:421
const exploded_edge & m_eedge
Definition checker-event.h:419
bool should_filter_p(int verbosity) const
void record_critical_state(tree var, state_machine::state_t state)
Definition checker-event.h:404
void maybe_add_sarif_properties(sarif_object &thread_flow_loc_obj) const override
const superedge * m_sedge
Definition checker-event.h:420
Definition supergraph.h:314
Definition supergraph.h:235
Definition svalue.h:90
Definition checker-event.h:683
tree m_var
Definition checker-event.h:703
const exploded_node * get_exploded_node() const
Definition checker-event.h:698
const state_machine * m_sm
Definition checker-event.h:702
meaning get_meaning() const override
const exploded_node * m_enode
Definition checker-event.h:701
label_text get_desc(bool can_colorize) const final override
state_machine::state_t m_state
Definition checker-event.h:704
warning_event(const event_loc_info &loc_info, const exploded_node *enode, const state_machine *sm, tree var, state_machine::state_t state)
Definition checker-event.h:685
Definition diagnostic-event-id.h:37
Definition diagnostic-path.h:72
Definition logical-location.h:52
Definition pretty-print.h:244
Definition diagnostic-format-sarif.h:42
Definition tree-logical-location.h:42
union tree_node * tree
Definition coretypes.h:97
unsigned diagnostic_thread_id_t
Definition diagnostic-event-id.h:64
void final(rtx_insn *first, FILE *file, int optimize_p)
Definition final.cc:2002
free(str)
tree_code
Definition genmatch.cc:347
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
#define LOCATION_BLOCK(LOC)
Definition input.h:187
Definition access-diagram.h:30
event_kind
Definition checker-event.h:46
@ EK_STATE_CHANGE
Definition checker-event.h:52
@ EK_END_CONSOLIDATED_CFG_EDGES
Definition checker-event.h:58
@ EK_REWIND_TO_SETJMP
Definition checker-event.h:62
@ EK_SETJMP
Definition checker-event.h:60
@ EK_WARNING
Definition checker-event.h:63
@ EK_STMT
Definition checker-event.h:49
@ EK_CALL_EDGE
Definition checker-event.h:55
@ EK_FUNCTION_ENTRY
Definition checker-event.h:51
@ EK_CUSTOM
Definition checker-event.h:48
@ EK_START_CONSOLIDATED_CFG_EDGES
Definition checker-event.h:57
@ EK_START_CFG_EDGE
Definition checker-event.h:53
@ EK_DEBUG
Definition checker-event.h:47
@ EK_REWIND_FROM_LONGJMP
Definition checker-event.h:61
@ EK_RETURN_EDGE
Definition checker-event.h:56
@ EK_INLINED_CALL
Definition checker-event.h:59
@ EK_REGION_CREATION
Definition checker-event.h:50
@ EK_END_CFG_EDGE
Definition checker-event.h:54
const char * event_kind_to_string(enum event_kind ek)
memory_space
Definition region.h:31
Definition checker-event.h:32
location_t m_loc
Definition checker-event.h:37
event_loc_info(location_t loc, tree fndecl, int depth)
Definition checker-event.h:33
tree m_fndecl
Definition checker-event.h:38
int m_depth
Definition checker-event.h:39
Definition diagnostic-path.h:116
Definition function.h:249
Definition gimple.h:352
Definition gimple.h:225
Definition genautomata.cc:669
#define NULL
Definition system.h:50
#define gcc_assert(EXPR)
Definition system.h:821