Line data Source code
1 : /* Subclasses of diagnostics::paths::event for analyzer diagnostics.
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 : #include "analyzer/common.h"
22 :
23 : #include "gimple-pretty-print.h"
24 : #include "sbitmap.h"
25 : #include "ordered-hash-map.h"
26 : #include "fold-const.h"
27 : #include "gimple-iterator.h"
28 : #include "inlining-iterator.h"
29 : #include "tree-logical-location.h"
30 : #include "diagnostics/sarif-sink.h"
31 : #include "diagnostics/state-graphs.h"
32 : #include "custom-sarif-properties/state-graphs.h"
33 :
34 : #include "analyzer/analyzer-logging.h"
35 : #include "analyzer/sm.h"
36 : #include "analyzer/call-string.h"
37 : #include "analyzer/program-point.h"
38 : #include "analyzer/store.h"
39 : #include "analyzer/region-model.h"
40 : #include "analyzer/program-state.h"
41 : #include "analyzer/checker-path.h"
42 : #include "analyzer/supergraph.h"
43 : #include "analyzer/pending-diagnostic.h"
44 : #include "analyzer/diagnostic-manager.h"
45 : #include "analyzer/constraint-manager.h"
46 : #include "analyzer/checker-event.h"
47 : #include "analyzer/exploded-graph.h"
48 : #include "analyzer/callsite-expr.h"
49 : #include "analyzer/state-transition.h"
50 :
51 : #if ENABLE_ANALYZER
52 :
53 : namespace ana {
54 :
55 : /* Get a string for EK. */
56 :
57 : const char *
58 196 : event_kind_to_string (enum event_kind ek)
59 : {
60 196 : switch (ek)
61 : {
62 0 : default:
63 0 : gcc_unreachable ();
64 : case event_kind::debug:
65 : return "debug";
66 4 : case event_kind::custom:
67 4 : return "custom";
68 8 : case event_kind::stmt:
69 8 : return "stmt";
70 18 : case event_kind::region_creation:
71 18 : return "region_creation";
72 0 : case event_kind::state_transition:
73 0 : return "state_transition";
74 23 : case event_kind::function_entry:
75 23 : return "function_entry";
76 27 : case event_kind::state_change:
77 27 : return "state_change";
78 20 : case event_kind::start_cfg_edge:
79 20 : return "start_cfg_edge";
80 20 : case event_kind::end_cfg_edge:
81 20 : return "end_cfg_edge";
82 6 : case event_kind::catch_:
83 6 : return "catch";
84 13 : case event_kind::call_:
85 13 : return "call";
86 3 : case event_kind::return_:
87 3 : return "return";
88 0 : case event_kind::start_consolidated_cfg_edges:
89 0 : return "start_consolidated_cfg_edges";
90 0 : case event_kind::end_consolidated_cfg_edges:
91 0 : return "end_consolidated_cfg_edges";
92 1 : case event_kind::inlined_call:
93 1 : return "inlined_call";
94 1 : case event_kind::setjmp_:
95 1 : return "setjmp";
96 1 : case event_kind::rewind_from_longjmp:
97 1 : return "rewind_from_longjmp";
98 1 : case event_kind::rewind_to_setjmp:
99 1 : return "rewind_to_setjmp";
100 6 : case event_kind::throw_:
101 6 : return "throw";
102 3 : case event_kind::unwind:
103 3 : return "unwind";
104 41 : case event_kind::warning:
105 41 : return "warning";
106 : }
107 : }
108 :
109 : /* class checker_event : public diagnostics::paths::event. */
110 :
111 : /* checker_event's ctor. */
112 :
113 38187 : checker_event::checker_event (enum event_kind kind,
114 : const event_loc_info &loc_info)
115 38187 : : m_path (nullptr),
116 38187 : m_kind (kind), m_loc (loc_info.m_loc),
117 38187 : m_original_fndecl (loc_info.m_fndecl),
118 38187 : m_effective_fndecl (loc_info.m_fndecl),
119 38187 : m_original_depth (loc_info.m_depth),
120 38187 : m_effective_depth (loc_info.m_depth),
121 38187 : m_pending_diagnostic (nullptr), m_emission_id (),
122 : m_logical_loc
123 38187 : (tree_logical_location_manager::key_from_tree (loc_info.m_fndecl))
124 : {
125 : /* Update effective fndecl and depth if inlining has been recorded. */
126 38187 : if (flag_analyzer_undo_inlining)
127 : {
128 38175 : inlining_info info (m_loc);
129 38175 : if (info.get_inner_fndecl ())
130 : {
131 30309 : m_effective_fndecl = info.get_inner_fndecl ();
132 30309 : m_effective_depth += info.get_extra_frames ();
133 30309 : m_logical_loc
134 30309 : = tree_logical_location_manager::key_from_tree (m_effective_fndecl);
135 : }
136 : }
137 38187 : }
138 :
139 : /* No-op implementation of diagnostics::paths::event::get_meaning vfunc for
140 : checker_event: checker events have no meaning by default. */
141 :
142 : diagnostics::paths::event::meaning
143 56 : checker_event::get_meaning () const
144 : {
145 56 : return diagnostics::paths::event::meaning ();
146 : }
147 :
148 : /* Implementation of diagnostics::paths::event::maybe_add_sarif_properties
149 : for checker_event. */
150 :
151 : void
152 159 : checker_event::
153 : maybe_add_sarif_properties (diagnostics::sarif_builder &builder,
154 : diagnostics::sarif_object &thread_flow_loc_obj) const
155 : {
156 159 : auto &props = thread_flow_loc_obj.get_or_create_properties ();
157 : #define PROPERTY_PREFIX "gcc/analyzer/checker_event/"
158 318 : props.set (PROPERTY_PREFIX "emission_id",
159 159 : diagnostic_event_id_to_json (m_emission_id));
160 159 : props.set_string (PROPERTY_PREFIX "kind", event_kind_to_string (m_kind));
161 :
162 159 : if (m_original_fndecl != m_effective_fndecl)
163 0 : props.set_logical_location
164 0 : (PROPERTY_PREFIX "original_fndecl",
165 : builder,
166 0 : tree_logical_location_manager::key_from_tree (m_original_fndecl));
167 :
168 159 : if (m_original_depth != m_effective_depth)
169 0 : props.set_integer (PROPERTY_PREFIX "original_depth", m_original_depth);
170 : #undef PROPERTY_PREFIX
171 159 : }
172 :
173 : /* Dump this event to PP (for debugging/logging purposes). */
174 :
175 : void
176 37 : checker_event::dump (pretty_printer *pp) const
177 : {
178 37 : pp_character (pp, '"');
179 37 : print_desc (*pp);
180 37 : pp_printf (pp, "\" (depth %i", m_effective_depth);
181 :
182 37 : if (m_effective_depth != m_original_depth)
183 10 : pp_printf (pp, " corrected from %i",
184 : m_original_depth);
185 37 : if (m_effective_fndecl)
186 : {
187 37 : pp_printf (pp, ", fndecl %qE", m_effective_fndecl);
188 37 : if (m_effective_fndecl != m_original_fndecl)
189 10 : pp_printf (pp, " corrected from %qE", m_original_fndecl);
190 : }
191 37 : pp_printf (pp, ", m_loc=%llx)",
192 37 : (unsigned long long) get_location ());
193 37 : }
194 :
195 : /* Dump this event to stderr (for debugging/logging purposes). */
196 :
197 : DEBUG_FUNCTION void
198 0 : checker_event::debug () const
199 : {
200 0 : tree_dump_pretty_printer pp (stderr);
201 0 : dump (&pp);
202 0 : pp_newline (&pp);
203 0 : }
204 :
205 : /* Hook for being notified when this event has its final id EMISSION_ID
206 : and is about to emitted for PD.
207 :
208 : Base implementation of checker_event::prepare_for_emission vfunc;
209 : subclasses that override this should chain up to it.
210 :
211 : Record PD and EMISSION_ID, and call the print_desc vfunc, so that any
212 : side-effects of the call to print_desc take place before
213 : pending_diagnostic::emit is called.
214 :
215 : For example, state_change_event::print_desc can call
216 : pending_diagnostic::describe_state_change; free_of_non_heap can use this
217 : to tweak the message (TODO: would be neater to simply capture the
218 : pertinent data within the sm-state). */
219 :
220 : void
221 17743 : checker_event::prepare_for_emission (checker_path *path,
222 : pending_diagnostic *pd,
223 : diagnostics::paths::event_id_t emission_id)
224 : {
225 17743 : m_path = path;
226 17743 : m_pending_diagnostic = pd;
227 17743 : m_emission_id = emission_id;
228 :
229 17743 : auto pp = global_dc->clone_printer ();
230 17743 : print_desc (*pp.get ());
231 17743 : }
232 :
233 : std::unique_ptr<diagnostics::digraphs::digraph>
234 28 : checker_event::maybe_make_diagnostic_state_graph (bool debug) const
235 : {
236 28 : const program_state *state = get_program_state ();
237 28 : if (!state)
238 0 : return nullptr;
239 :
240 28 : gcc_assert (m_path);
241 28 : const extrinsic_state &ext_state = m_path->get_ext_state ();
242 :
243 28 : auto result = state->make_diagnostic_state_graph (ext_state);
244 :
245 28 : if (debug)
246 : {
247 27 : pretty_printer pp;
248 27 : text_art::theme *theme = global_dc->get_diagram_theme ();
249 27 : symbolic::dump_node_tree_to_pp<program_state>
250 27 : (*state, theme, &pp, true, true);
251 27 : const json::string_property program_state_property
252 : (custom_sarif_properties::state_graphs::graph::prefix,
253 27 : "analyzer/program_state/");
254 27 : result->set_property (program_state_property,
255 : pp_formatted_text (&pp));
256 27 : }
257 :
258 28 : return result;
259 28 : }
260 :
261 : /* class debug_event : public checker_event. */
262 :
263 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
264 : debug_event.
265 : Use the saved string as the event's description. */
266 :
267 : void
268 0 : debug_event::print_desc (pretty_printer &pp) const
269 : {
270 0 : pp_string (&pp, m_desc);
271 0 : }
272 :
273 : /* class precanned_custom_event : public custom_event. */
274 :
275 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
276 : precanned_custom_event.
277 : Use the saved string as the event's description. */
278 :
279 : void
280 40 : precanned_custom_event::print_desc (pretty_printer &pp) const
281 : {
282 40 : pp_string (&pp, m_desc);
283 40 : }
284 :
285 : /* class statement_event : public checker_event. */
286 :
287 : /* statement_event's ctor. */
288 :
289 12854 : statement_event::statement_event (const gimple *stmt, tree fndecl, int depth,
290 : const program_state &dst_state)
291 : : checker_event (event_kind::stmt,
292 12854 : event_loc_info (gimple_location (stmt), fndecl, depth)),
293 12854 : m_stmt (stmt),
294 12854 : m_dst_state (dst_state)
295 : {
296 12854 : }
297 :
298 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
299 : statement_event.
300 : Use the statement's dump form as the event's description. */
301 :
302 : void
303 12 : statement_event::print_desc (pretty_printer &pp) const
304 : {
305 12 : pp_string (&pp, "stmt: ");
306 12 : pp_gimple_stmt_1 (&pp, m_stmt, 0, (dump_flags_t)0);
307 12 : }
308 :
309 : /* class state_transition_event : public checker_event. */
310 :
311 : void
312 132 : state_transition_event::print_desc (pretty_printer &pp) const
313 : {
314 132 : gcc_assert (m_state_trans);
315 132 : switch (m_state_trans->get_kind ())
316 : {
317 0 : default:
318 0 : gcc_unreachable ();
319 90 : case state_transition::kind::origin:
320 90 : {
321 90 : const state_transition_origin &state_trans
322 : = *static_cast <const state_transition_origin *> (m_state_trans);
323 90 : if (m_pending_diagnostic)
324 : {
325 60 : evdesc::origin_of_state evd (state_trans.m_dst_reg_expr);
326 60 : if (m_pending_diagnostic->describe_origin_of_state (pp, evd))
327 44 : return;
328 : }
329 46 : pp_printf (&pp, "value originates here");
330 : }
331 46 : break;
332 :
333 0 : case state_transition::kind::at_call:
334 0 : case state_transition::kind::at_return:
335 : // These should be handled by call_event and return_event
336 0 : gcc_unreachable ();
337 18 : break;
338 :
339 18 : case state_transition::kind::copy:
340 18 : {
341 18 : const state_transition_copy &state_trans
342 : = *static_cast <const state_transition_copy *> (m_state_trans);
343 18 : if (m_pending_diagnostic)
344 : {
345 24 : evdesc::copy_of_state evd (state_trans.m_src_reg_expr,
346 : state_trans.get_src_event_id (),
347 12 : state_trans.m_dst_reg_expr);
348 12 : if (m_pending_diagnostic->describe_copy_of_state (pp, evd))
349 12 : return;
350 : }
351 6 : auto event_id = state_trans.get_src_event_id ();
352 6 : if (event_id.known_p ())
353 0 : pp_printf (&pp, "copying value from %@ from %qE to %qE",
354 : &event_id,
355 0 : state_trans.m_src_reg_expr,
356 0 : state_trans.m_dst_reg_expr);
357 : else
358 6 : pp_printf (&pp, "copying value from %qE to %qE",
359 6 : state_trans.m_src_reg_expr,
360 6 : state_trans.m_dst_reg_expr);
361 : }
362 6 : break;
363 24 : case state_transition::kind::use:
364 24 : {
365 24 : const state_transition_use &state_trans
366 : = *static_cast <const state_transition_use *> (m_state_trans);
367 24 : if (m_pending_diagnostic)
368 : {
369 32 : evdesc::use_of_state evd (state_trans.m_src_reg_expr,
370 16 : state_trans.get_src_event_id ());
371 16 : if (m_pending_diagnostic->describe_use_of_state (pp, evd))
372 16 : return;
373 : }
374 8 : auto event_id = state_trans.get_src_event_id ();
375 8 : if (state_trans.get_src_event_id ().known_p ())
376 0 : pp_printf (&pp, "using value from %@ from %qE",
377 : &event_id,
378 0 : state_trans.m_src_reg_expr);
379 : else
380 8 : pp_printf (&pp, "using value from %qE",
381 8 : state_trans.m_src_reg_expr);
382 : }
383 8 : break;
384 : }
385 : }
386 :
387 : void
388 44 : state_transition_event::
389 : prepare_for_emission (checker_path *path,
390 : pending_diagnostic *pd,
391 : diagnostics::paths::event_id_t emission_id)
392 : {
393 44 : checker_event::prepare_for_emission (path, pd, emission_id);
394 44 : const_cast<state_transition *> (m_state_trans)->m_event_id = emission_id;
395 44 : }
396 :
397 : /* class region_creation_event : public checker_event. */
398 :
399 1607 : region_creation_event::region_creation_event (const event_loc_info &loc_info)
400 1607 : : checker_event (event_kind::region_creation, loc_info)
401 : {
402 1607 : }
403 :
404 : /* The various region_creation_event subclasses' print_desc
405 : implementations. */
406 :
407 : void
408 1214 : region_creation_event_memory_space::print_desc (pretty_printer &pp) const
409 : {
410 1214 : switch (m_mem_space)
411 : {
412 28 : default:
413 28 : pp_string (&pp, "region created here");
414 28 : return;
415 1086 : case MEMSPACE_STACK:
416 1086 : pp_string (&pp, "region created on stack here");
417 1086 : return;
418 100 : case MEMSPACE_HEAP:
419 100 : pp_string (&pp, "region created on heap here");
420 100 : return;
421 : }
422 : }
423 :
424 : void
425 1678 : region_creation_event_capacity::print_desc (pretty_printer &pp) const
426 : {
427 1678 : gcc_assert (m_capacity);
428 1678 : if (TREE_CODE (m_capacity) == INTEGER_CST)
429 : {
430 1482 : unsigned HOST_WIDE_INT hwi = tree_to_uhwi (m_capacity);
431 1482 : return pp_printf_n (&pp,
432 : hwi,
433 : "capacity: %wu byte",
434 : "capacity: %wu bytes",
435 1482 : hwi);
436 : }
437 : else
438 196 : return pp_printf (&pp, "capacity: %qE bytes", m_capacity);
439 : }
440 :
441 : void
442 220 : region_creation_event_allocation_size::print_desc (pretty_printer &pp) const
443 : {
444 220 : if (m_capacity)
445 : {
446 212 : if (TREE_CODE (m_capacity) == INTEGER_CST)
447 124 : pp_printf_n (&pp,
448 : tree_to_uhwi (m_capacity),
449 : "allocated %E byte here",
450 : "allocated %E bytes here",
451 : m_capacity);
452 : else
453 88 : pp_printf (&pp,
454 : "allocated %qE bytes here",
455 : m_capacity);
456 : }
457 : else
458 8 : pp_printf (&pp, "allocated here");
459 220 : }
460 :
461 : void
462 0 : region_creation_event_debug::print_desc (pretty_printer &pp) const
463 : {
464 0 : pp_string (&pp, "region creation: ");
465 0 : m_reg->dump_to_pp (&pp, true);
466 0 : if (m_capacity)
467 0 : pp_printf (&pp, " capacity: %qE", m_capacity);
468 0 : }
469 :
470 : /* class function_entry_event : public checker_event. */
471 :
472 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
473 : function_entry_event.
474 :
475 : Use a string such as "entry to 'foo'" as the event's description. */
476 :
477 : void
478 2703 : function_entry_event::print_desc (pretty_printer &pp) const
479 : {
480 2703 : if (m_state_trans)
481 : {
482 42 : callsite_expr expr = m_state_trans->get_callsite_expr ();
483 42 : if (tree parm = expr.get_param_tree (m_effective_fndecl))
484 : {
485 40 : auto src_event_id = m_state_trans->get_src_event_id ();
486 40 : if (src_event_id.known_p ())
487 16 : pp_printf (&pp,
488 : "entry to %qE with problematic value from %@ for %qE",
489 16 : m_effective_fndecl,
490 : &src_event_id,
491 : parm);
492 : else
493 24 : pp_printf (&pp, "entry to %qE with problematic value for %qE",
494 24 : m_effective_fndecl, parm);
495 40 : return;
496 : }
497 : }
498 :
499 2663 : pp_printf (&pp, "entry to %qE", m_effective_fndecl);
500 : }
501 :
502 : /* Implementation of diagnostics::paths::event::get_meaning vfunc for
503 : function entry. */
504 :
505 : diagnostics::paths::event::meaning
506 220 : function_entry_event::get_meaning () const
507 : {
508 220 : return meaning (verb::enter, noun::function);
509 : }
510 :
511 : void
512 1634 : function_entry_event::
513 : prepare_for_emission (checker_path *path,
514 : pending_diagnostic *pd,
515 : diagnostics::paths::event_id_t emission_id)
516 : {
517 1634 : checker_event::prepare_for_emission (path, pd, emission_id);
518 1634 : if (m_state_trans)
519 23 : const_cast<state_transition_at_call *> (m_state_trans)->m_event_id = emission_id;
520 1634 : }
521 :
522 : /* class state_change_event : public checker_event. */
523 :
524 : /* state_change_event's ctor. */
525 :
526 4483 : state_change_event::state_change_event (const event_loc_info &loc_info,
527 : const gimple *stmt,
528 : const state_machine &sm,
529 : const svalue *sval,
530 : state_machine::state_t from,
531 : state_machine::state_t to,
532 : const svalue *origin,
533 : const program_state &dst_state,
534 : const exploded_node *enode)
535 : : checker_event (event_kind::state_change, loc_info),
536 4483 : m_stmt (stmt),
537 4483 : m_sm (sm),
538 4483 : m_sval (sval), m_from (from), m_to (to),
539 4483 : m_origin (origin),
540 4483 : m_dst_state (dst_state),
541 4483 : m_enode (enode)
542 : {
543 4483 : }
544 :
545 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
546 : state_change_event.
547 :
548 : Attempt to generate a nicer human-readable description.
549 : For greatest precision-of-wording, give the pending diagnostic
550 : a chance to describe this state change (in terms of the
551 : diagnostic).
552 : Note that we only have a pending_diagnostic set on the event once
553 : the diagnostic is about to being emitted, so the description for
554 : an event can change. */
555 :
556 : void
557 4853 : state_change_event::print_desc (pretty_printer &pp) const
558 : {
559 4853 : if (m_pending_diagnostic)
560 : {
561 4853 : region_model *model = m_dst_state.m_region_model;
562 4853 : tree var = model->get_representative_tree (m_sval);
563 4853 : tree origin = model->get_representative_tree (m_origin);
564 4853 : evdesc::state_change evd (var, origin,
565 4853 : m_from, m_to, m_emission_id, *this);
566 4853 : if (m_pending_diagnostic->describe_state_change (pp, evd))
567 : {
568 4851 : if (flag_analyzer_verbose_state_changes)
569 : {
570 : /* Append debugging information about this event. */
571 :
572 144 : if (var)
573 136 : pp_printf (&pp, " (state of %qE: ", var);
574 : else
575 8 : pp_string (&pp, " (state: ");
576 :
577 144 : pp_printf (&pp, "%qs -> %qs, ",
578 144 : m_from->get_name (),
579 144 : m_to->get_name ());
580 :
581 144 : if (m_origin)
582 0 : pp_printf (&pp, "origin: %qE", origin);
583 : else
584 144 : pp_string (&pp, "NULL origin");
585 :
586 : /* Get any "meaning" of event. */
587 144 : diagnostics::paths::event::meaning meaning = get_meaning ();
588 144 : pp_string (&pp, ", meaning: ");
589 144 : meaning.dump_to_pp (&pp);
590 144 : pp_string (&pp, ")");
591 : }
592 4851 : return;
593 : }
594 : }
595 :
596 : /* Fallback description. */
597 2 : if (m_sval)
598 : {
599 2 : label_text sval_desc = m_sval->get_desc ();
600 2 : pp_printf (&pp,
601 : "state of %qs: %qs -> %qs",
602 : sval_desc.get (),
603 2 : m_from->get_name (),
604 2 : m_to->get_name ());
605 2 : if (m_origin)
606 : {
607 0 : label_text origin_desc = m_origin->get_desc ();
608 0 : pp_printf (&pp, " (origin: %qs)",
609 : origin_desc.get ());
610 0 : }
611 : else
612 2 : pp_string (&pp, " (NULL origin)");
613 2 : }
614 : else
615 : {
616 0 : gcc_assert (m_origin == nullptr);
617 0 : pp_printf (&pp,
618 : "global state: %qs -> %qs",
619 0 : m_from->get_name (),
620 0 : m_to->get_name ());
621 : }
622 : }
623 :
624 : /* Implementation of diagnostics::paths::event::get_meaning vfunc for
625 : state change events: delegate to the pending_diagnostic to
626 : get any meaning. */
627 :
628 : diagnostics::paths::event::meaning
629 337 : state_change_event::get_meaning () const
630 : {
631 337 : if (m_pending_diagnostic)
632 : {
633 337 : region_model *model = m_dst_state.m_region_model;
634 337 : tree var = model->get_representative_tree (m_sval);
635 337 : tree origin = model->get_representative_tree (m_origin);
636 337 : evdesc::state_change evd (var, origin,
637 337 : m_from, m_to, m_emission_id, *this);
638 337 : return m_pending_diagnostic->get_meaning_for_state_change (evd);
639 : }
640 : else
641 0 : return meaning ();
642 : }
643 :
644 : /* class superedge_event : public checker_event. */
645 :
646 : /* Implementation of diagnostics::paths::event::maybe_add_sarif_properties
647 : for superedge_event. */
648 :
649 : void
650 51 : superedge_event::
651 : maybe_add_sarif_properties (diagnostics::sarif_builder &builder,
652 : diagnostics::sarif_object &thread_flow_loc_obj)
653 : const
654 : {
655 51 : checker_event::maybe_add_sarif_properties (builder, thread_flow_loc_obj);
656 51 : auto &props = thread_flow_loc_obj.get_or_create_properties ();
657 : #define PROPERTY_PREFIX "gcc/analyzer/superedge_event/"
658 51 : if (m_sedge)
659 51 : props.set (PROPERTY_PREFIX "superedge", m_sedge->to_json ());
660 : #undef PROPERTY_PREFIX
661 51 : }
662 :
663 : /* Determine if this event should be filtered at the given verbosity
664 : level. */
665 :
666 : bool
667 2599 : superedge_event::should_filter_p (int verbosity) const
668 : {
669 2599 : if (m_sedge->get_any_cfg_edge ())
670 : {
671 2599 : if (verbosity < 2)
672 : return true;
673 :
674 2566 : if (verbosity < 4)
675 : {
676 : /* Filter events with empty descriptions. This ought to filter
677 : FALLTHRU, but retain true/false/switch edges. */
678 2566 : auto pp = global_dc->clone_printer ();
679 2566 : print_desc (*pp.get ());
680 2566 : if (pp_formatted_text (pp.get ()) [0] == '\0')
681 2 : return true;
682 2566 : }
683 : }
684 : return false;
685 : }
686 :
687 : const program_state *
688 12 : superedge_event::get_program_state () const
689 : {
690 12 : return &m_eedge.m_dest->get_state ();
691 : }
692 :
693 : const call_and_return_op *
694 1397 : superedge_event::get_call_and_return_op () const
695 : {
696 1397 : if (m_sedge)
697 1397 : if (auto base_op = m_sedge->get_op ())
698 1397 : return base_op->dyn_cast_call_and_return_op ();
699 : return nullptr;
700 : }
701 :
702 : /* superedge_event's ctor. */
703 :
704 7019 : superedge_event::superedge_event (enum event_kind kind,
705 : const exploded_edge &eedge,
706 : const event_loc_info &loc_info)
707 : : checker_event (kind, loc_info),
708 7019 : m_eedge (eedge), m_sedge (eedge.m_sedge)
709 : {
710 7019 : gcc_assert (m_sedge);
711 7019 : }
712 :
713 : /* class cfg_edge_event : public superedge_event. */
714 :
715 : /* cfg_edge_event's ctor. */
716 :
717 5622 : cfg_edge_event::cfg_edge_event (enum event_kind kind,
718 : const exploded_edge &eedge,
719 : const event_loc_info &loc_info,
720 : const control_flow_op *op)
721 : : superedge_event (kind, eedge, loc_info),
722 5622 : m_op (op)
723 : {
724 5622 : }
725 :
726 : /* Implementation of diagnostics::paths::event::get_meaning vfunc for
727 : CFG edge events. */
728 :
729 : diagnostics::paths::event::meaning
730 294 : cfg_edge_event::get_meaning () const
731 : {
732 294 : if (::edge e = get_cfg_edge ())
733 : {
734 294 : if (e->flags & EDGE_TRUE_VALUE)
735 126 : return meaning (verb::branch, property::true_);
736 168 : else if (e->flags & EDGE_FALSE_VALUE)
737 128 : return meaning (verb::branch, property::false_);
738 : }
739 40 : return meaning ();
740 : }
741 :
742 : ::edge
743 743 : cfg_edge_event::get_cfg_edge () const
744 : {
745 743 : return m_sedge->get_any_cfg_edge ();
746 : }
747 :
748 : /* If this event is for a conditional, write the sense of the
749 : conditional to *OUT and return true.
750 : Otherwise return false. */
751 :
752 : bool
753 449 : cfg_edge_event::maybe_get_edge_sense (bool *out) const
754 : {
755 449 : if (::edge e = get_cfg_edge ())
756 : {
757 449 : if (e->flags & EDGE_TRUE_VALUE)
758 : {
759 173 : *out = true;
760 173 : return true;
761 : }
762 276 : else if (e->flags & EDGE_FALSE_VALUE)
763 : {
764 270 : *out = false;
765 270 : return true;
766 : }
767 : }
768 : return false;
769 : }
770 :
771 : /* class start_cfg_edge_event : public cfg_edge_event. */
772 :
773 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
774 : start_cfg_edge_event.
775 :
776 : If -fanalyzer-verbose-edges, then generate low-level descriptions, such
777 : as
778 : "taking 'true' edge SN:7 -> SN:8".
779 :
780 : Otherwise, generate strings using the label of the underlying CFG if
781 : any, such as:
782 : "following 'true' branch..." or
783 : "following 'case 3' branch..."
784 : "following 'default' branch..."
785 :
786 : For conditionals, attempt to supply a description of the condition that
787 : holds, such as:
788 : "following 'false' branch (when 'ptr' is non-NULL)..."
789 :
790 : Failing that, print nothing (which will lead to this event
791 : being filtered). */
792 :
793 : void
794 7214 : start_cfg_edge_event::print_desc (pretty_printer &pp) const
795 : {
796 7214 : bool user_facing = !flag_analyzer_verbose_edges;
797 7214 : label_text edge_desc (m_sedge->get_description (user_facing));
798 7214 : if (user_facing)
799 : {
800 7214 : if (edge_desc.get ()
801 7214 : && strlen (edge_desc.get ()) > 0
802 14426 : && m_op)
803 : {
804 7212 : label_text cond_desc
805 7212 : = m_op->maybe_describe_condition (pp_show_color (&pp));
806 7212 : label_text result;
807 7212 : if (cond_desc.get ())
808 4346 : pp_printf (&pp,
809 : "following %qs branch (%s)...",
810 : edge_desc.get (), cond_desc.get ());
811 : else
812 2866 : pp_printf (&pp,
813 : "following %qs branch...",
814 : edge_desc.get ());
815 11435 : }
816 : }
817 : else
818 : {
819 0 : if (strlen (edge_desc.get ()) > 0)
820 0 : return pp_printf (&pp,
821 : "taking %qs edge SN:%i -> SN:%i",
822 : edge_desc.get (),
823 0 : m_sedge->m_src->m_id,
824 0 : m_sedge->m_dest->m_id);
825 : else
826 0 : return pp_printf (&pp,
827 : "taking edge SN:%i -> SN:%i",
828 0 : m_sedge->m_src->m_id,
829 0 : m_sedge->m_dest->m_id);
830 : }
831 7214 : }
832 :
833 : /* class catch_cfg_edge_event : public cfg_edge_event. */
834 :
835 : diagnostics::paths::event::meaning
836 6 : catch_cfg_edge_event::get_meaning () const
837 : {
838 6 : return meaning (verb::catch_);
839 : }
840 :
841 : /* class call_event : public superedge_event. */
842 :
843 : /* call_event's ctor. */
844 :
845 1397 : call_event::call_event (const exploded_edge &eedge,
846 : const event_loc_info &loc_info,
847 : const state_transition_at_call *state_trans)
848 : : superedge_event (event_kind::call_, eedge, loc_info),
849 1397 : m_state_trans (state_trans)
850 : {
851 1397 : m_src_snode = eedge.m_src->get_supernode ();
852 1397 : m_dest_snode = eedge.m_dest->get_supernode ();
853 1397 : }
854 :
855 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
856 : call_event.
857 :
858 : If this call event passes critical state for an sm-based warning,
859 : allow the diagnostic to generate a precise description, such as:
860 :
861 : "passing freed pointer 'ptr' in call to 'foo' from 'bar'"
862 :
863 : Otherwise, generate a description of the form
864 : "calling 'foo' from 'bar'". */
865 :
866 : void
867 1669 : call_event::print_desc (pretty_printer &pp) const
868 : {
869 1669 : if (m_pending_diagnostic)
870 : {
871 1669 : if (m_critical_state.m_state)
872 : {
873 402 : gcc_assert (m_critical_state.m_var);
874 402 : tree var = fixup_tree_for_diagnostic (m_critical_state.m_var);
875 402 : evdesc::call_with_state evd (m_src_snode->m_fun->decl,
876 402 : m_dest_snode->m_fun->decl,
877 : var,
878 402 : m_critical_state.m_state,
879 402 : m_state_trans);
880 402 : if (m_pending_diagnostic->describe_call_with_state (pp, evd))
881 180 : return;
882 : }
883 1267 : else if (m_state_trans)
884 : {
885 46 : evdesc::call_with_state evd (m_src_snode->m_fun->decl,
886 46 : m_dest_snode->m_fun->decl,
887 : NULL_TREE, nullptr,
888 46 : m_state_trans);
889 46 : if (m_pending_diagnostic->describe_call_with_state (pp, evd))
890 44 : return;
891 42 : callsite_expr expr = m_state_trans->get_callsite_expr ();
892 42 : if (expr.param_p ())
893 : {
894 40 : auto src_event_id = m_state_trans->get_src_event_id ();
895 40 : if (src_event_id.known_p ())
896 16 : pp_printf (&pp,
897 : "passing problematic value from %@ from %qE to %qE"
898 : " via parameter %i",
899 : &src_event_id,
900 : get_caller_fndecl (),
901 : get_callee_fndecl (),
902 : expr.param_num ());
903 : else
904 24 : pp_printf (&pp,
905 : "passing problematic value from %qE to %qE"
906 : " via parameter %i",
907 : get_caller_fndecl (),
908 : get_callee_fndecl (),
909 : expr.param_num ());
910 40 : return;
911 : }
912 : }
913 : }
914 :
915 1445 : pp_printf (&pp,
916 : "calling %qE from %qE",
917 : get_callee_fndecl (),
918 : get_caller_fndecl ());
919 : }
920 :
921 : /* Implementation of diagnostics::paths::event::get_meaning vfunc for
922 : function call events. */
923 :
924 : diagnostics::paths::event::meaning
925 136 : call_event::get_meaning () const
926 : {
927 136 : return meaning (verb::call, noun::function);
928 : }
929 :
930 : /* Override of checker_event::is_call_p for calls. */
931 :
932 : bool
933 2042 : call_event::is_call_p () const
934 : {
935 2042 : return true;
936 : }
937 :
938 : tree
939 1553 : call_event::get_caller_fndecl () const
940 : {
941 1553 : return m_src_snode->m_fun->decl;
942 : }
943 :
944 : tree
945 1553 : call_event::get_callee_fndecl () const
946 : {
947 1553 : return m_dest_snode->m_fun->decl;
948 : }
949 :
950 : const program_state *
951 3 : call_event::get_program_state () const
952 : {
953 : /* Use the state at the source (at the caller),
954 : rather than the one at the dest, which has a frame for the callee. */
955 3 : return &m_eedge.m_src->get_state ();
956 : }
957 :
958 : void
959 860 : call_event::prepare_for_emission (checker_path *path,
960 : pending_diagnostic *pd,
961 : diagnostics::paths::event_id_t emission_id)
962 : {
963 860 : checker_event::prepare_for_emission (path, pd, emission_id);
964 860 : if (m_state_trans)
965 23 : const_cast<state_transition_at_call *> (m_state_trans)->m_event_id = emission_id;
966 860 : }
967 :
968 : /* class return_event : public checker_event. */
969 :
970 : /* return_event's ctor. */
971 :
972 818 : return_event::return_event (const exploded_edge &eedge,
973 : const event_loc_info &loc_info,
974 : const state_transition_at_return *state_trans)
975 : : checker_event (event_kind::return_, loc_info),
976 818 : m_eedge (eedge),
977 818 : m_state_trans (state_trans)
978 : {
979 818 : m_src_snode = eedge.m_src->get_supernode ();
980 818 : m_dest_snode = eedge.m_dest->get_supernode ();
981 818 : m_call_and_return_op
982 818 : = eedge.m_src->get_point ().get_call_string ().get_top_of_stack ().m_call_op;
983 818 : }
984 :
985 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
986 : return_event.
987 :
988 : If this return event returns critical state for an sm-based warning,
989 : allow the diagnostic to generate a precise description, such as:
990 :
991 : "possible of NULL to 'foo' from 'bar'"
992 :
993 : Otherwise, generate a description of the form
994 : "returning to 'foo' from 'bar'. */
995 :
996 : void
997 564 : return_event::print_desc (pretty_printer &pp) const
998 : {
999 : /* For greatest precision-of-wording, if this is returning the
1000 : state involved in the pending diagnostic, give the pending
1001 : diagnostic a chance to describe this return (in terms of
1002 : itself). */
1003 564 : if (m_pending_diagnostic)
1004 : {
1005 564 : if (m_critical_state.m_state)
1006 : {
1007 104 : evdesc::return_of_state evd (m_dest_snode->m_fun->decl,
1008 104 : m_src_snode->m_fun->decl,
1009 : m_critical_state.m_state,
1010 104 : nullptr);
1011 104 : if (m_pending_diagnostic->describe_return_of_state (pp, evd))
1012 50 : return;
1013 : }
1014 460 : else if (m_state_trans)
1015 : {
1016 24 : evdesc::return_of_state evd (m_dest_snode->m_fun->decl,
1017 24 : m_src_snode->m_fun->decl,
1018 : nullptr,
1019 24 : m_state_trans);
1020 24 : if (m_pending_diagnostic->describe_return_of_state (pp, evd))
1021 24 : return;
1022 : }
1023 : }
1024 :
1025 490 : pp_printf (&pp,
1026 : "returning to %qE from %qE",
1027 490 : m_dest_snode->m_fun->decl,
1028 490 : m_src_snode->m_fun->decl);
1029 : }
1030 :
1031 : /* Implementation of diagnostics::paths::event::get_meaning vfunc for
1032 : function return events. */
1033 :
1034 : diagnostics::paths::event::meaning
1035 54 : return_event::get_meaning () const
1036 : {
1037 54 : return meaning (verb::return_, noun::function);
1038 : }
1039 :
1040 : /* Override of checker_event::is_return_p for returns. */
1041 :
1042 : bool
1043 818 : return_event::is_return_p () const
1044 : {
1045 818 : return true;
1046 : }
1047 :
1048 : const program_state *
1049 3 : return_event::get_program_state () const
1050 : {
1051 3 : return &m_eedge.m_dest->get_state ();
1052 : }
1053 :
1054 : void
1055 281 : return_event::prepare_for_emission (checker_path *path,
1056 : pending_diagnostic *pd,
1057 : diagnostics::paths::event_id_t emission_id)
1058 : {
1059 281 : checker_event::prepare_for_emission (path, pd, emission_id);
1060 281 : if (m_state_trans)
1061 12 : const_cast<state_transition_at_return *> (m_state_trans)->m_event_id = emission_id;
1062 281 : }
1063 :
1064 : /* class start_consolidated_cfg_edges_event : public checker_event. */
1065 :
1066 : void
1067 142 : start_consolidated_cfg_edges_event::print_desc (pretty_printer &pp) const
1068 : {
1069 142 : pp_printf (&pp,
1070 : "following %qs branch...",
1071 142 : m_edge_sense ? "true" : "false");
1072 142 : }
1073 :
1074 : /* Implementation of diagnostics::paths::event::get_meaning vfunc for
1075 : start_consolidated_cfg_edges_event. */
1076 :
1077 : diagnostics::paths::event::meaning
1078 0 : start_consolidated_cfg_edges_event::get_meaning () const
1079 : {
1080 0 : return meaning (verb::branch,
1081 0 : (m_edge_sense ? property::true_ : property::false_));
1082 : }
1083 :
1084 : /* class inlined_call_event : public checker_event. */
1085 :
1086 : void
1087 430 : inlined_call_event::print_desc (pretty_printer &pp) const
1088 : {
1089 430 : pp_printf (&pp,
1090 : "inlined call to %qE from %qE",
1091 430 : m_apparent_callee_fndecl,
1092 430 : m_apparent_caller_fndecl);
1093 430 : }
1094 :
1095 : /* Implementation of diagnostics::paths::event::get_meaning vfunc for
1096 : reconstructed inlined function calls. */
1097 :
1098 : diagnostics::paths::event::meaning
1099 72 : inlined_call_event::get_meaning () const
1100 : {
1101 72 : return meaning (verb::call, noun::function);
1102 : }
1103 :
1104 : /* class setjmp_event : public checker_event. */
1105 :
1106 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
1107 : setjmp_event. */
1108 :
1109 : void
1110 41 : setjmp_event::print_desc (pretty_printer &pp) const
1111 : {
1112 41 : pp_printf (&pp,
1113 : "%qs called here",
1114 : get_user_facing_name (m_setjmp_call));
1115 41 : }
1116 :
1117 : diagnostics::paths::event::meaning
1118 17 : setjmp_event::get_meaning () const
1119 : {
1120 17 : return meaning (verb::setjmp_);
1121 : }
1122 :
1123 : /* Implementation of checker_event::prepare_for_emission vfunc for setjmp_event.
1124 :
1125 : Record this setjmp's event ID into the path, so that rewind events can
1126 : use it. */
1127 :
1128 : void
1129 20 : setjmp_event::prepare_for_emission (checker_path *path,
1130 : pending_diagnostic *pd,
1131 : diagnostics::paths::event_id_t emission_id)
1132 : {
1133 20 : checker_event::prepare_for_emission (path, pd, emission_id);
1134 20 : path->record_setjmp_event (m_enode, emission_id);
1135 20 : }
1136 :
1137 : /* class rewind_event : public checker_event. */
1138 :
1139 : /* Get the fndecl containing the site of the longjmp call. */
1140 :
1141 : tree
1142 93 : rewind_event::get_longjmp_caller () const
1143 : {
1144 93 : return m_eedge->m_src->get_function ()->decl;
1145 : }
1146 :
1147 : /* Get the fndecl containing the site of the setjmp call. */
1148 :
1149 : tree
1150 85 : rewind_event::get_setjmp_caller () const
1151 : {
1152 85 : return m_eedge->m_dest->get_function ()->decl;
1153 : }
1154 :
1155 : diagnostics::paths::event::meaning
1156 26 : rewind_event::get_meaning () const
1157 : {
1158 26 : return meaning (verb::longjmp_);
1159 : }
1160 :
1161 : /* rewind_event's ctor. */
1162 :
1163 30 : rewind_event::rewind_event (const exploded_edge *eedge,
1164 : enum event_kind kind,
1165 : const event_loc_info &loc_info,
1166 : const rewind_info_t *rewind_info)
1167 : : checker_event (kind, loc_info),
1168 30 : m_rewind_info (rewind_info),
1169 30 : m_eedge (eedge)
1170 : {
1171 30 : gcc_assert (m_eedge->m_custom_info.get () == m_rewind_info);
1172 30 : }
1173 :
1174 : /* class rewind_from_longjmp_event : public rewind_event. */
1175 :
1176 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
1177 : rewind_from_longjmp_event. */
1178 :
1179 : void
1180 31 : rewind_from_longjmp_event::print_desc (pretty_printer &pp) const
1181 : {
1182 31 : const char *src_name
1183 31 : = get_user_facing_name (m_rewind_info->get_longjmp_call ());
1184 :
1185 31 : if (get_longjmp_caller () == get_setjmp_caller ())
1186 : /* Special-case: purely intraprocedural rewind. */
1187 8 : pp_printf (&pp,
1188 : "rewinding within %qE from %qs...",
1189 : get_longjmp_caller (),
1190 : src_name);
1191 : else
1192 23 : pp_printf (&pp,
1193 : "rewinding from %qs in %qE...",
1194 : src_name,
1195 : get_longjmp_caller ());
1196 31 : }
1197 :
1198 : /* class rewind_to_setjmp_event : public rewind_event. */
1199 :
1200 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
1201 : rewind_to_setjmp_event. */
1202 :
1203 : void
1204 31 : rewind_to_setjmp_event::print_desc (pretty_printer &pp) const
1205 : {
1206 31 : const char *dst_name
1207 31 : = get_user_facing_name (m_rewind_info->get_setjmp_call ());
1208 :
1209 : /* If we can, identify the ID of the setjmp_event. */
1210 31 : if (m_original_setjmp_event_id.known_p ())
1211 : {
1212 16 : if (get_longjmp_caller () == get_setjmp_caller ())
1213 : /* Special-case: purely intraprocedural rewind. */
1214 4 : pp_printf (&pp,
1215 : "...to %qs (saved at %@)",
1216 : dst_name,
1217 : &m_original_setjmp_event_id);
1218 : else
1219 12 : pp_printf (&pp,
1220 : "...to %qs in %qE (saved at %@)",
1221 : dst_name,
1222 : get_setjmp_caller (),
1223 : &m_original_setjmp_event_id);
1224 : }
1225 : else
1226 : {
1227 15 : if (get_longjmp_caller () == get_setjmp_caller ())
1228 : /* Special-case: purely intraprocedural rewind. */
1229 4 : pp_printf (&pp,
1230 : "...to %qs",
1231 : dst_name);
1232 : else
1233 11 : pp_printf (&pp,
1234 : "...to %qs in %qE",
1235 : dst_name,
1236 : get_setjmp_caller ());
1237 : }
1238 31 : }
1239 :
1240 : /* Implementation of checker_event::prepare_for_emission vfunc for
1241 : rewind_to_setjmp_event.
1242 :
1243 : Attempt to look up the setjmp event ID that recorded the jmp_buf
1244 : for this rewind. */
1245 :
1246 : void
1247 15 : rewind_to_setjmp_event::prepare_for_emission (checker_path *path,
1248 : pending_diagnostic *pd,
1249 : diagnostics::paths::event_id_t emission_id)
1250 : {
1251 15 : checker_event::prepare_for_emission (path, pd, emission_id);
1252 15 : path->get_setjmp_event (m_rewind_info->get_enode_origin (),
1253 : &m_original_setjmp_event_id);
1254 15 : }
1255 :
1256 : /* class throw_event : public checker_event. */
1257 :
1258 : diagnostics::paths::event::meaning
1259 6 : throw_event::get_meaning () const
1260 : {
1261 6 : return meaning (verb::throw_);
1262 : }
1263 :
1264 : /* class explicit_throw_event : public throw_event. */
1265 : void
1266 192 : explicit_throw_event::print_desc (pretty_printer &pp) const
1267 : {
1268 192 : if (m_is_rethrow)
1269 : {
1270 30 : if (m_type)
1271 18 : pp_printf (&pp, "rethrowing exception of type %qT here...", m_type);
1272 : else
1273 12 : pp_printf (&pp, "rethrowing exception here...");
1274 : }
1275 : else
1276 : {
1277 162 : if (m_type)
1278 162 : pp_printf (&pp, "throwing exception of type %qT here...", m_type);
1279 : else
1280 0 : pp_printf (&pp, "throwing exception here...");
1281 : }
1282 192 : }
1283 :
1284 : /* class throw_from_call_to_external_fn_event : public throw_event. */
1285 :
1286 : void
1287 70 : throw_from_call_to_external_fn_event::print_desc (pretty_printer &pp) const
1288 : {
1289 70 : if (m_fndecl)
1290 70 : pp_printf (&pp, "if %qD throws an exception...", m_fndecl);
1291 : else
1292 0 : pp_printf (&pp, "if the called function throws an exception...");
1293 70 : }
1294 :
1295 : // class unwind_event : public checker_event
1296 :
1297 : void
1298 26 : unwind_event::print_desc (pretty_printer &pp) const
1299 : {
1300 26 : if (m_num_frames > 1)
1301 18 : pp_printf (&pp, "unwinding %i stack frames", m_num_frames);
1302 : else
1303 8 : pp_printf (&pp, "unwinding stack frame");
1304 26 : }
1305 :
1306 : diagnostics::paths::event::meaning
1307 3 : unwind_event::get_meaning () const
1308 : {
1309 3 : return meaning (verb::unwind_);
1310 : }
1311 :
1312 : /* class warning_event : public checker_event. */
1313 :
1314 : /* Implementation of diagnostics::paths::event::print_desc vfunc for
1315 : warning_event.
1316 :
1317 : If the pending diagnostic implements describe_final_event, use it,
1318 : generating a precise description e.g.
1319 : "second 'free' here; first 'free' was at (7)"
1320 :
1321 : Otherwise generate a generic description. */
1322 :
1323 : void
1324 8754 : warning_event::print_desc (pretty_printer &pp) const
1325 : {
1326 8754 : if (m_pending_diagnostic)
1327 : {
1328 8742 : tree var = fixup_tree_for_diagnostic (m_var);
1329 8742 : evdesc::final_event evd (var, m_state, *this);
1330 8742 : if (m_pending_diagnostic->describe_final_event (pp, evd))
1331 : {
1332 8141 : if (m_sm && flag_analyzer_verbose_state_changes)
1333 : {
1334 72 : if (var)
1335 64 : pp_printf (&pp, " (%qE is in state %qs)",
1336 64 : var, m_state->get_name ());
1337 : else
1338 8 : pp_printf (&pp, " (in global state %qs)",
1339 8 : m_state->get_name ());
1340 : }
1341 8141 : return;
1342 : }
1343 : }
1344 :
1345 613 : if (m_sm)
1346 : {
1347 64 : if (m_var)
1348 64 : pp_printf (&pp, "here (%qE is in state %qs)",
1349 64 : m_var, m_state->get_name ());
1350 : else
1351 0 : pp_printf (&pp, "here (in global state %qs)",
1352 0 : m_state->get_name ());
1353 : return;
1354 : }
1355 : else
1356 549 : pp_string (&pp, "here");
1357 : }
1358 :
1359 : /* Implementation of diagnostics::paths::event::get_meaning vfunc for
1360 : warning_event. */
1361 :
1362 : diagnostics::paths::event::meaning
1363 233 : warning_event::get_meaning () const
1364 : {
1365 233 : return meaning (verb::danger, noun::unknown);
1366 : }
1367 :
1368 : const program_state *
1369 3 : warning_event::get_program_state () const
1370 : {
1371 3 : if (m_program_state)
1372 : return m_program_state.get ();
1373 : else
1374 1 : return &m_enode->get_state ();
1375 : }
1376 :
1377 : } // namespace ana
1378 :
1379 : #endif /* #if ENABLE_ANALYZER */
|