Line data Source code
1 : /* Symbolic values.
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 : #ifndef GCC_ANALYZER_SVALUE_H
22 : #define GCC_ANALYZER_SVALUE_H
23 :
24 : #include "analyzer/symbolic-nodes.h"
25 : #include "analyzer/store.h"
26 : #include "analyzer/program-point.h"
27 : #include "analyzer/symbolic-pointers.h"
28 :
29 : using namespace ana;
30 :
31 : namespace ana {
32 :
33 : /* An enum for discriminating between the different concrete subclasses
34 : of svalue. */
35 :
36 : enum svalue_kind
37 : {
38 : SK_POINTER,
39 : SK_CONSTANT,
40 : SK_UNKNOWN,
41 : SK_POISONED,
42 : SK_SETJMP,
43 : SK_INITIAL,
44 : SK_UNARYOP,
45 : SK_BINOP,
46 : SK_BIT_VECTOR,
47 : SK_UNMERGEABLE,
48 : SK_PLACEHOLDER,
49 : SK_WIDENING,
50 : SK_ASM_OUTPUT,
51 : SK_CONST_FN_RESULT
52 : };
53 :
54 : /* svalue and its subclasses.
55 :
56 : The class hierarchy looks like this (using indentation to show
57 : inheritance, and with svalue_kinds shown for the concrete subclasses):
58 :
59 : svalue
60 : pointer_svalue (SK_POINTER): a symbolic::pointer with a type
61 : constant_svalue (SK_CONSTANT): a constant
62 : unknown_svalue (SK_UNKNOWN): an unknowable value
63 : poisoned_svalue (SK_POISONED): a unusable value (undefined)
64 : setjmp_svalue (SK_SETJMP): a setjmp/longjmp buffer
65 : initial_svalue (SK_INITIAL): the initial value of a region
66 : unaryop_svalue (SK_UNARYOP): unary operation on another svalue
67 : binop_svalue (SK_BINOP): binary operation on two svalues
68 : svalue_from_bit_vector (SK_BIT_VECTOR): the interpretation of a symbolic bit_vector as a type
69 : unmergeable_svalue (SK_UNMERGEABLE): a value that is so interesting
70 : from a control-flow perspective that it can inhibit state-merging
71 : placeholder_svalue (SK_PLACEHOLDER): for use in selftests.
72 : widening_svalue (SK_WIDENING): a merger of two svalues (possibly
73 : in an iteration).
74 : asm_output_svalue (SK_ASM_OUTPUT): an output from a deterministic
75 : asm stmt.
76 : const_fn_result_svalue (SK_CONST_FN_RESULT): the return value from
77 : a function with __attribute((const)) for given inputs. */
78 :
79 : /* An abstract base class representing a value held by a region of memory. */
80 :
81 : class svalue : public symbolic::value_node
82 : {
83 : public:
84 76 : virtual ~svalue () {}
85 :
86 22060759 : tree get_type () const { return m_type; }
87 :
88 : const svalue *
89 20021505 : dyn_cast_svalue () const final override { return this; }
90 :
91 : virtual enum svalue_kind get_kind () const = 0;
92 :
93 : void print (const region_model &model,
94 : pretty_printer *pp) const;
95 :
96 : virtual void dump_to_pp (pretty_printer *pp, bool simple) const = 0;
97 : void dump () const;
98 : void dump (bool simple) const;
99 :
100 : void
101 : print_dump_widget_label (pretty_printer *pp) const final override;
102 :
103 : virtual void
104 : print_svalue_for_dump_widget_label (pretty_printer *pp) const = 0;
105 :
106 : void
107 : add_dump_widget_children (text_art::tree_widget &w,
108 : symbolic::node_dump_state &nds) const override;
109 :
110 : const char *
111 42090 : get_any_dump_color () const override { return "svalue"; }
112 :
113 : label_text get_desc (bool simple=true) const;
114 :
115 : virtual const pointer_svalue *
116 20640195 : dyn_cast_pointer_svalue () const { return nullptr; }
117 : virtual const constant_svalue *
118 5561577 : dyn_cast_constant_svalue () const { return nullptr; }
119 : virtual const poisoned_svalue *
120 332257 : dyn_cast_poisoned_svalue () const { return nullptr; }
121 : virtual const setjmp_svalue *
122 38 : dyn_cast_setjmp_svalue () const { return nullptr; }
123 : virtual const initial_svalue *
124 1830704 : dyn_cast_initial_svalue () const { return nullptr; }
125 : virtual const unaryop_svalue *
126 11569407 : dyn_cast_unaryop_svalue () const { return nullptr; }
127 : virtual const binop_svalue *
128 523789 : dyn_cast_binop_svalue () const { return nullptr; }
129 : virtual const svalue_from_bit_vector *
130 20395368 : dyn_cast_svalue_from_bit_vector () const { return nullptr; }
131 : virtual const unmergeable_svalue *
132 10865662 : dyn_cast_unmergeable_svalue () const { return nullptr; }
133 : virtual const widening_svalue *
134 215710 : dyn_cast_widening_svalue () const { return nullptr; }
135 : virtual const asm_output_svalue *
136 0 : dyn_cast_asm_output_svalue () const { return nullptr; }
137 : virtual const const_fn_result_svalue *
138 0 : dyn_cast_const_fn_result_svalue () const { return nullptr; }
139 :
140 : iter_result
141 : for_each_svalue (iter_result (*cb) (const svalue &sval,
142 : void *user_data),
143 : void *user_data) const final override;
144 :
145 : bool
146 : has_concrete_size_p (concrete_bit_size *out,
147 : symbolic::scalar_manager<concrete_bit_size> &bit_mgr) const;
148 :
149 : tree maybe_get_constant () const;
150 : const symbolic::pointer *maybe_get_symbolic_pointer () const;
151 : const svalue *maybe_undo_cast () const;
152 : const svalue *unwrap_any_unmergeable () const;
153 :
154 : const svalue *can_merge_p (const svalue *other,
155 : region_model_manager *mgr,
156 : model_merger *merger) const;
157 :
158 : virtual void accept (visitor *v) const = 0;
159 :
160 : static int cmp_ptr (const svalue *, const svalue *);
161 : static int cmp_ptr_ptr (const void *, const void *);
162 :
163 : virtual bool all_zeroes_p () const;
164 :
165 : /* Can this svalue be involved in constraints and sm-state?
166 : Most can, but UNKNOWN and POISONED svalues are singletons
167 : per-type and thus it's meaningless for them to "have state". */
168 1704101 : virtual bool can_have_associated_state_p () const { return true; }
169 :
170 : const region *maybe_get_deref_base_region () const;
171 :
172 : bool maybe_print_for_user (pretty_printer *pp,
173 : const region_model &model,
174 : const svalue *outer_sval = nullptr) const;
175 :
176 : tree maybe_get_type_from_typeinfo () const;
177 :
178 : /* If we can get a value_range for this svalue, write it to OUT
179 : and return true. Otherwise return false. */
180 : bool
181 305726 : maybe_get_value_range (value_range &out) const
182 : {
183 305726 : if (maybe_get_value_range_1 (out))
184 : {
185 199916 : gcc_assert (!out.undefined_p ());
186 : return true;
187 : }
188 : return false;
189 : }
190 :
191 : virtual bool conjured_p () const;
192 :
193 : bool derived_from_initial_value_p () const;
194 :
195 : protected:
196 1337315 : svalue (complexity c, symbolic::node::id_t id, tree type)
197 76039 : : value_node (c, id), m_type (type)
198 : {}
199 :
200 : void print_svalue_node_label (pretty_printer *pp) const;
201 :
202 : std::unique_ptr<json::object>
203 : make_json_obj (const char *type_name) const;
204 :
205 : private:
206 : virtual bool
207 : maybe_get_value_range_1 (value_range &out) const;
208 :
209 : tree m_type;
210 : };
211 :
212 : /* Concrete subclass of svalue representing a symbolic::pointer with a type.
213 :
214 : Consolidation/canonicalization:
215 : - the pointer must not be a zero-offset pointer to *SYMBOLIC_REGION (PTR);
216 : we fold such cases to PTR (perhaps with a cast). */
217 :
218 : class pointer_svalue : public svalue
219 : {
220 : public:
221 : /* A support class for uniquifying instances of pointer_svalue. */
222 : struct key_t
223 : {
224 2782270 : key_t (tree type, symbolic::pointer ptr)
225 2782270 : : m_type (type), m_ptr (ptr)
226 : {}
227 :
228 : bool operator< (const key_t &other) const;
229 : bool operator== (const key_t &other) const
230 : {
231 : return (m_type == other.m_type && m_ptr == other.m_ptr);
232 : }
233 :
234 : complexity
235 : get_complexity () const;
236 :
237 : tree m_type;
238 : symbolic::pointer m_ptr;
239 : };
240 :
241 44589 : pointer_svalue (symbolic::node::id_t id, key_t k)
242 : : svalue (k.get_complexity (), id, k.m_type),
243 44589 : m_ptr (k.m_ptr)
244 : {
245 44589 : }
246 :
247 3051289 : enum svalue_kind get_kind () const final override { return SK_POINTER; }
248 : const pointer_svalue *
249 5904739 : dyn_cast_pointer_svalue () const final override { return this; }
250 :
251 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
252 :
253 : void
254 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
255 : void
256 : add_dump_widget_children (text_art::tree_widget &w,
257 : symbolic::node_dump_state &nds) const final override;
258 : void
259 : accept_node_visitor (symbolic::node_visitor &v) const final override;
260 :
261 : std::unique_ptr<json::object>
262 : to_json () const final override;
263 :
264 : std::unique_ptr<diagnostics::markup::node>
265 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
266 :
267 : void accept (visitor *v) const final override;
268 : bool implicitly_live_p (symbolic::liveness_context &) const final override;
269 :
270 : const symbolic::pointer &
271 5891443 : get_symbolic_pointer () const { return m_ptr; }
272 :
273 : /* Deprecated (poor terminology); use get_cluster_region instead. */
274 : const cluster_region &
275 229796 : get_base_region () const { return m_ptr.get_cluster_region (); }
276 :
277 : const cluster_region &
278 : get_cluster_region () const { return m_ptr.get_cluster_region (); }
279 :
280 : const symbolic_byte_offset &
281 977 : get_byte_offset () const { return m_ptr.get_byte_offset (); }
282 :
283 : bool
284 : zero_offset_p () const { return m_ptr.zero_offset_p (); }
285 :
286 12351 : bool non_null_p () const { return m_ptr.non_null_p (); }
287 :
288 : private:
289 : symbolic::pointer m_ptr;
290 : };
291 :
292 : } // namespace ana
293 :
294 : template <>
295 : template <>
296 : inline bool
297 9016 : is_a_helper <const pointer_svalue *>::test (const svalue *sval)
298 : {
299 9016 : return sval->get_kind () == SK_POINTER;
300 : }
301 :
302 : namespace ana {
303 :
304 : /* Concrete subclass of svalue representing a specific constant value.
305 : The type will either be the same as that of the underlying tree constant,
306 : or NULL_TREE indicating the constant is intended to be "typeless". */
307 :
308 : class constant_svalue : public svalue
309 : {
310 : public:
311 : /* A support class for uniquifying instances of constant_svalue. */
312 : struct key_t
313 : {
314 2670306 : key_t (tree type, tree cst)
315 2670306 : : m_type (type), m_cst (cst)
316 : {}
317 :
318 : bool
319 : operator< (const key_t &other) const;
320 : bool operator== (const key_t &other) const
321 : {
322 : return (m_type == other.m_type && m_cst == other.m_cst);
323 : }
324 :
325 : tree m_type;
326 : tree m_cst;
327 : };
328 :
329 1191110 : constant_svalue (symbolic::node::id_t id, tree type, tree cst_expr)
330 1191110 : : svalue (complexity (1, 1), id, type),
331 1191110 : m_cst_expr (cst_expr)
332 : {
333 1191110 : gcc_assert (cst_expr);
334 1191110 : gcc_assert (CONSTANT_CLASS_P (cst_expr));
335 1191110 : gcc_assert (type == TREE_TYPE (cst_expr) || type == NULL_TREE);
336 1191110 : }
337 :
338 6914760 : enum svalue_kind get_kind () const final override { return SK_CONSTANT; }
339 : const constant_svalue *
340 2899466 : dyn_cast_constant_svalue () const final override { return this; }
341 :
342 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
343 :
344 : void
345 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
346 :
347 : void
348 : accept_node_visitor (symbolic::node_visitor &v) const final override;
349 :
350 : std::unique_ptr<json::object>
351 : to_json () const final override;
352 :
353 : std::unique_ptr<diagnostics::markup::node>
354 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
355 :
356 : void accept (visitor *v) const final override;
357 : bool implicitly_live_p (symbolic::liveness_context &) const final override;
358 :
359 3531524 : tree get_constant () const { return m_cst_expr; }
360 : static tristate eval_condition (const constant_svalue *lhs,
361 : enum tree_code op,
362 : const constant_svalue *rhs);
363 :
364 : bool all_zeroes_p () const final override;
365 :
366 : bool maybe_get_value_range_1 (value_range &out) const final override;
367 :
368 : private:
369 : tree m_cst_expr;
370 : };
371 :
372 : } // namespace ana
373 :
374 : template <>
375 : template <>
376 : inline bool
377 675061 : is_a_helper <const constant_svalue *>::test (const svalue *sval)
378 : {
379 675061 : return sval->get_kind () == SK_CONSTANT;
380 : }
381 :
382 : namespace ana {
383 :
384 : /* Concrete subclass of svalue representing an unknowable value, the bottom
385 : value when thinking of svalues as a lattice.
386 : This is a singleton (w.r.t. its manager): there is a single unknown_svalue
387 : per type. Self-comparisons of such instances yield "unknown". */
388 :
389 : class unknown_svalue : public svalue
390 : {
391 : public:
392 8326 : unknown_svalue (symbolic::node::id_t id, tree type)
393 8326 : : svalue (complexity (1, 1), id, type)
394 : {}
395 :
396 587825 : enum svalue_kind get_kind () const final override { return SK_UNKNOWN; }
397 :
398 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
399 :
400 : void
401 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
402 :
403 : void
404 : accept_node_visitor (symbolic::node_visitor &v) const final override;
405 :
406 : std::unique_ptr<json::object>
407 : to_json () const final override;
408 :
409 : std::unique_ptr<diagnostics::markup::node>
410 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
411 :
412 : void accept (visitor *v) const final override;
413 :
414 : bool maybe_get_value_range_1 (value_range &out) const final override;
415 :
416 : /* Unknown values are singletons per-type, so can't have state. */
417 33182 : bool can_have_associated_state_p () const final override { return false; }
418 : };
419 :
420 : // TODO: can this be eliminated? (in favor of poisoned_bit_vector)
421 : /* Concrete subclass of svalue representing a value that should not
422 : be used (e.g. uninitialized memory, freed memory). */
423 :
424 : class poisoned_svalue : public svalue
425 : {
426 : public:
427 : /* A support class for uniquifying instances of poisoned_svalue. */
428 : struct key_t
429 : {
430 6 : key_t (enum poison_kind kind, tree type)
431 6 : : m_kind (kind), m_type (type)
432 : {}
433 :
434 : bool
435 10 : operator< (const key_t &other) const
436 : {
437 10 : if (m_kind < other.m_kind)
438 : return true;
439 10 : return cmp_types (m_type, other.m_type) < 0;
440 : }
441 :
442 : bool
443 : operator== (const key_t &other) const
444 : {
445 : return (m_kind == other.m_kind && m_type == other.m_type);
446 : }
447 :
448 : enum poison_kind m_kind;
449 : tree m_type;
450 : };
451 :
452 1 : poisoned_svalue (enum poison_kind kind, symbolic::node::id_t id, tree type)
453 1 : : svalue (complexity (1, 1), id, type), m_kind (kind) {}
454 :
455 0 : enum svalue_kind get_kind () const final override { return SK_POISONED; }
456 : const poisoned_svalue *
457 0 : dyn_cast_poisoned_svalue () const final override { return this; }
458 :
459 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
460 :
461 : void
462 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
463 :
464 : void
465 : accept_node_visitor (symbolic::node_visitor &v) const final override;
466 :
467 : std::unique_ptr<json::object>
468 : to_json () const final override;
469 :
470 : std::unique_ptr<diagnostics::markup::node>
471 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
472 :
473 : void accept (visitor *v) const final override;
474 :
475 0 : enum poison_kind get_poison_kind () const { return m_kind; }
476 :
477 : /* Poisoned svalues are singletons per-type, so can't have state. */
478 0 : bool can_have_associated_state_p () const final override { return false; }
479 :
480 : private:
481 : enum poison_kind m_kind;
482 : };
483 :
484 : } // namespace ana
485 :
486 : template <>
487 : template <>
488 : inline bool
489 0 : is_a_helper <const poisoned_svalue *>::test (const svalue *sval)
490 : {
491 0 : return sval->get_kind () == SK_POISONED;
492 : }
493 :
494 : namespace ana {
495 :
496 : /* A bundle of information recording a setjmp/sigsetjmp call, corresponding
497 : roughly to a jmp_buf. */
498 :
499 : struct setjmp_record
500 : {
501 34 : setjmp_record (const exploded_node *enode,
502 : const superedge *sedge,
503 : const gcall &setjmp_call)
504 34 : : m_enode (enode), m_sedge (sedge), m_setjmp_call (&setjmp_call)
505 : {
506 : }
507 :
508 : bool operator== (const setjmp_record &other) const
509 : {
510 : return (m_enode == other.m_enode
511 : && m_sedge == other.m_sedge
512 : && m_setjmp_call == other.m_setjmp_call);
513 : }
514 :
515 : static int cmp (const setjmp_record &rec1, const setjmp_record &rec2);
516 :
517 : const exploded_node *m_enode;
518 : const superedge *m_sedge;
519 : const gcall *m_setjmp_call;
520 : // non-null, but we can't use a reference since we're putting these in a std::map
521 : };
522 :
523 : /* Concrete subclass of svalue representing buffers for setjmp/sigsetjmp,
524 : so that longjmp/siglongjmp can potentially "return" to an entirely
525 : different function. */
526 :
527 : class setjmp_svalue : public svalue
528 : {
529 : public:
530 : /* A support class for uniquifying instances of poisoned_svalue. */
531 : struct key_t
532 : {
533 34 : key_t (const setjmp_record &record, tree type)
534 34 : : m_record (record), m_type (type)
535 : {}
536 :
537 : bool operator< (const key_t &other) const;
538 : bool operator== (const key_t &other) const
539 : {
540 : return (m_record == other.m_record && m_type == other.m_type);
541 : }
542 :
543 : setjmp_record m_record;
544 : tree m_type;
545 : };
546 :
547 34 : setjmp_svalue (const setjmp_record &setjmp_record,
548 : symbolic::node::id_t id,
549 : tree type)
550 34 : : svalue (complexity (1, 1), id, type), m_setjmp_record (setjmp_record)
551 : {}
552 :
553 2583 : enum svalue_kind get_kind () const final override { return SK_SETJMP; }
554 : const setjmp_svalue *
555 25 : dyn_cast_setjmp_svalue () const final override { return this; }
556 :
557 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
558 :
559 : void
560 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
561 : void
562 : add_dump_widget_children (text_art::tree_widget &w,
563 : symbolic::node_dump_state &nds) const final override;
564 : void
565 : accept_node_visitor (symbolic::node_visitor &v) const final override;
566 :
567 : std::unique_ptr<json::object>
568 : to_json () const final override;
569 :
570 : std::unique_ptr<diagnostics::markup::node>
571 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
572 :
573 : void accept (visitor *v) const final override;
574 :
575 : int get_enode_index () const;
576 :
577 : const setjmp_record &get_setjmp_record () const { return m_setjmp_record; }
578 :
579 : private:
580 : setjmp_record m_setjmp_record;
581 : };
582 :
583 : } // namespace ana
584 :
585 : template <>
586 : template <>
587 : inline bool
588 : is_a_helper <const setjmp_svalue *>::test (const svalue *sval)
589 : {
590 : return sval->get_kind () == SK_SETJMP;
591 : }
592 :
593 : namespace ana {
594 :
595 : /* Concrete subclass of svalue representing the initial value of a
596 : specific base region.
597 :
598 : This represents the initial value at the start of the analysis path,
599 : as opposed to the first time the region is accessed during the path.
600 : Hence as soon as we have a call to an unknown function, all previously
601 : unmodelled globals become implicitly "unknown" rathen than "initial".
602 :
603 : Consolidation/canonicalization:
604 : - the region must be a "base region". */
605 :
606 : class initial_svalue : public svalue
607 : {
608 : public:
609 : initial_svalue (symbolic::node::id_t id, tree type, const region *reg);
610 :
611 5395932 : enum svalue_kind get_kind () const final override { return SK_INITIAL; }
612 : const initial_svalue *
613 248158 : dyn_cast_initial_svalue () const final override { return this; }
614 :
615 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
616 :
617 : void
618 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
619 : void
620 : add_dump_widget_children (text_art::tree_widget &w,
621 : symbolic::node_dump_state &nds) const final override;
622 : void
623 : accept_node_visitor (symbolic::node_visitor &v) const final override;
624 :
625 : std::unique_ptr<json::object>
626 : to_json () const final override;
627 :
628 : std::unique_ptr<diagnostics::markup::node>
629 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
630 :
631 : void accept (visitor *v) const final override;
632 : bool implicitly_live_p (symbolic::liveness_context &) const final override;
633 :
634 : bool initial_value_of_param_p () const;
635 :
636 1106632 : const region *get_region () const { return m_reg; }
637 :
638 : private:
639 : const region *m_reg;
640 : };
641 :
642 : } // namespace ana
643 :
644 : template <>
645 : template <>
646 : inline bool
647 897970 : is_a_helper <const initial_svalue *>::test (const svalue *sval)
648 : {
649 897970 : return sval->get_kind () == SK_INITIAL;
650 : }
651 :
652 : namespace ana {
653 :
654 : /* Concrete subclass of svalue representing a unary operation on
655 : another svalues (e.g. a cast).
656 :
657 : Consolidation/canonicalization:
658 : - arg->can_have_associated_state_p () must be true. In particular,
659 : the arg cannot be SK_UNKNOWN (this will get folded to unknown). */
660 :
661 : class unaryop_svalue : public svalue
662 : {
663 : public:
664 : /* A support class for uniquifying instances of unaryop_svalue. */
665 : struct key_t
666 : {
667 152492 : key_t (tree type, enum tree_code op, const svalue *arg)
668 152492 : : m_type (type), m_op (op), m_arg (arg)
669 : {}
670 :
671 : bool operator< (const key_t &other) const;
672 : bool operator== (const key_t &other) const
673 : {
674 : return (m_type == other.m_type
675 : && m_op == other.m_op
676 : && m_arg == other.m_arg);
677 : }
678 :
679 : tree m_type;
680 : enum tree_code m_op;
681 : const svalue *m_arg;
682 : };
683 :
684 9193 : unaryop_svalue (symbolic::node::id_t id, tree type, enum tree_code op,
685 : const svalue *arg)
686 9193 : : svalue (complexity (arg), id, type), m_op (op), m_arg (arg)
687 : {
688 9193 : gcc_assert (arg->can_have_associated_state_p ());
689 9193 : }
690 :
691 2505406 : enum svalue_kind get_kind () const final override { return SK_UNARYOP; }
692 : const unaryop_svalue *
693 2053786 : dyn_cast_unaryop_svalue () const final override { return this; }
694 :
695 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
696 :
697 : void
698 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
699 : void
700 : add_dump_widget_children (text_art::tree_widget &w,
701 : symbolic::node_dump_state &nds) const final override;
702 : void
703 : accept_node_visitor (symbolic::node_visitor &v) const final override;
704 :
705 : std::unique_ptr<json::object>
706 : to_json () const final override;
707 :
708 : std::unique_ptr<diagnostics::markup::node>
709 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
710 :
711 : void accept (visitor *v) const final override;
712 : bool implicitly_live_p (symbolic::liveness_context &) const final override;
713 :
714 4279064 : enum tree_code get_op () const { return m_op; }
715 2331999 : const svalue *get_arg () const { return m_arg; }
716 :
717 : bool maybe_get_value_range_1 (value_range &out) const final override;
718 :
719 : private:
720 : enum tree_code m_op;
721 : const svalue *m_arg;
722 : };
723 :
724 : } // namespace ana
725 :
726 : template <>
727 : template <>
728 : inline bool
729 461133 : is_a_helper <const unaryop_svalue *>::test (const svalue *sval)
730 : {
731 461133 : return sval->get_kind () == SK_UNARYOP;
732 : }
733 :
734 : namespace ana {
735 :
736 : /* Concrete subclass of svalue representing a binary operation of
737 : two svalues.
738 :
739 : Consolidation/canonicalization:
740 : - can_have_associated_state_p () must be true for both arguments.
741 : In particular, they cannot be SK_UNKNOWN (this will get folded
742 : to unknown). */
743 :
744 : class binop_svalue : public svalue
745 : {
746 : public:
747 : /* A support class for uniquifying instances of binop_svalue. */
748 : struct key_t
749 : {
750 50502 : key_t (tree type, enum tree_code op,
751 : const svalue *arg0, const svalue *arg1)
752 50502 : : m_type (type), m_op (op), m_arg0 (arg0), m_arg1 (arg1)
753 : {}
754 :
755 : bool operator< (const key_t &other) const;
756 : bool operator== (const key_t &other) const
757 : {
758 : return (m_type == other.m_type
759 : && m_op == other.m_op
760 : && m_arg0 == other.m_arg0
761 : && m_arg1 == other.m_arg1);
762 : }
763 :
764 : tree m_type;
765 : enum tree_code m_op;
766 : const svalue *m_arg0;
767 : const svalue *m_arg1;
768 : };
769 :
770 14061 : binop_svalue (symbolic::node::id_t id, tree type, enum tree_code op,
771 : const svalue *arg0, const svalue *arg1)
772 : : svalue (complexity::from_pair (arg0->get_complexity (),
773 : arg1->get_complexity ()),
774 : id,
775 : type),
776 14061 : m_op (op), m_arg0 (arg0), m_arg1 (arg1)
777 : {
778 14061 : gcc_assert (arg0->can_have_associated_state_p ());
779 14061 : gcc_assert (arg1->can_have_associated_state_p ());
780 14061 : }
781 :
782 4012940 : enum svalue_kind get_kind () const final override { return SK_BINOP; }
783 79888 : const binop_svalue *dyn_cast_binop_svalue () const final override
784 : {
785 79888 : return this;
786 : }
787 :
788 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
789 :
790 : void
791 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
792 : void
793 : add_dump_widget_children (text_art::tree_widget &w,
794 : symbolic::node_dump_state &nds) const final override;
795 : void
796 : accept_node_visitor (symbolic::node_visitor &v) const final override;
797 :
798 : std::unique_ptr<json::object>
799 : to_json () const final override;
800 :
801 : std::unique_ptr<diagnostics::markup::node>
802 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
803 :
804 : void accept (visitor *v) const final override;
805 : bool implicitly_live_p (symbolic::liveness_context &) const final override;
806 :
807 : bool maybe_get_value_range_1 (value_range &out) const final override;
808 :
809 3434264 : enum tree_code get_op () const { return m_op; }
810 691993 : const svalue *get_arg0 () const { return m_arg0; }
811 678404 : const svalue *get_arg1 () const { return m_arg1; }
812 :
813 : private:
814 : enum tree_code m_op;
815 : const svalue *m_arg0;
816 : const svalue *m_arg1;
817 : };
818 :
819 : } // namespace ana
820 :
821 : template <>
822 : template <>
823 : inline bool
824 211437 : is_a_helper <const binop_svalue *>::test (const svalue *sval)
825 : {
826 211437 : return sval->get_kind () == SK_BINOP;
827 : }
828 :
829 : namespace ana {
830 :
831 : /* Concrete svalue subclass: interpreting a collection of bits as a
832 : symbolic value of a particular type.
833 :
834 : Consolidation/canonicalization:
835 : - all qualifiers (except address spaces) are stripped from the type
836 : of the pointee
837 : - no nesting: the underlying bit vector can't be a bit_vector_from_svalue
838 : (we fold away such cases).
839 : - for integral types, the underlying bit_vector must not be a
840 : tristate_bit_vector of kind "true" or "false" (but could be "unknown"):
841 : all-zeros/all-ones get folded to constant_svalue. */
842 :
843 : class svalue_from_bit_vector : public svalue
844 : {
845 : public:
846 : struct key_t
847 : {
848 978222 : key_t (tree type,
849 : const symbolic::bit_vector *bv)
850 978222 : : m_type (type),
851 978222 : m_bv (bv)
852 : {
853 : }
854 :
855 : bool operator< (const key_t &other) const;
856 : bool operator== (const key_t &other) const
857 : {
858 : return (m_type == other.m_type
859 : && m_bv == other.m_bv);
860 : }
861 :
862 : /* Use m_bv to mark empty/deleted. */
863 : void mark_deleted () { m_bv = reinterpret_cast<const symbolic::bit_vector *> (1); }
864 : void mark_empty () { m_bv = nullptr; }
865 : bool is_deleted () const
866 : {
867 : return m_bv == reinterpret_cast<const symbolic::bit_vector *> (1);
868 : }
869 : bool is_empty () const { return m_bv == nullptr; }
870 :
871 : tree m_type;
872 : const symbolic::bit_vector *m_bv;
873 : };
874 :
875 : svalue_from_bit_vector (symbolic::node::id_t id,
876 : tree type,
877 : const symbolic::bit_vector &bv);
878 :
879 2438000 : enum svalue_kind get_kind () const final override
880 : {
881 2438000 : return SK_BIT_VECTOR;
882 : }
883 : const svalue_from_bit_vector *
884 2400678 : dyn_cast_svalue_from_bit_vector () const final override
885 : {
886 2400678 : return this;
887 : }
888 :
889 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
890 :
891 : void
892 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
893 : void
894 : add_dump_widget_children (text_art::tree_widget &w,
895 : symbolic::node_dump_state &nds) const final override;
896 : void
897 : accept_node_visitor (symbolic::node_visitor &v) const final override;
898 :
899 : std::unique_ptr<json::object>
900 : to_json () const final override;
901 :
902 : std::unique_ptr<diagnostics::markup::node>
903 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
904 :
905 : void accept (visitor *v) const final override;
906 :
907 2506450 : const symbolic::bit_vector &get_bit_vector () const { return m_bv; }
908 :
909 : bool all_zeroes_p () const final override;
910 :
911 : bool implicitly_live_p (symbolic::liveness_context &) const final override;
912 :
913 : bool
914 : maybe_get_value_range_1 (value_range &out) const final override;
915 :
916 : bool
917 : conjured_p () const final override;
918 :
919 : private:
920 : const symbolic::bit_vector &m_bv;
921 : };
922 :
923 : } // namespace ana
924 :
925 : template <>
926 : template <>
927 : inline bool
928 81728 : is_a_helper <const svalue_from_bit_vector *>::test (const svalue *sval)
929 : {
930 81728 : return sval->get_kind () == SK_BIT_VECTOR;
931 : }
932 :
933 : namespace ana {
934 :
935 : /* Concrete subclass of svalue: decorate another svalue,
936 : so that the resulting svalue can be identified as being
937 : "interesting to control flow".
938 : For example, consider the return value from setjmp. We
939 : don't want to merge states in which the result is 0 with
940 : those in which the result is non-zero. By using an
941 : unmergeable_svalue for the result, we can inhibit such merges
942 : and have separate exploded nodes for those states, keeping
943 : the first and second returns from setjmp distinct in the exploded
944 : graph.
945 :
946 : Consolidation/canonicalization:
947 : - no nesting: the underlying arg is not itself unmergeable (we fold
948 : away nesting). */
949 :
950 : class unmergeable_svalue : public svalue
951 : {
952 : public:
953 305 : unmergeable_svalue (symbolic::node::id_t id, const svalue *arg)
954 305 : : svalue (complexity (arg), id, arg->get_type ()), m_arg (arg)
955 : {
956 305 : }
957 :
958 56531 : enum svalue_kind get_kind () const final override { return SK_UNMERGEABLE; }
959 : const unmergeable_svalue *
960 13589 : dyn_cast_unmergeable_svalue () const final override { return this; }
961 :
962 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
963 :
964 : void
965 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
966 : void
967 : add_dump_widget_children (text_art::tree_widget &w,
968 : symbolic::node_dump_state &nds) const final override;
969 : void
970 : accept_node_visitor (symbolic::node_visitor &v) const final override;
971 :
972 : std::unique_ptr<json::object>
973 : to_json () const final override;
974 :
975 : std::unique_ptr<diagnostics::markup::node>
976 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
977 :
978 : void accept (visitor *v) const final override;
979 : bool implicitly_live_p (symbolic::liveness_context &) const final override;
980 :
981 14399 : const svalue *get_arg () const { return m_arg; }
982 :
983 : private:
984 : const svalue *m_arg;
985 : };
986 :
987 : } // namespace ana
988 :
989 : template <>
990 : template <>
991 : inline bool
992 0 : is_a_helper <const unmergeable_svalue *>::test (const svalue *sval)
993 : {
994 0 : return sval->get_kind () == SK_UNMERGEABLE;
995 : }
996 :
997 : namespace ana {
998 :
999 : /* Concrete subclass of svalue for use in selftests, where
1000 : we want a specific but unknown svalue.
1001 : Unlike other svalue subclasses these aren't managed by
1002 : region_model_manager. */
1003 :
1004 76 : class placeholder_svalue : public svalue
1005 : {
1006 : public:
1007 5671 : placeholder_svalue (symbolic::node::id_t id, tree type, const char *name)
1008 5671 : : svalue (complexity (1, 1), id, type), m_name (name)
1009 : {
1010 : }
1011 :
1012 18703 : enum svalue_kind get_kind () const final override { return SK_PLACEHOLDER; }
1013 :
1014 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
1015 :
1016 : void
1017 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
1018 :
1019 : void
1020 : accept_node_visitor (symbolic::node_visitor &v) const final override;
1021 :
1022 : std::unique_ptr<json::object>
1023 : to_json () const final override;
1024 :
1025 : std::unique_ptr<diagnostics::markup::node>
1026 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
1027 :
1028 : void accept (visitor *v) const final override;
1029 :
1030 : const char *get_name () const { return m_name; }
1031 :
1032 : private:
1033 : const char *m_name;
1034 : };
1035 :
1036 : } // namespace ana
1037 :
1038 : template <>
1039 : template <>
1040 : inline bool
1041 : is_a_helper <const placeholder_svalue *>::test (const svalue *sval)
1042 : {
1043 : return sval->get_kind () == SK_PLACEHOLDER;
1044 : }
1045 :
1046 : namespace ana {
1047 :
1048 : /* Concrete subclass of svalue representing a "widening" seen when merging
1049 : states, widening from a base value to {base value, iter value} and thus
1050 : representing a possible fixed point in an iteration from the base to
1051 : +ve infinity, or -ve infinity, and thus useful for representing a value
1052 : within a loop.
1053 : TODO: We also need to capture the program_point at which the merger happens,
1054 : so that distinguish between different iterators, and thus handle
1055 : nested loops. (currently we capture the function_point instead, for
1056 : redundant historical reasons).
1057 :
1058 : Consolidation/canonicalization:
1059 : - the underlying args must not themselves be SK_WIDENING. */
1060 :
1061 : class widening_svalue : public svalue
1062 : {
1063 : public:
1064 : /* A support class for uniquifying instances of widening_svalue. */
1065 : struct key_t
1066 : {
1067 2849 : key_t (tree type, const supernode *snode,
1068 : const svalue *base_sval, const svalue *iter_sval)
1069 2849 : : m_type (type), m_snode (snode),
1070 2849 : m_base_sval (base_sval), m_iter_sval (iter_sval)
1071 : {}
1072 :
1073 : bool operator< (const key_t &other) const;
1074 : bool operator== (const key_t &other) const
1075 : {
1076 : return (m_type == other.m_type
1077 : && m_snode == other.m_snode
1078 : && m_base_sval == other.m_base_sval
1079 : && m_iter_sval == other.m_iter_sval);
1080 : }
1081 :
1082 : tree m_type;
1083 : const supernode *m_snode;
1084 : const svalue *m_base_sval;
1085 : const svalue *m_iter_sval;
1086 : };
1087 :
1088 : enum direction_t
1089 : {
1090 : DIR_ASCENDING,
1091 : DIR_DESCENDING,
1092 : DIR_UNKNOWN
1093 : };
1094 :
1095 1693 : widening_svalue (symbolic::node::id_t id, tree type, const supernode *snode,
1096 : const svalue *base_sval, const svalue *iter_sval)
1097 : : svalue (complexity::from_pair (base_sval->get_complexity (),
1098 : iter_sval->get_complexity ()),
1099 : id,
1100 : type),
1101 1693 : m_snode (snode),
1102 1693 : m_base_sval (base_sval), m_iter_sval (iter_sval)
1103 : {
1104 1693 : gcc_assert (base_sval->can_have_associated_state_p ());
1105 1693 : gcc_assert (iter_sval->can_have_associated_state_p ());
1106 1693 : }
1107 :
1108 713152 : enum svalue_kind get_kind () const final override { return SK_WIDENING; }
1109 18197 : const widening_svalue *dyn_cast_widening_svalue () const final override
1110 : {
1111 18197 : return this;
1112 : }
1113 :
1114 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
1115 :
1116 : void
1117 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
1118 : void
1119 : add_dump_widget_children (text_art::tree_widget &w,
1120 : symbolic::node_dump_state &nds) const final override;
1121 : void
1122 : accept_node_visitor (symbolic::node_visitor &v) const final override;
1123 :
1124 : std::unique_ptr<json::object>
1125 : to_json () const final override;
1126 :
1127 : std::unique_ptr<diagnostics::markup::node>
1128 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
1129 :
1130 : void accept (visitor *v) const final override;
1131 :
1132 114 : const supernode *get_snode () const { return m_snode; }
1133 9283 : const svalue *get_base_svalue () const { return m_base_sval; }
1134 2919 : const svalue *get_iter_svalue () const { return m_iter_sval; }
1135 :
1136 : enum direction_t get_direction () const;
1137 :
1138 : tristate eval_condition_without_cm (enum tree_code op,
1139 : tree rhs_cst) const;
1140 :
1141 : private:
1142 : const supernode *m_snode;
1143 : const svalue *m_base_sval;
1144 : const svalue *m_iter_sval;
1145 : };
1146 :
1147 : } // namespace ana
1148 :
1149 : template <>
1150 : template <>
1151 : inline bool
1152 114 : is_a_helper <const widening_svalue *>::test (const svalue *sval)
1153 : {
1154 114 : return sval->get_kind () == SK_WIDENING;
1155 : }
1156 :
1157 : namespace ana {
1158 :
1159 : /* An output from a deterministic asm stmt, where we want to identify a
1160 : particular unknown value, rather than resorting to the unknown_value
1161 : singleton.
1162 :
1163 : Comparisons of variables that share the same asm_output_svalue are known
1164 : to be equal, even if we don't know what the value is.
1165 :
1166 : Consolidation/canonicalization:
1167 : - none of the inputs may be unknown (we fold away such cases). */
1168 :
1169 : class asm_output_svalue : public svalue
1170 : {
1171 : public:
1172 : /* Imposing an upper limit and using a (small) array allows key_t
1173 : to avoid memory management. */
1174 : static const unsigned MAX_INPUTS = 2;
1175 :
1176 : /* A support class for uniquifying instances of asm_output_svalue. */
1177 : struct key_t
1178 : {
1179 289 : key_t (tree type,
1180 : const char *asm_string,
1181 : unsigned output_idx,
1182 : const vec<const svalue *> &inputs)
1183 289 : : m_type (type), m_asm_string (asm_string), m_output_idx (output_idx),
1184 289 : m_num_inputs (inputs.length ())
1185 : {
1186 289 : gcc_assert (inputs.length () <= MAX_INPUTS);
1187 750 : for (unsigned i = 0; i < m_num_inputs; i++)
1188 461 : m_input_arr[i] = inputs[i];
1189 289 : }
1190 :
1191 : bool operator< (const key_t &other) const;
1192 : bool operator== (const key_t &other) const
1193 : {
1194 : if (!(m_type == other.m_type
1195 : && 0 == (strcmp (m_asm_string, other.m_asm_string))
1196 : && m_output_idx == other.m_output_idx
1197 : && m_num_inputs == other.m_num_inputs))
1198 : return false;
1199 : for (unsigned i = 0; i < m_num_inputs; i++)
1200 : if (m_input_arr[i] != other.m_input_arr[i])
1201 : return false;
1202 : return true;
1203 : }
1204 :
1205 : tree m_type;
1206 : const char *m_asm_string;
1207 : unsigned m_output_idx;
1208 : unsigned m_num_inputs;
1209 : const svalue *m_input_arr[MAX_INPUTS];
1210 : };
1211 :
1212 173 : asm_output_svalue (symbolic::node::id_t id,
1213 : tree type,
1214 : const char *asm_string,
1215 : unsigned output_idx,
1216 : unsigned num_outputs,
1217 : const vec<const svalue *> &inputs)
1218 : : svalue (complexity::from_vec_svalue (inputs), id, type),
1219 173 : m_asm_string (asm_string),
1220 173 : m_output_idx (output_idx),
1221 173 : m_num_outputs (num_outputs),
1222 173 : m_num_inputs (inputs.length ())
1223 : {
1224 173 : gcc_assert (inputs.length () <= MAX_INPUTS);
1225 430 : for (unsigned i = 0; i < m_num_inputs; i++)
1226 257 : m_input_arr[i] = inputs[i];
1227 173 : }
1228 :
1229 23336 : enum svalue_kind get_kind () const final override { return SK_ASM_OUTPUT; }
1230 : const asm_output_svalue *
1231 0 : dyn_cast_asm_output_svalue () const final override
1232 : {
1233 0 : return this;
1234 : }
1235 :
1236 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
1237 :
1238 : void
1239 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
1240 : void
1241 : add_dump_widget_children (text_art::tree_widget &w,
1242 : symbolic::node_dump_state &nds) const final override;
1243 : void
1244 : accept_node_visitor (symbolic::node_visitor &v) const final override;
1245 :
1246 : std::unique_ptr<json::object>
1247 : to_json () const final override;
1248 :
1249 : std::unique_ptr<diagnostics::markup::node>
1250 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
1251 :
1252 : void accept (visitor *v) const final override;
1253 :
1254 8 : const char *get_asm_string () const { return m_asm_string; }
1255 14 : unsigned get_output_idx () const { return m_output_idx; }
1256 8 : unsigned get_num_outputs () const { return m_num_outputs; }
1257 8 : unsigned get_num_inputs () const { return m_num_inputs; }
1258 0 : const svalue *get_input (unsigned idx) const { return m_input_arr[idx]; }
1259 :
1260 : private:
1261 : void dump_input (pretty_printer *pp,
1262 : unsigned input_idx,
1263 : const svalue *sval,
1264 : bool simple) const;
1265 : unsigned input_idx_to_asm_idx (unsigned input_idx) const;
1266 :
1267 : const char *m_asm_string;
1268 : unsigned m_output_idx;
1269 :
1270 : /* We capture this so that we can offset the input indices
1271 : to match the %0, %1, %2 in the asm_string when dumping. */
1272 : unsigned m_num_outputs;
1273 :
1274 : unsigned m_num_inputs;
1275 : const svalue *m_input_arr[MAX_INPUTS];
1276 : };
1277 :
1278 : } // namespace ana
1279 :
1280 : template <>
1281 : template <>
1282 : inline bool
1283 8 : is_a_helper <const asm_output_svalue *>::test (const svalue *sval)
1284 : {
1285 8 : return sval->get_kind () == SK_ASM_OUTPUT;
1286 : }
1287 :
1288 : namespace ana {
1289 :
1290 : /* The return value from a function with __attribute((const)) for given
1291 : inputs, provided that we don't have too many inputs, and all of them
1292 : are deterministic.
1293 :
1294 : Comparisons of variables that share the same const_fn_result_svalue are known
1295 : to be equal, even if we don't know what the value is.
1296 :
1297 : Consolidation/canonicalization:
1298 : - TODO. */
1299 :
1300 : class const_fn_result_svalue : public svalue
1301 : {
1302 : public:
1303 : /* Imposing an upper limit and using a (small) array allows key_t
1304 : to avoid memory management. */
1305 : static const unsigned MAX_INPUTS = 2;
1306 :
1307 : /* A support class for uniquifying instances of const_fn_result_svalue. */
1308 : struct key_t
1309 : {
1310 639 : key_t (tree type,
1311 : tree fndecl,
1312 : const vec<const svalue *> &inputs)
1313 639 : : m_type (type), m_fndecl (fndecl),
1314 639 : m_num_inputs (inputs.length ())
1315 : {
1316 639 : gcc_assert (inputs.length () <= MAX_INPUTS);
1317 1198 : for (unsigned i = 0; i < m_num_inputs; i++)
1318 559 : m_input_arr[i] = inputs[i];
1319 639 : }
1320 :
1321 : bool operator< (const key_t &other) const;
1322 : bool operator== (const key_t &other) const
1323 : {
1324 : if (!(m_type == other.m_type
1325 : && m_fndecl == other.m_fndecl
1326 : && m_num_inputs == other.m_num_inputs))
1327 : return false;
1328 : for (unsigned i = 0; i < m_num_inputs; i++)
1329 : if (m_input_arr[i] != other.m_input_arr[i])
1330 : return false;
1331 : return true;
1332 : }
1333 :
1334 : tree m_type;
1335 : tree m_fndecl;
1336 : unsigned m_num_inputs;
1337 : const svalue *m_input_arr[MAX_INPUTS];
1338 : };
1339 :
1340 152 : const_fn_result_svalue (symbolic::node::id_t id,
1341 : tree type,
1342 : tree fndecl,
1343 : const vec<const svalue *> &inputs)
1344 : : svalue (complexity::from_vec_svalue (inputs), id, type),
1345 152 : m_fndecl (fndecl),
1346 152 : m_num_inputs (inputs.length ())
1347 : {
1348 152 : gcc_assert (inputs.length () <= MAX_INPUTS);
1349 305 : for (unsigned i = 0; i < m_num_inputs; i++)
1350 153 : m_input_arr[i] = inputs[i];
1351 152 : }
1352 :
1353 39348 : enum svalue_kind get_kind () const final override
1354 : {
1355 39348 : return SK_CONST_FN_RESULT;
1356 : }
1357 : const const_fn_result_svalue *
1358 0 : dyn_cast_const_fn_result_svalue () const final override
1359 : {
1360 0 : return this;
1361 : }
1362 :
1363 : void dump_to_pp (pretty_printer *pp, bool simple) const final override;
1364 :
1365 : void
1366 : print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
1367 : void
1368 : add_dump_widget_children (text_art::tree_widget &w,
1369 : symbolic::node_dump_state &nds) const final override;
1370 : void
1371 : accept_node_visitor (symbolic::node_visitor &v) const final override;
1372 :
1373 : std::unique_ptr<json::object>
1374 : to_json () const final override;
1375 :
1376 : std::unique_ptr<diagnostics::markup::node>
1377 : make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
1378 :
1379 : void accept (visitor *v) const final override;
1380 :
1381 2 : tree get_fndecl () const { return m_fndecl; }
1382 2 : unsigned get_num_inputs () const { return m_num_inputs; }
1383 2 : const svalue *get_input (unsigned idx) const { return m_input_arr[idx]; }
1384 :
1385 : private:
1386 : void dump_input (pretty_printer *pp,
1387 : unsigned input_idx,
1388 : const svalue *sval,
1389 : bool simple) const;
1390 :
1391 : tree m_fndecl;
1392 : unsigned m_num_inputs;
1393 : const svalue *m_input_arr[MAX_INPUTS];
1394 : };
1395 :
1396 : } // namespace ana
1397 :
1398 : template <>
1399 : template <>
1400 : inline bool
1401 2 : is_a_helper <const const_fn_result_svalue *>::test (const svalue *sval)
1402 : {
1403 2 : return sval->get_kind () == SK_CONST_FN_RESULT;
1404 : }
1405 :
1406 : #endif /* GCC_ANALYZER_SVALUE_H */
|