36 const irep_idt &identifier =
function.get_identifier();
39 if(arguments.size()!=2)
42 error() <<
"`" << identifier
43 <<
"' expected to have two arguments" <<
eom;
50 error() <<
"`" << identifier <<
"' expected to have LHS" <<
eom;
57 if(lhs.
type().
id()!=ID_unsignedbv &&
58 lhs.
type().
id()!=ID_signedbv)
61 error() <<
"`" << identifier <<
"' expected other type" <<
eom;
65 if(arguments[0].type().
id()!=lhs.
type().
id() ||
66 arguments[1].type().id()!=lhs.
type().
id())
69 error() <<
"`" << identifier
70 <<
"' expected operands to be of same type as LHS" <<
eom;
74 if(!arguments[0].is_constant() ||
75 !arguments[1].is_constant())
78 error() <<
"`" << identifier
79 <<
"' expected operands to be constant literals" <<
eom;
89 error() <<
"error converting operands" <<
eom;
96 error() <<
"expected lower bound to be smaller or equal to the " 97 <<
"upper bound" <<
eom;
101 rhs.copy_to_operands(arguments[0], arguments[1]);
114 const irep_idt &identifier =
function.get_identifier();
117 if(arguments.size()!=2)
120 error() <<
"`" << identifier <<
"' expected to have two arguments" 128 error() <<
"`" << identifier <<
"' expected to have LHS" <<
eom;
137 error() <<
"`" << identifier <<
"' expected bool" <<
eom;
141 if(arguments[0].type().
id()!=ID_unsignedbv ||
142 arguments[0].
id()!=ID_constant)
145 error() <<
"`" << identifier <<
"' expected first operand to be " 146 <<
"a constant literal of type unsigned long" <<
eom;
156 error() <<
"error converting operands" <<
eom;
163 error() <<
"probability has to be smaller than 1" <<
eom;
170 error() <<
"denominator may not be zero" <<
eom;
174 rationalt numerator(num), denominator(den);
175 rationalt prob = numerator / denominator;
190 const irep_idt &f_id =
function.get_identifier();
196 static_cast<const typet &
>(
function.type().find(ID_return_type));
198 ID_printf, return_type,
function.source_location());
211 printf_code.
id(ID_code);
226 const irep_idt &f_id =
function.get_identifier();
230 if(arguments.empty())
233 error() <<
"scanf takes at least one argument" <<
eom;
245 std::size_t argument_number=1;
247 for(
const auto &t : token_list)
253 if(argument_number<arguments.size())
259 if(type.
id()==ID_array)
268 type,
"scanf_string", dest,
function.source_location());
276 codet array_copy_statement;
278 array_copy_statement.
operands().resize(2);
279 array_copy_statement.
op0()=ptr;
280 \ array_copy_statement.
op1()=rhs;
282 function.source_location();
291 assign.add_source_location()=
function.source_location();
300 type,
function.source_location());
313 function_call.
lhs()=lhs;
326 const exprt &
function,
330 codet input_code(ID_input);
334 if(arguments.size()<2)
337 error() <<
"input takes at least two arguments" <<
eom;
345 const exprt &
function,
349 codet output_code(ID_output);
353 if(arguments.size()<2)
356 error() <<
"output takes at least two arguments" <<
eom;
372 error() <<
"atomic_begin does not expect an LHS" <<
eom;
376 if(!arguments.empty())
379 error() <<
"atomic_begin takes no arguments" <<
eom;
384 t->source_location=
function.source_location();
396 error() <<
"atomic_end does not expect an LHS" <<
eom;
400 if(!arguments.empty())
403 error() <<
"atomic_end takes no arguments" <<
eom;
408 t->source_location=
function.source_location();
419 error() <<
"do_cpp_new without lhs is yet to be implemented" <<
eom;
425 static_cast<const exprt &
>(rhs.
find(ID_sizeof));
427 bool new_array=rhs.
get(ID_statement)==ID_cpp_new_array;
433 count=
static_cast<const exprt &
>(rhs.
find(ID_size));
442 exprt tmp_symbol_expr;
449 ns.
lookup(new_array?
"__new_array":
"__new").symbol_expr();
454 const typet &return_type=
463 tmp_symbol_expr=tmp_symbol.symbol_expr();
471 new_call.
lhs()=tmp_symbol_expr;
474 convert(new_call, dest, ID_cpp);
481 new_array?
"__placement_new_array":
"__placement_new").symbol_expr();
494 tmp_symbol_expr=tmp_symbol.symbol_expr();
503 new_call.
lhs()=tmp_symbol_expr;
506 for(std::size_t i=0; i<code_type.
parameters().size(); i++)
510 convert(new_call, dest, ID_cpp);
515 error() <<
"cpp_new expected to have 0 or 1 operands" <<
eom;
538 static_cast<const exprt &
>(rhs.
find(ID_initializer));
561 if(src.
id()==ID_typecast)
567 if(src.
id()!=ID_address_of)
570 error() <<
"expected array-pointer as argument" <<
eom;
576 if(src.
op0().
id()!=ID_index)
579 error() <<
"expected array-element as argument" <<
eom;
588 error() <<
"expected array as argument" <<
eom;
602 if(arguments.size()!=2)
605 error() <<
id <<
" expects two arguments" <<
eom;
609 codet array_op_statement(
id);
610 array_op_statement.
operands()=arguments;
615 if(
id == ID_array_equal)
624 if(expr.
id()==ID_typecast)
628 if(expr.
id()==ID_address_of &&
643 if(
function.get_bool(ID_C_invalid_object))
647 const irep_idt &identifier=
function.get_identifier();
653 error() <<
"error: function `" << identifier <<
"' not found" 658 if(symbol->
type.
id()!=ID_code)
661 error() <<
"error: function `" << identifier
662 <<
"' type mismatch: expected code" <<
eom;
667 identifier==
"__VERIFIER_assume")
669 if(arguments.size()!=1)
672 error() <<
"`" << identifier <<
"' expected to have one argument" 678 t->guard=arguments.front();
679 t->source_location=
function.source_location();
680 t->source_location.set(
"user-provided",
true);
683 if(t->guard.type().id()!=ID_bool)
689 error() << identifier <<
" expected not to have LHS" <<
eom;
693 else if(identifier==
"__VERIFIER_error")
695 if(!arguments.empty())
698 error() <<
"`" << identifier <<
"' expected to have no arguments" 705 t->source_location=
function.source_location();
706 t->source_location.set(
"user-provided",
true);
707 t->source_location.set_property_class(ID_assertion);
712 error() << identifier <<
" expected not to have LHS" <<
eom;
720 a->source_location=
function.source_location();
721 a->source_location.set(
"user-provided",
true);
723 else if(identifier==
"assert" &&
724 !
ns.
lookup(identifier).location.get_function().empty())
726 if(arguments.size()!=1)
729 error() <<
"`" << identifier <<
"' expected to have one argument" 735 t->guard=arguments.front();
736 t->source_location=
function.source_location();
737 t->source_location.set(
"user-provided",
true);
738 t->source_location.set_property_class(ID_assertion);
739 t->source_location.set_comment(
743 if(t->guard.type().id()!=ID_bool)
749 error() << identifier <<
" expected not to have LHS" <<
eom;
756 if(arguments.size()!=2)
759 error() <<
"`" << identifier <<
"' expected to have two arguments" 764 bool is_precondition=
771 t->guard=arguments[0];
772 t->source_location=
function.source_location();
776 t->source_location.set_property_class(ID_precondition);
780 t->source_location.set(
782 !
function.source_location().is_built_in());
783 t->source_location.set_property_class(ID_assertion);
786 t->source_location.set_comment(description);
789 if(t->guard.type().id()!=ID_bool)
795 error() << identifier <<
" expected not to have LHS" <<
eom;
801 if(arguments.size()!=1)
804 error() <<
"`" << identifier <<
"' expected to have one argument" 812 error() << identifier <<
" expected not to have LHS" <<
eom;
817 t->source_location=
function.source_location();
818 t->code=
codet(ID_havoc_object);
819 t->code.add_source_location()=
function.source_location();
820 t->code.copy_to_operands(arguments[0]);
824 do_printf(lhs,
function, arguments, dest);
828 do_scanf(lhs,
function, arguments, dest);
831 identifier==
"__CPROVER::input")
836 error() << identifier <<
" expected not to have LHS" <<
eom;
840 do_input(
function, arguments, dest);
843 identifier==
"__CPROVER::output")
848 error() << identifier <<
" expected not to have LHS" <<
eom;
855 identifier==
"__CPROVER::atomic_begin" ||
856 identifier==
"java::org.cprover.CProver.atomicBegin:()V" ||
857 identifier==
"__VERIFIER_atomic_begin")
862 identifier==
"__CPROVER::atomic_end" ||
863 identifier==
"java::org.cprover.CProver.atomicEnd:()V" ||
864 identifier==
"__VERIFIER_atomic_end")
887 if(lhs.
type().
id()==ID_c_bool)
890 rhs.
set(ID_C_identifier, identifier);
896 rhs.
set(ID_C_identifier, identifier);
921 do_array_op(ID_array_equal, lhs,
function, arguments, dest);
925 do_array_op(ID_array_set, lhs,
function, arguments, dest);
929 do_array_op(ID_array_copy, lhs,
function, arguments, dest);
933 do_array_op(ID_array_replace, lhs,
function, arguments, dest);
935 else if(identifier==
"printf")
942 do_printf(lhs,
function, arguments, dest);
944 else if(identifier==
"__assert_fail" ||
945 identifier==
"_assert" ||
946 identifier==
"__assert_c99" ||
947 identifier==
"_wassert")
968 if(arguments.size()!=4 &&
972 error() <<
"`" << identifier <<
"' expected to have four arguments" 982 t->source_location=
function.source_location();
983 t->source_location.set(
"user-provided",
true);
984 t->source_location.set_property_class(ID_assertion);
985 t->source_location.set_comment(description);
988 else if(identifier==
"__assert_rtn" ||
989 identifier==
"__assert")
1000 if(arguments.size()==4)
1005 else if(arguments.size()==3)
1013 error() <<
"`" << identifier <<
"' expected to have four arguments" 1020 t->source_location=
function.source_location();
1021 t->source_location.set(
"user-provided",
true);
1022 t->source_location.set_property_class(ID_assertion);
1023 t->source_location.set_comment(description);
1026 else if(identifier==
"__assert_func")
1031 if(arguments.size()!=4)
1034 error() <<
"`" << identifier <<
"' expected to have four arguments" 1049 description=
"assertion";
1054 t->source_location=
function.source_location();
1055 t->source_location.set(
"user-provided",
true);
1056 t->source_location.set_property_class(ID_assertion);
1057 t->source_location.set_comment(description);
1062 if(arguments.empty())
1065 error() <<
"`" << identifier
1066 <<
"' expected to have at least one argument" <<
eom;
1071 t->source_location=
function.source_location();
1072 t->code.set(ID_statement, ID_fence);
1077 t->code.set(kind,
true);
1080 else if(identifier==
"__builtin_prefetch")
1084 else if(identifier==
"__builtin_unreachable")
1088 else if(identifier==ID_gcc_builtin_va_arg)
1096 if(arguments.size()!=1)
1099 error() <<
"`" << identifier <<
"' expected to have one argument" 1108 ID_gcc_builtin_va_arg_next,
1112 rhs.set(ID_C_va_arg_type,
to_code_type(
function.type()).return_type());
1114 t1->source_location=
function.source_location();
1123 rhs.add_source_location()=
function.source_location();
1125 t2->source_location=
function.source_location();
1129 else if(identifier==
"__builtin_va_copy")
1131 if(arguments.size()!=2)
1134 error() <<
"`" << identifier <<
"' expected to have two arguments" 1145 error() <<
"va_copy argument expected to be lvalue" <<
eom;
1150 t->source_location=
function.source_location();
1153 else if(identifier==
"__builtin_va_start")
1157 if(arguments.size()!=2)
1160 error() <<
"`" << identifier <<
"' expected to have two arguments" 1172 error() <<
"va_start argument expected to be lvalue" <<
eom;
1177 t->source_location=
function.source_location();
1180 else if(identifier==
"__builtin_va_end")
1183 if(arguments.size()!=1)
1186 error() <<
"`" << identifier <<
"' expected to have one argument" 1196 error() <<
"va_end argument expected to be lvalue" <<
eom;
1204 t->source_location=
function.source_location();
1214 else if(identifier==
"__sync_fetch_and_add" ||
1215 identifier==
"__sync_fetch_and_sub" ||
1216 identifier==
"__sync_fetch_and_or" ||
1217 identifier==
"__sync_fetch_and_and" ||
1218 identifier==
"__sync_fetch_and_xor" ||
1219 identifier==
"__sync_fetch_and_nand")
1224 if(arguments.size()<2)
1227 error() <<
"`" << identifier
1228 <<
"' expected to have at least two arguments" <<
eom;
1232 if(arguments[0].type().
id()!=ID_pointer)
1235 error() <<
"`" << identifier <<
"' expected to have pointer argument" 1244 t1->source_location=
function.source_location();
1250 t2->source_location=
function.source_location();
1252 if(t2->code.op0().type()!=t2->code.op1().type())
1253 t2->code.op1().make_typecast(t2->code.op0().type());
1257 identifier==
"__sync_fetch_and_add"?ID_plus:
1258 identifier==
"__sync_fetch_and_sub"?ID_minus:
1259 identifier==
"__sync_fetch_and_or"?ID_bitor:
1260 identifier==
"__sync_fetch_and_and"?ID_bitand:
1261 identifier==
"__sync_fetch_and_xor"?ID_bitxor:
1262 identifier==
"__sync_fetch_and_nand"?ID_bitnand:
1267 if(op_expr.op1().type()!=op_expr.type())
1271 t3->source_location=
function.source_location();
1276 t4->source_location=
function.source_location();
1277 t4->code=
codet(ID_fence);
1278 t4->code.set(ID_WRfence,
true);
1281 t5->source_location=
function.source_location();
1283 else if(identifier==
"__sync_add_and_fetch" ||
1284 identifier==
"__sync_sub_and_fetch" ||
1285 identifier==
"__sync_or_and_fetch" ||
1286 identifier==
"__sync_and_and_fetch" ||
1287 identifier==
"__sync_xor_and_fetch" ||
1288 identifier==
"__sync_nand_and_fetch")
1293 if(arguments.size()<2)
1296 error() <<
"`" << identifier
1297 <<
"' expected to have at least two arguments" <<
eom;
1301 if(arguments[0].type().
id()!=ID_pointer)
1304 error() <<
"`" << identifier
1305 <<
"' expected to have pointer argument" <<
eom;
1313 t1->source_location=
function.source_location();
1316 identifier==
"__sync_add_and_fetch"?ID_plus:
1317 identifier==
"__sync_sub_and_fetch"?ID_minus:
1318 identifier==
"__sync_or_and_fetch"?ID_bitor:
1319 identifier==
"__sync_and_and_fetch"?ID_bitand:
1320 identifier==
"__sync_xor_and_fetch"?ID_bitxor:
1321 identifier==
"__sync_nand_and_fetch"?ID_bitnand:
1326 if(op_expr.op1().type()!=op_expr.type())
1330 t3->source_location=
function.source_location();
1337 t2->source_location=
function.source_location();
1339 if(t2->code.op0().type()!=t2->code.op1().type())
1340 t2->code.op1().make_typecast(t2->code.op0().type());
1345 t4->source_location=
function.source_location();
1346 t4->code=
codet(ID_fence);
1347 t4->code.set(ID_WRfence,
true);
1350 t5->source_location=
function.source_location();
1352 else if(identifier==
"__sync_bool_compare_and_swap")
1366 if(arguments.size()<3)
1369 error() <<
"`" << identifier
1370 <<
"' expected to have at least three arguments" <<
eom;
1374 if(arguments[0].type().
id()!=ID_pointer)
1377 error() <<
"`" << identifier
1378 <<
"' expected to have pointer argument" <<
eom;
1386 t1->source_location=
function.source_location();
1397 t2->source_location=
function.source_location();
1399 if(t2->code.op0().type()!=t2->code.op1().type())
1400 t2->code.op1().make_typecast(t2->code.op0().type());
1404 if_exprt if_expr(equal, arguments[2], deref_ptr, deref_ptr.
type());
1405 if(if_expr.op1().type()!=if_expr.type())
1409 t3->source_location=
function.source_location();
1414 t4->source_location=
function.source_location();
1415 t4->code=
codet(ID_fence);
1416 t4->code.set(ID_WRfence,
true);
1419 t5->source_location=
function.source_location();
1421 else if(identifier==
"__sync_val_compare_and_swap")
1425 if(arguments.size()<3)
1428 error() <<
"`" << identifier
1429 <<
"' expected to have at least three arguments" <<
eom;
1433 if(arguments[0].type().
id()!=ID_pointer)
1436 error() <<
"`" << identifier
1437 <<
"' expected to have pointer argument" <<
eom;
1445 t1->source_location=
function.source_location();
1451 t2->source_location=
function.source_location();
1453 if(t2->code.op0().type()!=t2->code.op1().type())
1454 t2->code.op1().make_typecast(t2->code.op0().type());
1463 if_exprt if_expr(equal, arguments[2], deref_ptr, deref_ptr.
type());
1464 if(if_expr.op1().type()!=if_expr.type())
1468 t3->source_location=
function.source_location();
1473 t4->source_location=
function.source_location();
1474 t4->code=
codet(ID_fence);
1475 t4->code.set(ID_WRfence,
true);
1478 t5->source_location=
function.source_location();
1480 else if(identifier==
"__sync_lock_test_and_set")
1493 else if(identifier==
"__sync_lock_release")
1503 else if(identifier==
"__builtin_isgreater" ||
1504 identifier==
"__builtin_isgreater" ||
1505 identifier==
"__builtin_isgreaterequal" ||
1506 identifier==
"__builtin_isless" ||
1507 identifier==
"__builtin_islessequal" ||
1508 identifier==
"__builtin_islessgreater" ||
1509 identifier==
"__builtin_isunordered")
1513 if(arguments.size()!=2 ||
1520 error() <<
"`" << identifier
1521 <<
"' expected to have two float/double arguments" 1528 bool use_double=arguments[0].type()==
double_type();
1529 if(arguments[0].type()!=arguments[1].type())
1532 new_arguments[1].make_typecast(arguments[0].type());
1535 new_arguments[0].make_typecast(arguments[1].type());
1542 const typet &a_t=new_arguments[0].type();
1549 name+=use_double?
'd':
'f';
1553 new_function.
type()=f_type;
1556 function_call.
lhs()=lhs;
1557 function_call.
function()=new_function;
1558 function_call.
arguments()=new_arguments;
1565 new_symbol.
name=name;
1566 new_symbol.
type=f_type;
1567 new_symbol.
location=
function.source_location();
1579 function_call.
lhs()=lhs;
The type of an expression.
irep_idt get_string_constant(const exprt &expr)
irep_idt name
The unique identifier.
const std::string & id2string(const irep_idt &d)
pointer_typet pointer_type(const typet &subtype)
application of (mathematical) function
void convert(const codet &code, goto_programt &dest, const irep_idt &mode)
converts 'code' and appends the result to 'dest'
Deprecated expression utility functions.
void do_printf(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
const code_typet & to_code_type(const typet &type)
Cast a generic typet to a code_typet.
void copy_to_operands(const exprt &expr)
#define forall_expr(it, expr)
void do_atomic_begin(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
std::vector< parametert > parameterst
void do_atomic_end(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
void destructive_append(goto_programt &p)
Appends the given program, which is destroyed.
virtual void do_function_call_symbol(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
add function calls to function queue for later processing
The trinary if-then-else operator.
bitvector_typet double_type()
unsignedbv_typet size_type()
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
static mstreamt & eom(mstreamt &m)
bool is_lvalue(const exprt &expr)
Returns true iff the argument is (syntactically) an lvalue.
Expression Initialization.
void do_array_op(const irep_idt &id, const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
exprt make_va_list(const exprt &expr)
exprt object_size(const exprt &pointer)
const irep_idt & id() const
class symbol_exprt symbol_expr() const
produces a symbol_exprt for a symbol
void do_input(const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest)
void clean_expr(exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used=true)
virtual void do_cpp_new(const exprt &lhs, const side_effect_exprt &rhs, goto_programt &dest)
A generic base class for binary expressions.
bitvector_typet float_type()
instructionst::iterator targett
const source_locationt & find_source_location() const
source_locationt source_location
Operator to dereference a pointer.
const irep_idt & get(const irep_namet &name) const
void do_output(const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest)
A side effect that returns a non-deterministically chosen value.
bool has_prefix(const std::string &s, const std::string &prefix)
const exprt & size() const
const typet & follow(const typet &) const
void do_prob_uniform(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
bitvector_typet index_type()
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Operator to return the address of an object.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
exprt get_array_argument(const exprt &src)
The boolean constant false.
symbol_exprt & function()
exprt zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns, message_handlert &message_handler)
std::vector< exprt > operandst
const source_locationt & source_location() const
A generic container class for the GOTO intermediate representation of one function.
typet type
Type of symbol.
source_locationt location
Source code location of definition of symbol.
message_handlert & get_message_handler()
void cpp_new_initializer(const exprt &lhs, const side_effect_exprt &rhs, goto_programt &dest)
builds a goto program for object initialization after new
void set_statement(const irep_idt &statement)
targett add_instruction()
Adds an instruction at the end.
const array_typet & to_array_type(const typet &type)
Cast a generic typet to an array_typet.
Base class for all expressions.
const parameterst & parameters() const
irep_idt base_name
Base (non-scoped) name.
void do_prob_coin(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
const source_locationt & source_location() const
symbolt & new_tmp_symbol(const typet &type, const std::string &suffix, goto_programt &dest, const source_locationt &, const irep_idt &mode)
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast a generic exprt to a typecast_exprt.
symbol_table_baset & symbol_table
void set_identifier(const irep_idt &identifier)
source_locationt & add_source_location()
const codet & to_code(const exprt &expr)
Expression to hold a symbol (variable)
void do_scanf(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
Extract class identifier.
void copy(const codet &code, goto_program_instruction_typet type, goto_programt &dest)
A statement in a programming language.
const typet & subtype() const
An expression containing a side effect.
void make_typecast(const typet &_type)
static void replace_new_object(const exprt &object, exprt &dest)
const irept & find(const irep_namet &name) const
const typet & return_type() const
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See namespace_baset::lookup().
void set(const irep_namet &name, const irep_idt &value)
const irep_idt & get_statement() const