CBMC
Loading...
Searching...
No Matches
goto_symex_state.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Symbolic Execution
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#include "goto_symex_state.h"
13
14#include <util/as_const.h>
15#include <util/base_exceptions.h> // IWYU pragma: keep
16#include <util/byte_operators.h>
17#include <util/c_types.h>
19#include <util/expr_util.h>
20#include <util/invariant.h>
21#include <util/std_expr.h>
22
23#include <analyses/dirty.h>
25
29
33 bool should_simplify,
34 const irep_idt &language_mode,
35 guard_managert &manager,
36 std::function<std::size_t(const irep_idt &)> fresh_l2_name_provider)
37 : goto_statet(manager),
38 source(_source),
39 guard_manager(manager),
40 symex_target(nullptr),
41 field_sensitivity(
43 should_simplify,
44 language_mode),
45 record_events({true}),
46 language_mode(language_mode),
47 fresh_l2_name_provider(fresh_l2_name_provider)
48{
49 threads.emplace_back(guard_manager);
50 call_stack().new_frame(source, guardt(true_exprt(), manager));
51}
52
54
55template <>
57goto_symex_statet::set_indices<L0>(ssa_exprt ssa_expr, const namespacet &ns)
58{
59 return symex_level0(std::move(ssa_expr), ns, source.thread_nr);
60}
61
62template <>
64goto_symex_statet::set_indices<L1>(ssa_exprt ssa_expr, const namespacet &ns)
65{
66 return level1(symex_level0(std::move(ssa_expr), ns, source.thread_nr));
67}
68
69template <>
71goto_symex_statet::set_indices<L2>(ssa_exprt ssa_expr, const namespacet &ns)
72{
73 return level2(
74 level1(symex_level0(std::move(ssa_expr), ns, source.thread_nr)));
75}
76
78 ssa_exprt lhs, // L0/L1
79 const exprt &rhs, // L2
80 const namespacet &ns,
82 bool record_value,
83 bool allow_pointer_unsoundness)
84{
85 // identifier should be l0 or l1, make sure it's l1
86 lhs = rename_ssa<L1>(std::move(lhs), ns).get();
88
89 // the type might need renaming
90 rename<L2>(lhs.type(), l1_identifier, ns);
93 lhs.update_type();
95 {
96 DATA_INVARIANT(!check_renaming_l1(lhs), "lhs renaming failed on l1");
97 }
98
99 // do the l2 renaming
101 renamedt<ssa_exprt, L2> l2_lhs = set_indices<L2>(std::move(lhs), ns);
102 lhs = l2_lhs.get();
103
104 // in case we happen to be multi-threaded, record the memory access
106
108 {
109 DATA_INVARIANT(!check_renaming(lhs), "lhs renaming failed on l2");
110 DATA_INVARIANT(!check_renaming(rhs), "rhs renaming failed on l2");
111 }
112
113 // see #305 on GitHub for a simple example and possible discussion
114 if(is_shared && lhs.type().id() == ID_pointer && !allow_pointer_unsoundness)
116 "pointer handling for concurrency is unsound");
117
118 // Update constant propagation map -- the RHS is L2
120 {
122 if(!propagation_entry.has_value())
123 propagation.insert(l1_identifier, rhs);
124 else if(propagation_entry->get() != rhs)
125 propagation.replace(l1_identifier, rhs);
126 }
127 else
128 propagation.erase_if_exists(l1_identifier);
129
131
132#ifdef DEBUG
133 std::cout << "Assigning " << l1_identifier << '\n';
134 value_set.output(std::cout);
135 std::cout << "**********************\n";
136#endif
137
138 return l2_lhs;
139}
140
141template <levelt level>
144{
145 static_assert(
146 level == L0 || level == L1,
147 "rename_ssa can only be used for levels L0 and L1");
148 ssa = set_indices<level>(std::move(ssa), ns).get();
149 rename<level>(ssa.type(), ssa.get_identifier(), ns);
150 ssa.update_type();
152}
153
156goto_symex_statet::rename_ssa<L0>(ssa_exprt ssa, const namespacet &ns);
158goto_symex_statet::rename_ssa<L1>(ssa_exprt ssa, const namespacet &ns);
159
160template <levelt level>
163{
164 // rename all the symbols with their last known value
165
166 static_assert(
167 level == L0 || level == L1 || level == L1_WITH_CONSTANT_PROPAGATION ||
168 level == L2,
169 "must handle all renaming levels");
170
171 if(is_ssa_expr(expr))
172 {
173 exprt original_expr = expr;
175
176 if(level == L0)
177 {
179 std::move(rename_ssa<L0>(std::move(ssa), ns).value())};
180 }
181 else if(level == L1)
182 {
184 std::move(rename_ssa<L1>(std::move(ssa), ns).value())};
185 }
186 else
187 {
188 ssa = set_indices<L1>(std::move(ssa), ns).get();
189 rename<level>(expr.type(), ssa.get_identifier(), ns);
190 ssa.update_type();
191
192 // renaming taken care of by l2_thread_encoding, or already at L2
193 if(l2_thread_read_encoding(ssa, ns) || !ssa.get_level_2().empty())
194 {
196 {
197 // Don't actually rename to L2 -- we just used `ssa` to check whether
198 // constant-propagation was applicable
199 return renamedt<exprt, level>(std::move(original_expr));
200 }
201 else
202 return renamedt<exprt, level>(std::move(ssa));
203 }
204 else
205 {
206 // We also consider propagation if we go up to L2.
207 // L1 identifiers are used for propagation!
208 auto p_it = propagation.find(ssa.get_identifier());
209
210 if(p_it.has_value())
211 {
212 return renamedt<exprt, level>(*p_it); // already L2
213 }
214 else
215 {
216 if(level == L2)
217 ssa = set_indices<L2>(std::move(ssa), ns).get();
218 return renamedt<exprt, level>(std::move(ssa));
219 }
220 }
221 }
222 }
223 else if(expr.id()==ID_symbol)
224 {
225 const auto &type = as_const(expr).type();
226
227 // we never rename function symbols
228 if(type.id() == ID_code || type.id() == ID_mathematical_function)
229 {
230 rename<level>(expr.type(), to_symbol_expr(expr).get_identifier(), ns);
231 return renamedt<exprt, level>{std::move(expr)};
232 }
233 else
234 return rename<level>(ssa_exprt{expr}, ns);
235 }
236 else if(expr.id()==ID_address_of)
237 {
240 to_pointer_type(expr.type()).base_type() =
241 as_const(address_of_expr).object().type();
242 return renamedt<exprt, level>{std::move(expr)};
243 }
244 else if(expr.is_nil())
245 {
246 return renamedt<exprt, level>{std::move(expr)};
247 }
248 else
249 {
250 rename<level>(expr.type(), irep_idt(), ns);
251
252 // do this recursively
253 Forall_operands(it, expr)
254 *it = rename<level>(std::move(*it), ns).get();
255
256 const exprt &c_expr = as_const(expr);
257
258 // It may happen that the `old` subexpression of a `with_exprt` expression
259 // is propagated with a value that has an array type with a size that is a
260 // symbol with an L2 index that is different. In this case the type of the
261 // `with_exprt` will not match with the type of the `old` subexpression
262 // anymore.
263 // To address this issue we re-canonicalize the `with_exprt` by propagating
264 // the type of the `old` subexpression to the type of the `with_exprt`.
266 if(
269 c_with_expr->type() != c_with_expr->old().type())
270 {
271 expr.type() = to_with_expr(expr).old().type();
272 }
274 expr.id() != ID_with ||
275 c_expr.type() == to_with_expr(c_expr).old().type(),
276 "Type of renamed expr should be the same as operands for with_exprt",
277 c_expr.type().pretty(),
278 to_with_expr(c_expr).old().type().pretty());
280 expr.id() != ID_if ||
281 c_expr.type() == to_if_expr(c_expr).true_case().type(),
282 "Type of renamed expr should be the same as operands for if_exprt",
283 c_expr.type().pretty(),
284 to_if_expr(c_expr).true_case().type().pretty());
286 expr.id() != ID_if ||
287 c_expr.type() == to_if_expr(c_expr).false_case().type(),
288 "Type of renamed expr should be the same as operands for if_exprt",
289 c_expr.type().pretty(),
290 to_if_expr(c_expr).false_case().type().pretty());
291
292 if(level == L2)
293 expr = field_sensitivity.apply(ns, *this, std::move(expr), false);
294
295 return renamedt<exprt, level>{std::move(expr)};
296 }
297}
298
299// Explicitly instantiate the one version of this function without an explicit
300// caller in this file:
303
305{
306 rename(lvalue.type(), irep_idt(), ns);
307
308 if(lvalue.id() == ID_symbol)
309 {
310 // Nothing to do
311 }
313 {
314 // Ignore apparent writes to 'NULL-object' and similar read-only objects
315 }
316 else if(lvalue.id() == ID_typecast)
317 {
320 }
321 else if(lvalue.id() == ID_member)
322 {
324 member_lvalue.compound() = l2_rename_rvalues(member_lvalue.compound(), ns);
325 }
326 else if(lvalue.id() == ID_index)
327 {
328 // The index is an rvalue:
330 index_lvalue.array() = l2_rename_rvalues(index_lvalue.array(), ns);
331 index_lvalue.index() = rename(index_lvalue.index(), ns).get();
332 }
333 else if(
336 {
337 // The offset is an rvalue:
340 byte_extract_lvalue.offset() = rename(byte_extract_lvalue.offset(), ns);
341 }
342 else if(lvalue.id() == ID_if)
343 {
344 // The condition is an rvalue:
345 auto &if_lvalue = to_if_expr(lvalue);
346 if_lvalue.cond() = rename(if_lvalue.cond(), ns);
347 if(!if_lvalue.cond().is_false())
348 if_lvalue.true_case() = l2_rename_rvalues(if_lvalue.true_case(), ns);
349 if(!if_lvalue.cond().is_true())
350 if_lvalue.false_case() = l2_rename_rvalues(if_lvalue.false_case(), ns);
351 }
352 else if(lvalue.id() == ID_complex_real)
353 {
356 }
357 else if(lvalue.id() == ID_complex_imag)
358 {
361 }
362 else
363 {
365 "l2_rename_rvalues case `" + lvalue.id_string() + "' not handled");
366 }
367
368 return lvalue;
369}
370
371template renamedt<exprt, L1>
372goto_symex_statet::rename<L1>(exprt expr, const namespacet &ns);
373
376 ssa_exprt &expr,
377 const namespacet &ns)
378{
379 // do we have threads?
380 if(threads.size()<=1)
381 return false;
382
383 // is it a shared object?
384 PRECONDITION(dirty != nullptr);
386 if(
388 (!ns.lookup(obj_identifier).is_shared() && !(*dirty)(obj_identifier)))
389 {
390 return false;
391 }
392
393 // only continue if an indivisible object is being accessed
394 if(field_sensitivity.is_divisible(expr, true))
395 return false;
396
397 const ssa_exprt ssa_l1 = remove_level_2(expr);
398 const irep_idt &l1_identifier=ssa_l1.get_identifier();
400
401 // see whether we are within an atomic section
402 if(atomic_section_id!=0)
403 {
405
408 {
409 for(const auto &guard_in_list : a_s_writes->second)
410 {
412 g-=guard;
413 if(g.is_true())
414 // There has already been a write to l1_identifier within this atomic
415 // section under the same guard, or a guard implied by the current
416 // one.
417 return false;
418
420 }
421 }
422
423 not_exprt no_write(write_guard.as_expr());
424
425 // we cannot determine for sure that there has been a write already
426 // so generate a read even if l1_identifier has been written on
427 // all branches flowing into this read
429
431 for(const auto &a_s_read_guard : a_s_read.second)
432 {
433 guardt g = a_s_read_guard; // copy
434 g-=guard;
435 if(g.is_true())
436 // There has already been a read of l1_identifier within this atomic
437 // section under the same guard, or a guard implied by the current one.
438 return false;
439
441 }
442
443 guardt cond = read_guard;
444 if(!no_write.op().is_false())
445 cond |= guardt{no_write.op(), guard_manager};
446
447 // It is safe to perform constant propagation in case we have read or
448 // written this object within the atomic section. We must actually do this,
449 // because goto_state::apply_condition may have placed the latest value in
450 // the propagation map without recording an assignment.
451 auto p_it = propagation.find(ssa_l1.get_identifier());
452 const exprt l2_true_case =
453 p_it.has_value() ? *p_it : set_indices<L2>(ssa_l1, ns).get();
454
455 if(!cond.is_true())
457
458 if(a_s_read.second.empty())
460
462
463 exprt tmp;
464 if(cond.is_false())
465 tmp = l2_false_case.get();
466 else if(cond.is_true())
468 else
470
471 record_events.push(false);
472 ssa_exprt ssa_l2 = assignment(std::move(ssa_l1), tmp, ns, true, true).get();
473 record_events.pop();
474
477 ssa_l2,
478 ssa_l2,
479 ssa_l2.get_original_expr(),
480 tmp,
481 source,
483
484 INVARIANT(!check_renaming(ssa_l2), "expr should be renamed to L2");
485 expr = std::move(ssa_l2);
486
487 a_s_read.second.push_back(guard);
488 if(!no_write.op().is_false())
489 a_s_read.second.back().add(no_write);
490
491 return true;
492 }
493
494 // No event and no fresh index, but avoid constant propagation
495 if(!record_events.top())
496 {
497 expr = set_indices<L2>(std::move(ssa_l1), ns).get();
498 return true;
499 }
500
501 // produce a fresh L2 name
503 expr = set_indices<L2>(std::move(ssa_l1), ns).get();
504
505 // and record that
507 symex_target!=nullptr, nullptr_exceptiont, "symex_target is null");
509
510 return true;
511}
512
514 const ssa_exprt &expr,
515 const namespacet &ns) const
516{
517 if(!record_events.top())
519
520 PRECONDITION(dirty != nullptr);
522 if(
524 (!ns.lookup(obj_identifier).is_shared() && !(*dirty)(obj_identifier)))
525 {
527 }
528
529 // only continue if an indivisible object is being accessed
530 if(field_sensitivity.is_divisible(expr, true))
532
533 if(atomic_section_id != 0)
535
537}
538
542 const ssa_exprt &expr,
543 const namespacet &ns)
544{
545 switch(write_is_shared(expr, ns))
546 {
548 return false;
550 {
552 return false;
553 }
555 break;
556 }
557
558 // record a shared write
560 guard.as_expr(),
561 expr,
563 source);
564
565 // do we have threads?
566 return threads.size() > 1;
567}
568
569template <levelt level>
571{
572 if(is_ssa_expr(expr))
573 {
575
576 // only do L1!
577 ssa = set_indices<L1>(std::move(ssa), ns).get();
578
579 rename<level>(expr.type(), ssa.get_identifier(), ns);
580 ssa.update_type();
581 }
582 else if(expr.id()==ID_symbol)
583 {
584 expr=ssa_exprt(expr);
585 rename_address<level>(expr, ns);
586 }
587 else
588 {
589 if(expr.id()==ID_index)
590 {
592
594 PRECONDITION(index_expr.array().type().id() == ID_array);
595 expr.type() = to_array_type(index_expr.array().type()).element_type();
596
597 // the index is not an address
598 index_expr.index() =
599 rename<level>(std::move(index_expr.index()), ns).get();
600 }
601 else if(expr.id()==ID_if)
602 {
603 // the condition is not an address
605 if_expr.cond() = rename<level>(std::move(if_expr.cond()), ns).get();
606 rename_address<level>(if_expr.true_case(), ns);
607 rename_address<level>(if_expr.false_case(), ns);
608
609 if_expr.type()=if_expr.true_case().type();
610 }
611 else if(expr.id()==ID_member)
612 {
614
615 rename_address<level>(member_expr.struct_op(), ns);
616
617 // type might not have been renamed in case of nesting of
618 // structs and pointers/arrays
619 if(
620 member_expr.struct_op().type().id() != ID_struct_tag &&
621 member_expr.struct_op().type().id() != ID_union_tag)
622 {
624 to_struct_union_type(member_expr.struct_op().type());
626 su_type.get_component(member_expr.get_component_name());
627 PRECONDITION(comp.is_not_nil());
628 expr.type()=comp.type();
629 }
630 else
631 rename<level>(expr.type(), irep_idt(), ns);
632 }
633 else
634 {
635 // this could go wrong, but we would have to re-typecheck ...
636 rename<level>(expr.type(), irep_idt(), ns);
637
638 // do this recursively; we assume here
639 // that all the operands are addresses
640 Forall_operands(it, expr)
641 rename_address<level>(*it, ns);
642 }
643 }
644}
645
649static bool requires_renaming(const typet &type, const namespacet &ns)
650{
651 if(type.id() == ID_array)
652 {
653 const auto &array_type = to_array_type(type);
654 return requires_renaming(array_type.element_type(), ns) ||
655 !array_type.size().is_constant();
656 }
657 else if(type.id() == ID_struct || type.id() == ID_union)
658 {
660 const struct_union_typet::componentst &components = s_u_type.components();
661
662 for(auto &component : components)
663 {
664 // be careful, or it might get cyclic
665 if(component.type().id() == ID_array)
666 {
667 if(!to_array_type(component.type()).size().is_constant())
668 return true;
669 }
670 else if(
671 component.type().id() != ID_pointer &&
672 requires_renaming(component.type(), ns))
673 {
674 return true;
675 }
676 }
677
678 return false;
679 }
680 else if(type.id() == ID_pointer)
681 {
682 return requires_renaming(to_pointer_type(type).base_type(), ns);
683 }
684 else if(type.id() == ID_union_tag)
685 {
686 const symbolt &symbol = ns.lookup(to_union_tag_type(type));
687 return requires_renaming(symbol.type, ns);
688 }
689 else if(type.id() == ID_struct_tag)
690 {
691 const symbolt &symbol = ns.lookup(to_struct_tag_type(type));
692 return requires_renaming(symbol.type, ns);
693 }
694
695 return false;
696}
697
698template <levelt level>
700 typet &type,
701 const irep_idt &l1_identifier,
702 const namespacet &ns)
703{
704 // check whether there are symbol expressions in the type; if not, there
705 // is no need to expand the struct/union tags in the type
706 if(!requires_renaming(type, ns))
707 return; // no action
708
709 // rename all the symbols with their last known value
710 // to the given level
711
712 std::pair<l1_typest::iterator, bool> l1_type_entry;
713 if(level==L2 &&
714 !l1_identifier.empty())
715 {
716 l1_type_entry=l1_types.insert(std::make_pair(l1_identifier, type));
717
718 if(!l1_type_entry.second) // was already in map
719 {
720 // do not change a complete array type to an incomplete one
721
722 const typet &type_prev=l1_type_entry.first->second;
723
724 if(type.id()!=ID_array ||
725 type_prev.id()!=ID_array ||
726 to_array_type(type).is_incomplete() ||
727 to_array_type(type_prev).is_complete())
728 {
729 type=l1_type_entry.first->second;
730 return;
731 }
732 }
733 }
734
735 if(type.id()==ID_array)
736 {
737 auto &array_type = to_array_type(type);
738 rename<level>(array_type.element_type(), irep_idt(), ns);
739 array_type.size() = rename<level>(std::move(array_type.size()), ns).get();
740 }
741 else if(
742 type.id() == ID_struct || type.id() == ID_union ||
743 type.id() == ID_struct_tag || type.id() == ID_union_tag)
744 {
745 // expand struct and union tag types
746 if(type.id() == ID_struct_tag)
747 type = ns.follow_tag(to_struct_tag_type(type));
748 else if(type.id() == ID_union_tag)
749 type = ns.follow_tag(to_union_tag_type(type));
750
752 struct_union_typet::componentst &components=s_u_type.components();
753
754 for(auto &component : components)
755 {
756 // be careful, or it might get cyclic
757 if(component.type().id() == ID_array)
758 {
759 auto &array_type = to_array_type(component.type());
760 array_type.size() =
761 rename<level>(std::move(array_type.size()), ns).get();
762 }
763 else if(component.type().id() != ID_pointer)
764 rename<level>(component.type(), irep_idt(), ns);
765 }
766 }
767 else if(type.id()==ID_pointer)
768 {
769 rename<level>(to_pointer_type(type).base_type(), irep_idt(), ns);
770 }
771
772 if(level==L2 &&
773 !l1_identifier.empty())
774 l1_type_entry.first->second=type;
775}
776
782void goto_symex_statet::print_backtrace(std::ostream &out) const
783{
784 if(threads[source.thread_nr].call_stack.empty())
785 {
786 out << "No stack!\n";
787 return;
788 }
789
790 out << source.function_id << " " << source.pc->location_number << "\n";
791
792 for(auto stackit = threads[source.thread_nr].call_stack.rbegin(),
793 stackend = threads[source.thread_nr].call_stack.rend();
794 stackit != stackend;
795 ++stackit)
796 {
797 const auto &frame = *stackit;
798 out << frame.calling_location.function_id << " "
799 << frame.calling_location.pc->location_number << "\n";
800 }
801}
802
804 const symbol_exprt &expr,
805 std::function<std::size_t(const irep_idt &)> index_generator,
806 const namespacet &ns)
807{
808 framet &frame = call_stack().top();
809
811 const irep_idt l0_name = renamed.get_identifier();
812 const std::size_t l1_index = index_generator(l0_name);
813
814 if(const auto old_value = level1.insert_or_replace(renamed, l1_index))
815 {
816 // save old L1 name
817 if(!frame.old_level1.has(renamed))
818 frame.old_level1.insert(renamed, old_value->second);
819 }
820
821 const ssa_exprt ssa = rename_ssa<L1>(renamed.get(), ns).get();
822 const bool inserted = frame.local_objects.insert(ssa.get_identifier()).second;
823 INVARIANT(inserted, "l1_name expected to be unique by construction");
824
825 return ssa;
826}
827
829{
830 const irep_idt &l1_identifier = ssa.get_identifier();
831
832 // rename type to L2
833 rename(ssa.type(), l1_identifier, ns);
834 ssa.update_type();
835
836 // in case of pointers, put something into the value set
837 if(ssa.type().id() == ID_pointer)
838 {
839 exprt rhs;
840 if(
841 auto failed =
842 get_failed_symbol(to_symbol_expr(ssa.get_original_expr()), ns))
844 else
845 rhs = exprt(ID_invalid);
846
847 exprt l1_rhs = rename<L1>(std::move(rhs), ns).get();
848 value_set.assign(ssa, l1_rhs, ns, true, false);
849 }
850
851 // L2 renaming
852 exprt fields = field_sensitivity.get_fields(ns, *this, ssa, false);
853 fields.visit_pre([this](const exprt &e) {
855 {
857 const std::size_t field_generation = level2.increase_generation(
858 l1_symbol->get_identifier(), field_ssa, fresh_l2_name_provider);
860 }
862 {
863 const ssa_exprt &ssa = fs_ssa->get_object_ssa();
864 const std::size_t field_generation = level2.increase_generation(
865 ssa.get_identifier(), ssa, fresh_l2_name_provider);
867 }
868 });
869
870 record_events.push(false);
871 exprt expr_l2 = rename(std::move(ssa), ns).get();
872 INVARIANT(
874 "symbol to declare should not be replaced by constant propagation");
876 record_events.pop();
877
878 return ssa;
879}
std::optional< symbol_exprt > get_failed_symbol(const symbol_exprt &expr, const namespacet &ns)
Get the failed-dereference symbol for the given symbol.
Pointer Dereferencing.
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
Definition as_const.h:14
Generic exception types primarily designed for use with invariants.
Expression classes for byte-level operators.
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
Definition c_types.h:224
Operator to return the address of an object.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
framet & top()
Definition call_stack.h:17
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:56
void visit_pre(std::function< void(exprt &)>)
Definition expr.cpp:227
typet & type()
Return the type of the expression.
Definition expr.h:84
The Boolean constant false.
Definition std_expr.h:3200
exprt get_fields(const namespacet &ns, goto_symex_statet &state, const ssa_exprt &ssa_expr, bool disjoined_fields_only) const
Compute an expression representing the individual components of a field-sensitive SSA representation ...
exprt apply(const namespacet &ns, goto_symex_statet &state, exprt expr, bool write) const
Turn an expression expr into a field-sensitive SSA expression.
bool is_divisible(const ssa_exprt &expr, bool disjoined_fields_only) const
Determine whether expr would translate to an atomic SSA expression (returns false) or a composite obj...
Stack frames – these are used for function calls and for exceptions.
symex_level1t old_level1
Definition frame.h:42
std::set< irep_idt > local_objects
Definition frame.h:44
Container for data that varies per program point, e.g.
Definition goto_state.h:32
symex_level2t level2
Definition goto_state.h:38
guardt guard
Definition goto_state.h:58
unsigned atomic_section_id
Threads.
Definition goto_state.h:76
sharing_mapt< irep_idt, exprt > propagation
Definition goto_state.h:71
value_sett value_set
Uses level 1 names, and is used to do dereferencing.
Definition goto_state.h:51
ssa_exprt declare(ssa_exprt ssa, const namespacet &ns)
Add invalid (or a failed symbol) to the value_set if ssa is a pointer, ensure that level2 index of sy...
ssa_exprt add_object(const symbol_exprt &expr, std::function< std::size_t(const irep_idt &)> index_generator, const namespacet &ns)
Instantiate the object expr.
call_stackt & call_stack()
std::pair< unsigned, std::list< guardt > > a_s_r_entryt
std::stack< bool > record_events
bool l2_thread_write_encoding(const ssa_exprt &expr, const namespacet &ns)
thread encoding
exprt l2_rename_rvalues(exprt lvalue, const namespacet &ns)
static irep_idt guard_identifier()
const incremental_dirtyt * dirty
std::unordered_map< ssa_exprt, a_s_r_entryt, irep_hash > read_in_atomic_section
std::unordered_map< ssa_exprt, a_s_w_entryt, irep_hash > written_in_atomic_section
symex_level1t level1
const irep_idt & language_mode
void rename_address(exprt &expr, const namespacet &ns)
renamedt< ssa_exprt, L2 > assignment(ssa_exprt lhs, const exprt &rhs, const namespacet &ns, bool rhs_is_simplified, bool record_value, bool allow_pointer_unsoundness=false)
guard_managert & guard_manager
bool l2_thread_read_encoding(ssa_exprt &expr, const namespacet &ns)
thread encoding
void print_backtrace(std::ostream &) const
Dumps the current state of symex, printing the function name and location number for each stack frame...
renamedt< exprt, level > rename(exprt expr, const namespacet &ns)
Rewrites symbol expressions in exprt, applying a suffix to each symbol reflecting its most recent ver...
symex_target_equationt * symex_target
goto_symex_statet(const symex_targett::sourcet &, std::size_t max_field_sensitive_array_size, bool should_simplify, const irep_idt &language_mode, guard_managert &manager, std::function< std::size_t(const irep_idt &)> fresh_l2_name_provider)
static bool is_read_only_object(const exprt &lvalue)
Returns true if lvalue is a read-only object, such as the null object.
field_sensitivityt field_sensitivity
write_is_shared_resultt write_is_shared(const ssa_exprt &expr, const namespacet &ns) const
symex_targett::sourcet source
renamedt< ssa_exprt, level > rename_ssa(ssa_exprt ssa, const namespacet &ns)
Version of rename which is specialized for SSA exprt.
bool run_validation_checks
Should the additional validation checks be run?
std::vector< threadt > threads
std::function< std::size_t(const irep_idt &)> fresh_l2_name_provider
bool is_true() const
Definition guard_expr.h:60
exprt as_expr() const
Definition guard_expr.h:46
bool is_false() const
Definition guard_expr.h:65
The trinary if-then-else operator.
Definition std_expr.h:2502
Array index operator.
Definition std_expr.h:1470
const irep_idt & id() const
Definition irep.h:388
bool is_nil() const
Definition irep.h:368
Extract member of struct or union.
Definition std_expr.h:2972
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
Definition namespace.cpp:49
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Boolean negation.
Definition std_expr.h:2459
Expression providing an SSA-renamed symbol of expressions.
Definition ssa_expr.h:17
void update_type()
Definition ssa_expr.h:28
irep_idt get_object_name() const
Definition ssa_expr.cpp:145
Base type for structs and unions.
Definition std_types.h:62
std::vector< componentt > componentst
Definition std_types.h:140
Expression to hold a symbol (variable)
Definition std_expr.h:131
const irep_idt & get_identifier() const
Definition std_expr.h:160
Symbol table entry.
Definition symbol.h:28
typet type
Type of symbol.
Definition symbol.h:31
virtual void shared_read(const exprt &guard, const ssa_exprt &ssa_object, unsigned atomic_section_id, const sourcet &source)
Read from a shared variable ssa_object (which is both the left- and the right–hand side of assignment...
virtual void shared_write(const exprt &guard, const ssa_exprt &ssa_object, unsigned atomic_section_id, const sourcet &source)
Write to a shared variable ssa_object: we effectively assign a value from this thread to be visible b...
virtual void assignment(const exprt &guard, const ssa_exprt &ssa_lhs, const exprt &ssa_full_lhs, const exprt &original_full_lhs, const exprt &ssa_rhs, const sourcet &source, assignment_typet assignment_type)
Write to a local variable.
The Boolean constant true.
Definition std_expr.h:3191
The type of an expression, extends irept.
Definition type.h:29
Thrown when we encounter an instruction, parameters to an instruction etc.
void output(std::ostream &out, const std::string &indent="") const
Pretty-print this value-set.
void assign(const exprt &lhs, const exprt &rhs, const namespacet &ns, bool is_simplified, bool add_to_sets)
Transforms this value-set by executing executing the assignment lhs := rhs against it.
Variables whose address is taken.
#define Forall_operands(it, expr)
Definition expr.h:27
Deprecated expression utility functions.
GOTO Symex constant propagation.
static bool requires_renaming(const typet &type, const namespacet &ns)
Return true if, and only if, the type or one of its subtypes requires SSA renaming.
Symbolic Execution.
guard_exprt guardt
Definition guard.h:29
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
static bool is_shared(const namespacet &ns, const symbol_exprt &symbol_expr)
@ L2
Definition renamed.h:26
@ L0
Definition renamed.h:23
@ L1_WITH_CONSTANT_PROPAGATION
Definition renamed.h:25
@ L1
Definition renamed.h:24
bool check_renaming(const typet &type)
Check that type is correctly renamed to level 2 and return true in case an error is detected.
renamedt< ssa_exprt, L0 > symex_level0(ssa_exprt ssa_expr, const namespacet &ns, std::size_t thread_nr)
Set the level 0 renaming of SSA expressions.
bool check_renaming_l1(const exprt &expr)
Check that expr is correctly renamed to level 1 and return true in case an error is detected.
#define INVARIANT_STRUCTURED(CONDITION, TYPENAME,...)
Definition invariant.h:407
#define CHECK_RETURN(CONDITION)
Definition invariant.h:495
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition invariant.h:534
#define PRECONDITION(CONDITION)
Definition invariant.h:463
#define INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
Same as invariant, with one or more diagnostics attached Diagnostics can be of any type that has a sp...
Definition invariant.h:437
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
ssa_exprt remove_level_2(ssa_exprt ssa)
Definition ssa_expr.cpp:219
bool is_ssa_expr(const exprt &expr)
Definition ssa_expr.h:125
const ssa_exprt & to_ssa_expr(const exprt &expr)
Cast a generic exprt to an ssa_exprt.
Definition ssa_expr.h:145
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
Definition std_expr.cpp:122
API to expression classes.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
Definition std_expr.h:1538
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
Definition std_expr.h:2107
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
Definition std_expr.h:2582
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
Definition std_expr.h:3064
const complex_imag_exprt & to_complex_imag_expr(const exprt &expr)
Cast an exprt to a complex_imag_exprt.
Definition std_expr.h:2053
const complex_real_exprt & to_complex_real_expr(const exprt &expr)
Cast an exprt to a complex_real_exprt.
Definition std_expr.h:2010
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition std_expr.h:272
const with_exprt & to_with_expr(const exprt &expr)
Cast an exprt to a with_exprt.
Definition std_expr.h:2661
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition std_types.h:518
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
Definition std_types.h:888
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
Definition std_types.h:214
This is unused by this implementation of guards, but can be used by other implementations of the same...
Definition guard_expr.h:20
std::optional< std::pair< ssa_exprt, std::size_t > > insert_or_replace(const renamedt< ssa_exprt, L0 > &ssa, std::size_t index)
Set the index for ssa to index.
bool has(const renamedt< ssa_exprt, L0 > &ssa) const
void insert(const renamedt< ssa_exprt, L0 > &ssa, std::size_t index)
Assume ssa is not already known.
unsigned latest_index(const irep_idt &identifier) const
Counter corresponding to an identifier.
std::size_t increase_generation(const irep_idt &l1_identifier, const ssa_exprt &lhs, std::function< std::size_t(const irep_idt &)> fresh_l2_name_provider)
Allocates a fresh L2 name for the given L1 identifier, and makes it the latest generation on this pat...
Identifies source in the context of symbolic execution.
goto_programt::const_targett pc
Generate Equation using Symbolic Execution.
static bool failed(bool error_indicator)
dstringt irep_idt