CBMC
Loading...
Searching...
No Matches
goto_clean_expr.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Program Transformation
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#include "goto_convert_class.h"
13
14#include <util/expr_util.h>
15#include <util/fresh_symbol.h>
17#include <util/pointer_expr.h>
18#include <util/replace_expr.h>
19#include <util/std_expr.h>
20#include <util/symbol.h>
21
23
24#include "destructor.h"
25
26#include <unordered_map>
27
29{
30 if(expr.id() == ID_symbol)
31 {
32 return to_symbol_expr(expr);
33 }
34 else if(expr.id() == ID_member)
35 {
36 return find_base_symbol(to_member_expr(expr).struct_op());
37 }
38 else if(expr.id() == ID_index)
39 {
40 return find_base_symbol(to_index_expr(expr).array());
41 }
42 else if(expr.id() == ID_dereference)
43 {
44 return find_base_symbol(to_dereference_expr(expr).pointer());
45 }
46 else if(expr.id() == ID_typecast)
47 {
48 return find_base_symbol(to_typecast_expr(expr).op());
49 }
50 else if(expr.id() == ID_address_of)
51 {
52 return find_base_symbol(to_address_of_expr(expr).op());
53 }
54 else
55 {
56 throw "unsupported expression type for finding base symbol";
57 }
58}
59
61 const quantifier_exprt &qex,
62 const code_expressiont &code,
63 const irep_idt &mode,
64 goto_convertt &converter)
65{
66 goto_programt where;
67 converter.goto_convert(code, where, mode);
69
70 natural_loops_mutablet natural_loops(where);
72 natural_loops.loop_map.size() == 0, "quantifier must not contain loops");
73
74 std::unordered_set<symbol_exprt, irep_hash> declared_symbols;
75 // All bound variables are local.
76 declared_symbols.insert(qex.variables().begin(), qex.variables().end());
77
78 // `last` is the instruction corresponding to the last expression in the
79 // statement expression.
81 for(goto_programt::const_targett it = where.instructions.begin();
82 it != where.instructions.end();
83 ++it)
84 {
85 // `last` is an other-instruction.
86 if(it->is_other())
87 {
88 last = it;
89 }
90
91 if(it->is_decl())
92 {
93 declared_symbols.insert(it->decl_symbol());
94 }
95 }
96
98 last != where.instructions.end(),
99 "expression statements must contain a terminator expression");
100
101 auto last_expr = to_code_expression(last->get_other()).expression();
102 if(
103 last_expr.id() == ID_typecast &&
104 to_typecast_expr(last_expr).type().id() == ID_empty)
105 {
107 }
108
109 struct pathst
110 {
111 // `paths` contains all the `targett` we are iterating over.
112 std::vector<goto_programt::const_targett> paths;
113 std::vector<std::pair<exprt, replace_mapt>> path_conditions_and_value_maps;
114
115 pathst(
116 std::vector<goto_programt::const_targett> paths,
117 std::vector<std::pair<exprt, replace_mapt>>
119 : paths(paths),
121 {
122 }
123
124 bool empty()
125 {
126 return paths.empty();
127 }
128
130 {
131 return paths.back();
132 }
133
135 {
136 return path_conditions_and_value_maps.back().first;
137 }
138
140 {
141 return path_conditions_and_value_maps.back().second;
142 }
143
144 void push_back(
147 replace_mapt value_map)
148 {
149 paths.push_back(target);
151 std::make_pair(path_condition, value_map));
152 }
153
154 void pop_back()
155 {
156 paths.pop_back();
158 }
159 };
160
161 pathst paths(
162 {1, where.instructions.begin()},
163 {1, std::make_pair(true_exprt(), replace_mapt())});
164
165 exprt res = true_exprt();
166
167 // Visit the quantifier body along `paths`.
168 while(!paths.empty())
169 {
170 auto &current_it = paths.back_it();
171 auto &path_condition = paths.back_path_condition();
172 auto &value_map = paths.back_value_map();
173
174 if(current_it == where.instructions.end())
175 {
176 paths.pop_back();
177 continue;
178 }
179
180 switch(current_it->type())
181 {
182 // Add all local-declared symbols into `declared_symbols`.
184 declared_symbols.insert(current_it->decl_symbol());
185 break;
186
187 // ASSIGN lhs := rhs
188 // Add the replace lhr <- value_map(rhs) to the current value_map.
190 {
191 // Check that if lhs is a declared symbol.
192 auto lhs = current_it->assign_lhs();
193 INVARIANT(
195 "quantifier must not contain side effects");
196 exprt rhs = current_it->assign_rhs();
197 replace_expr(value_map, rhs);
198 value_map[lhs] = rhs;
199 }
200 break;
201
202 // GOTO label
203 // -----------
204 // Move the current targett to label.
205 // or
206 // IF cond GOTO label
207 // ----------
208 // Move the current targett to targett+1 with path condition
209 // path_condition && !cond;
210 // and add a new path starting from label with path condition
211 // path_condition && cond.
213 {
214 exprt condition = current_it->condition();
215 replace_expr(value_map, condition);
216 if(!condition.is_true())
217 {
218 auto next_it = current_it->targets.front();
221 current_it++;
222 paths.push_back(
223 next_it, and_exprt(copy_path_condition, condition), value_map);
224 }
225 else
226 {
227 current_it = current_it->targets.front();
228 }
229 continue;
230 }
231
232 // EXPRESSION(expr)
233 // The last instruction is an expression statement.
234 // We add the predicate path_condition ==> value_map(expr) to res.
236 {
237 if(current_it == last)
238 {
242 paths.pop_back();
243 continue;
244 }
245 }
246 break;
247
248 // Ignored instructions.
257 break;
258
259 // Unsupported instructions.
269 }
270
271 current_it++;
272 }
273 return res;
274}
275
277 const exprt &expr,
278 goto_programt &dest,
279 const irep_idt &mode)
280{
281 const source_locationt source_location = expr.find_source_location();
282
283 symbolt &new_symbol = get_fresh_aux_symbol(
284 expr.type(),
286 "literal",
287 source_location,
288 mode,
291 new_symbol.value = expr;
292
293 // The value might depend on a variable, thus
294 // generate code for this.
295
296 symbol_exprt result = new_symbol.symbol_expr();
297 result.add_source_location() = source_location;
298
299 // The lifetime of compound literals is really that of
300 // the block they are in.
301 if(!new_symbol.is_static_lifetime)
302 copy(code_declt(result), DECL, dest);
303
305 code_assign.add_source_location() = source_location;
306 convert(code_assign, dest, mode);
307
308 // now create a 'dead' instruction
309 if(!new_symbol.is_static_lifetime)
310 {
312 targets.scope_stack.add(std::move(code_dead), {});
313 }
314
315 return result;
316}
317
324{
325 if(
326 expr.id() == ID_side_effect || expr.id() == ID_compound_literal ||
327 expr.id() == ID_comma)
328 {
329 return true;
330 }
331
332 // We can't flatten quantified expressions by introducing new literals for
333 // conditional expressions. This is because the body of the quantified
334 // may refer to bound variables, which are not visible outside the scope
335 // of the quantifier.
336 //
337 // For example, the following transformation would not be valid:
338 //
339 // forall (i : int) (i == 0 || i > 10)
340 //
341 // transforming to
342 //
343 // g1 = (i == 0)
344 // g2 = (i > 10)
345 // forall (i : int) (g1 || g2)
346 if(expr.id() == ID_forall || expr.id() == ID_exists)
347 {
348 code_expressiont where{to_quantifier_expr(expr).where()};
349 // Need cleaning when the quantifier body is a side-effect expression.
350 if(has_subexpr(expr, ID_side_effect))
351 return true;
352
353 return false;
354 }
355
356 for(const auto &op : expr.operands())
357 {
358 if(needs_cleaning(op))
359 return true;
360 }
361
362 return false;
363}
364
367{
369 expr.id() == ID_and || expr.id() == ID_or || expr.id() == ID_implies);
371 expr.is_boolean(),
373 "'",
374 expr.id(),
375 "' must be Boolean, but got ",
377
378 const source_locationt source_location = expr.find_source_location();
379
380 // re-write "a ==> b" into a?b:1
381 if(auto implies = expr_try_dynamic_cast<implies_exprt>(expr))
382 {
383 expr = if_exprt{
384 std::move(implies->lhs()),
385 std::move(implies->rhs()),
386 true_exprt{}.with_source_location(source_location),
387 bool_typet{}};
388 return;
389 }
390
391 // re-write "a && b" into nested a?b:0
392 // re-write "a || b" into nested a?1:b
393
394 exprt tmp;
395
396 if(expr.id() == ID_and)
397 tmp = true_exprt();
398 else // ID_or
399 tmp = false_exprt();
400
401 tmp.add_source_location() = source_location;
402
403 exprt::operandst &ops = expr.operands();
404
405 // start with last one
406 for(exprt::operandst::reverse_iterator it = ops.rbegin(); it != ops.rend();
407 ++it)
408 {
409 exprt &op = *it;
410
412 op.is_boolean(),
413 "boolean operators must have only boolean operands",
414 source_location);
415
416 if(expr.id() == ID_and)
417 {
418 exprt if_e =
419 if_exprt{op, tmp, false_exprt{}.with_source_location(source_location)}
420 .with_source_location(source_location);
421 tmp.swap(if_e);
422 continue;
423 }
424 if(expr.id() == ID_or)
425 {
426 exprt if_e =
427 if_exprt{op, true_exprt{}.with_source_location(source_location), tmp}
428 .with_source_location(source_location);
429 tmp.swap(if_e);
430 continue;
431 }
433 }
434
435 expr.swap(tmp);
436}
437
439 exprt &expr,
440 const irep_idt &mode,
441 bool result_is_used)
442{
443 // this cleans:
444 // && || ==> ?: comma (control-dependency)
445 // function calls
446 // object constructors like arrays, string constants, structs
447 // ++ -- (pre and post)
448 // compound assignments
449 // compound literals
450
451 if(!needs_cleaning(expr))
452 return {};
453
454 if(expr.id() == ID_and || expr.id() == ID_or || expr.id() == ID_implies)
455 {
456 // rewrite into ?:
457 rewrite_boolean(expr);
458
459 // recursive call
460 return clean_expr(expr, mode, result_is_used);
461 }
462 else if(expr.id() == ID_if)
463 {
464 // first clean condition
465 clean_expr_resultt side_effects =
466 clean_expr(to_if_expr(expr).cond(), mode, true);
467
468 // possibly done now
469 if(
470 !needs_cleaning(to_if_expr(expr).true_case()) &&
471 !needs_cleaning(to_if_expr(expr).false_case()))
472 {
473 return side_effects;
474 }
475
476 // copy expression
478
480 if_expr.cond().is_boolean(),
481 "condition for an 'if' must be boolean",
482 if_expr.find_source_location());
483
484 const source_locationt source_location = expr.find_source_location();
485
486#if 0
487 // We do some constant-folding here, to mimic
488 // what typical compilers do.
489 {
490 exprt tmp_cond=if_expr.cond();
492 if(tmp_cond.is_true())
493 {
494 clean_expr(if_expr.true_case(), dest, result_is_used);
495 expr=if_expr.true_case();
496 return;
497 }
498 else if(tmp_cond.is_false())
499 {
500 clean_expr(if_expr.false_case(), dest, result_is_used);
501 expr=if_expr.false_case();
502 return;
503 }
504 }
505#endif
506
508 clean_expr(if_expr.true_case(), mode, result_is_used));
509
511 clean_expr(if_expr.false_case(), mode, result_is_used));
512
514 {
515 symbolt &new_symbol = new_tmp_symbol(
516 expr.type(),
517 "if_expr",
518 side_effects.side_effects,
519 source_location,
520 mode);
521
523 assignment_true.lhs() = new_symbol.symbol_expr();
524 assignment_true.rhs() = if_expr.true_case();
525 assignment_true.add_source_location() = source_location;
526 convert(assignment_true, tmp_true.side_effects, mode);
527
529 assignment_false.lhs() = new_symbol.symbol_expr();
530 assignment_false.rhs() = if_expr.false_case();
531 assignment_false.add_source_location() = source_location;
532 convert(assignment_false, tmp_false.side_effects, mode);
533
534 // overwrites expr
535 expr = new_symbol.symbol_expr();
536 }
537 else
538 {
539 // preserve the expressions for possible later checks
540 if(if_expr.true_case().is_not_nil())
541 {
542 // add a (void) type cast so that is_skip catches it in case the
543 // expression is just a constant
545 typecast_exprt(if_expr.true_case(), empty_typet()));
546 convert(code_expression, tmp_true.side_effects, mode);
547 }
548
549 if(if_expr.false_case().is_not_nil())
550 {
551 // add a (void) type cast so that is_skip catches it in case the
552 // expression is just a constant
554 typecast_exprt(if_expr.false_case(), empty_typet()));
555 convert(code_expression, tmp_false.side_effects, mode);
556 }
557
558 expr = nil_exprt();
559 }
560
561 // generate guard for argument side-effects
563 if_expr.cond(),
564 source_location,
565 tmp_true.side_effects,
566 if_expr.true_case().source_location(),
567 tmp_false.side_effects,
568 if_expr.false_case().source_location(),
569 side_effects.side_effects,
570 mode);
571
572 destruct_locals(tmp_false.temporaries, side_effects.side_effects, ns);
573 destruct_locals(tmp_true.temporaries, side_effects.side_effects, ns);
574 destruct_locals(side_effects.temporaries, side_effects.side_effects, ns);
575 side_effects.temporaries.clear();
576
577 if(expr.is_not_nil())
578 side_effects.add_temporary(to_symbol_expr(expr).get_identifier());
579
580 return side_effects;
581 }
582 else if(expr.id() == ID_comma)
583 {
584 clean_expr_resultt side_effects;
585
587 {
589
590 Forall_operands(it, expr)
591 {
592 bool last = (it == --expr.operands().end());
593
594 // special treatment for last one
595 if(last)
596 {
597 result.swap(*it);
598 side_effects.add(clean_expr(result, mode, true));
599 }
600 else
601 {
602 side_effects.add(clean_expr(*it, mode, false));
603
604 // remember these for later checks
605 if(it->is_not_nil())
606 convert(code_expressiont(*it), side_effects.side_effects, mode);
607 }
608 }
609
610 expr.swap(result);
611 }
612 else // result not used
613 {
614 Forall_operands(it, expr)
615 {
616 side_effects.add(clean_expr(*it, mode, false));
617
618 // remember as expression statement for later checks
619 if(it->is_not_nil())
620 convert(code_expressiont(*it), side_effects.side_effects, mode);
621 }
622
623 expr = nil_exprt();
624 }
625
626 return side_effects;
627 }
628 else if(expr.id() == ID_typecast)
629 {
630 typecast_exprt &typecast = to_typecast_expr(expr);
631
632 // preserve 'result_is_used'
633 clean_expr_resultt side_effects =
634 clean_expr(typecast.op(), mode, result_is_used);
635
636 if(typecast.op().is_nil())
637 expr.make_nil();
638
639 return side_effects;
640 }
641 else if(expr.id() == ID_side_effect)
642 {
643 // some of the side-effects need special treatment!
644 const irep_idt statement = to_side_effect_expr(expr).get_statement();
645
646 if(statement == ID_gcc_conditional_expression)
647 {
648 // need to do separately
649 return remove_gcc_conditional_expression(expr, mode);
650 }
651 else if(statement == ID_statement_expression)
652 {
653 // need to do separately to prevent that
654 // the operands of expr get 'cleaned'
657 }
658 else if(statement == ID_assign)
659 {
660 // we do a special treatment for x=f(...)
661 INVARIANT(
662 expr.operands().size() == 2,
663 "side-effect assignment expressions must have two operands");
664
666
667 if(
668 side_effect_assign.rhs().id() == ID_side_effect &&
671 {
672 clean_expr_resultt side_effects =
673 clean_expr(side_effect_assign.lhs(), mode);
674 exprt lhs = side_effect_assign.lhs();
675
677 if(must_use_rhs)
678 {
679 side_effects.add(remove_function_call(
681 mode,
682 true));
683 }
684
685 // turn into code
688 side_effect_assign.rhs(), new_lhs.type());
689 code_assignt assignment(std::move(new_lhs), new_rhs);
690 assignment.add_source_location() = expr.source_location();
691 convert_assign(assignment, side_effects.side_effects, mode);
692
694 expr = must_use_rhs ? new_rhs : lhs;
695 else
696 expr.make_nil();
697
698 return side_effects;
699 }
700 }
701 }
702 else if(expr.id() == ID_forall || expr.id() == ID_exists)
703 {
705 code_expressiont code{qex.where()};
707 !has_subexpr(expr, ID_side_effect) ||
708 (code.operands()[0].id() == ID_side_effect &&
709 code.operands()[0].get_named_sub()[ID_statement].id() ==
711 "quantifier must not contain side effects");
712
713 // Handle the case that quantifier body is a statement expression.
714 if(
715 code.operands()[0].id() == ID_side_effect &&
716 code.operands()[0].get_named_sub()[ID_statement].id() ==
718 {
719 auto res = convert_statement_expression(qex, code, mode, *this);
720 qex.where() = res;
721 return clean_expr(res, mode, result_is_used);
722 }
723 }
724 else if(expr.id() == ID_address_of)
725 {
727 return clean_expr_address_of(addr.object(), mode);
728 }
729
730 clean_expr_resultt side_effects;
731
732 // TODO: evaluation order
733
734 Forall_operands(it, expr)
735 side_effects.add(clean_expr(*it, mode));
736
737 if(expr.id() == ID_side_effect)
738 {
739 side_effects.add(remove_side_effect(
740 to_side_effect_expr(expr), mode, result_is_used, false));
741 }
742 else if(expr.id() == ID_compound_literal)
743 {
744 // This is simply replaced by the literal
746 expr.operands().size() == 1, "ID_compound_literal has a single operand");
747 expr = to_unary_expr(expr).op();
748 }
749
750 return side_effects;
751}
752
755{
756 clean_expr_resultt side_effects;
757
758 // The address of object constructors can be taken,
759 // which is re-written into the address of a variable.
760
761 if(expr.id() == ID_compound_literal)
762 {
764 expr.operands().size() == 1, "ID_compound_literal has a single operand");
765 side_effects.add(clean_expr(to_unary_expr(expr).op(), mode));
767 to_unary_expr(expr).op(), side_effects.side_effects, mode);
768 }
769 else if(expr.id() == ID_string_constant)
770 {
771 // Leave for now, but long-term these might become static symbols.
772 // LLVM appears to do precisely that.
773 }
774 else if(expr.id() == ID_index)
775 {
777 side_effects.add(clean_expr_address_of(index_expr.array(), mode));
778 side_effects.add(clean_expr(index_expr.index(), mode));
779 }
780 else if(expr.id() == ID_dereference)
781 {
783 side_effects.add(clean_expr(deref_expr.pointer(), mode));
784 }
785 else if(expr.id() == ID_comma)
786 {
787 // Yes, one can take the address of a comma expression.
788 // Treatment is similar to clean_expr() above.
789
791
792 Forall_operands(it, expr)
793 {
794 bool last = (it == --expr.operands().end());
795
796 // special treatment for last one
797 if(last)
798 result.swap(*it);
799 else
800 {
801 side_effects.add(clean_expr(*it, mode, false));
802
803 // get any side-effects
804 if(it->is_not_nil())
805 convert(code_expressiont(*it), side_effects.side_effects, mode);
806 }
807 }
808
809 expr.swap(result);
810
811 // do again
812 side_effects.add(clean_expr_address_of(expr, mode));
813 }
814 else if(expr.id() == ID_side_effect)
815 {
816 side_effects.add(
817 remove_side_effect(to_side_effect_expr(expr), mode, true, true));
818 }
819 else
820 Forall_operands(it, expr)
821 side_effects.add(clean_expr_address_of(*it, mode));
822
823 return side_effects;
824}
825
828 exprt &expr,
829 const irep_idt &mode)
830{
831 clean_expr_resultt side_effects;
832
833 {
834 auto &binary_expr = to_binary_expr(expr);
835
836 // first remove side-effects from condition
837 side_effects = clean_expr(to_binary_expr(expr).op0(), mode);
838
839 // now we can copy op0 safely
842 binary_expr.op0(),
843 binary_expr.op1(),
844 expr.type());
845 if_expr.add_source_location() = expr.source_location();
846
847 expr.swap(if_expr);
848 }
849
850 // there might still be junk in expr.op2()
851 side_effects.add(clean_expr(expr, mode));
852
853 return side_effects;
854}
@ AUTOMATIC_LOCAL
Allocate local objects with automatic lifetime.
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
Boolean AND.
Definition std_expr.h:2125
The Boolean type.
Definition std_types.h:36
A goto_instruction_codet representing an assignment in the program.
A goto_instruction_codet representing the removal of a local variable going out of scope.
A goto_instruction_codet representing the declaration of a local variable.
codet representation of an expression statement.
Definition std_code.h:1394
const exprt & expression() const
Definition std_code.h:1401
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
The empty type.
Definition std_types.h:51
Base class for all expressions.
Definition expr.h:56
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
Definition expr.cpp:147
std::vector< exprt > operandst
Definition expr.h:58
bool is_true() const
Return whether the expression is a constant representing true.
Definition expr.cpp:27
bool is_boolean() const
Return whether the expression represents a Boolean.
Definition expr.h:224
typet & type()
Return the type of the expression.
Definition expr.h:84
operandst & operands()
Definition expr.h:94
const source_locationt & source_location() const
Definition expr.h:231
source_locationt & add_source_location()
Definition expr.h:236
exprt & with_source_location(source_locationt location) &
Add the source location from location, if it is non-nil.
Definition expr.h:101
The Boolean constant false.
Definition std_expr.h:3199
clean_expr_resultt clean_expr_address_of(exprt &expr, const irep_idt &mode)
symbol_table_baset & symbol_table
void convert_assign(const code_assignt &code, goto_programt &dest, const irep_idt &mode)
clean_expr_resultt remove_gcc_conditional_expression(exprt &expr, const irep_idt &mode)
void goto_convert(const codet &code, goto_programt &dest, const irep_idt &mode)
void copy(const codet &code, goto_program_instruction_typet type, goto_programt &dest)
void generate_ifthenelse(const exprt &cond, const source_locationt &, goto_programt &true_case, const source_locationt &, goto_programt &false_case, const source_locationt &, goto_programt &dest, const irep_idt &mode)
if(guard) true_case; else false_case;
std::string tmp_symbol_prefix
struct goto_convertt::targetst targets
symbolt & new_tmp_symbol(const typet &type, const std::string &suffix, goto_programt &dest, const source_locationt &, const irep_idt &mode)
symbol_exprt make_compound_literal(const exprt &expr, goto_programt &dest, const irep_idt &mode)
clean_expr_resultt remove_side_effect(side_effect_exprt &expr, const irep_idt &mode, bool result_is_used, bool address_taken)
static bool needs_cleaning(const exprt &expr)
Returns 'true' for expressions that may change the program state.
void convert(const codet &code, goto_programt &dest, const irep_idt &mode)
converts 'code' and appends the result to 'dest'
clean_expr_resultt remove_function_call(side_effect_expr_function_callt &expr, const irep_idt &mode, bool result_is_used)
clean_expr_resultt remove_statement_expression(side_effect_exprt &expr, const irep_idt &mode, bool result_is_used)
clean_expr_resultt clean_expr(exprt &expr, const irep_idt &mode, bool result_is_used=true)
void rewrite_boolean(exprt &dest)
re-write boolean operators into ?:
static bool assignment_lhs_needs_temporary(const exprt &lhs)
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
instructionst::const_iterator const_targett
void compute_location_numbers(unsigned &nr)
Compute location numbers.
The trinary if-then-else operator.
Definition std_expr.h:2497
Boolean implication.
Definition std_expr.h:2225
Array index operator.
Definition std_expr.h:1470
bool is_not_nil() const
Definition irep.h:372
void make_nil()
Definition irep.h:446
void swap(irept &irep)
Definition irep.h:434
const irep_idt & id() const
Definition irep.h:388
loop_mapt loop_map
mstreamt & result() const
Definition message.h:401
The NIL expression.
Definition std_expr.h:3208
Boolean negation.
Definition std_expr.h:2454
A base class for quantifier expressions.
const irep_idt & get_statement() const
Definition std_code.h:1472
Expression to hold a symbol (variable)
Definition std_expr.h:131
Symbol table entry.
Definition symbol.h:28
bool is_static_lifetime
Definition symbol.h:70
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Definition symbol.cpp:121
exprt value
Initial value of symbol.
Definition symbol.h:34
The Boolean constant true.
Definition std_expr.h:3190
Semantic type conversion.
Definition std_expr.h:2073
static exprt conditional_cast(const exprt &expr, const typet &type)
Definition std_expr.h:2081
const exprt & op() const
Definition std_expr.h:391
void destruct_locals(const std::list< irep_idt > &vars, goto_programt &dest, const namespacet &ns)
Destructor Calls.
#define Forall_operands(it, expr)
Definition expr.h:27
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
bool has_subexpr(const exprt &expr, const std::function< bool(const exprt &)> &pred)
returns true if the expression has a subexpression that satisfies pred
Deprecated expression utility functions.
symbolt & get_fresh_aux_symbol(const typet &type, const std::string &name_prefix, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &symbol_mode, const namespacet &ns, symbol_table_baset &symbol_table)
Installs a fresh-named symbol with respect to the given namespace ns with the requested name pattern ...
Fresh auxiliary symbol creation.
static symbol_exprt find_base_symbol(const exprt &expr)
static exprt convert_statement_expression(const quantifier_exprt &qex, const code_expressiont &code, const irep_idt &mode, goto_convertt &converter)
Program Transformation.
@ FUNCTION_CALL
@ ATOMIC_END
@ DEAD
@ LOCATION
@ END_FUNCTION
@ ASSIGN
@ ASSERT
@ SET_RETURN_VALUE
@ ATOMIC_BEGIN
@ CATCH
@ END_THREAD
@ SKIP
@ NO_INSTRUCTION_TYPE
@ START_THREAD
@ THROW
@ DECL
@ OTHER
@ GOTO
@ INCOMPLETE_GOTO
@ ASSUME
API to expression classes for 'mathematical' expressions.
const quantifier_exprt & to_quantifier_expr(const exprt &expr)
Cast an exprt to a quantifier_exprt.
Compute natural loops in a goto_function.
std::list< patht > pathst
Definition path.h:45
API to expression classes for Pointers.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
std::unordered_map< exprt, exprt, irep_hash > replace_mapt
exprt deref_expr(const exprt &expr)
Wraps a given expression into a dereference_exprt unless it is an address_of_exprt in which case it j...
bool simplify(exprt &expr, const namespacet &ns)
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
Definition invariant.h:464
#define UNREACHABLE
This should be used to mark dead code.
Definition invariant.h:525
#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(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
#define DATA_INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
Definition invariant.h:535
side_effect_exprt & to_side_effect_expr(exprt &expr)
Definition std_code.h:1506
side_effect_expr_function_callt & to_side_effect_expr_function_call(exprt &expr)
Definition std_code.h:1739
side_effect_expr_assignt & to_side_effect_expr_assign(exprt &expr)
Definition std_code.h:1618
code_expressiont & to_code_expression(codet &code)
Definition std_code.h:1428
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 binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
Definition std_expr.h:715
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
Definition std_expr.h:426
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
Definition std_expr.h:2577
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
Definition std_expr.h:3063
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition std_expr.h:272
std::list< irep_idt > temporaries
Identifiers of temporaries introduced while cleaning an expression.
void add(clean_expr_resultt &&other)
void add_temporary(const irep_idt &id)
goto_programt side_effects
Statements implementing side effects of the expression that was subject to cleaning.
Symbol table entry.