38 const irep_idt &identifier =
function.get_identifier();
41 if(arguments.size() != 2)
44 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
51 error() <<
"'" << identifier <<
"' expected to have LHS" <<
eom;
58 if(lhs.
type().
id() != ID_unsignedbv && lhs.
type().
id() != ID_signedbv)
61 error() <<
"'" << identifier <<
"' expected other type" <<
eom;
66 arguments[0].type().
id() != lhs.
type().
id() ||
67 arguments[1].type().id() != lhs.
type().
id())
70 error() <<
"'" << identifier
71 <<
"' expected operands to be of same type as LHS" <<
eom;
78 error() <<
"'" << identifier
79 <<
"' expected operands to be constant literals" <<
eom;
90 error() <<
"error converting operands" <<
eom;
97 error() <<
"expected lower bound to be smaller or equal to the "
98 <<
"upper bound" <<
eom;
102 rhs.add_to_operands(
exprt{arguments[0]},
exprt{arguments[1]});
115 const irep_idt &identifier =
function.get_identifier();
118 if(arguments.size() != 2)
121 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
128 error() <<
"'" << identifier <<
"' expected to have LHS" <<
eom;
137 error() <<
"'" << identifier <<
"' expected bool" <<
eom;
141 if(arguments[0].type().
id() != ID_unsignedbv || !arguments[0].
is_constant())
144 error() <<
"'" << identifier <<
"' expected first operand to be "
145 <<
"a constant literal of type unsigned long" <<
eom;
149 if(arguments[1].type().
id() != ID_unsignedbv || !arguments[1].
is_constant())
152 error() <<
"'" << identifier <<
"' expected second operand to be "
153 <<
"a constant literal of type unsigned long" <<
eom;
164 error() <<
"error converting operands" <<
eom;
171 error() <<
"probability has to be smaller than 1" <<
eom;
178 error() <<
"denominator may not be zero" <<
eom;
182 rationalt numerator(num), denominator(den);
183 rationalt prob = numerator / denominator;
198 const irep_idt &f_id =
function.get_identifier();
202 codet printf_code(ID_printf, arguments,
function.source_location());
212 const irep_idt &f_id =
function.get_identifier();
216 if(arguments.empty())
219 error() <<
"scanf takes at least one argument" <<
eom;
231 std::size_t argument_number = 1;
233 for(
const auto &t : token_list)
239 if(argument_number < arguments.size())
245 if(type->id() == ID_array)
254 *type,
"scanf_string", dest,
function.source_location());
262 codet array_copy_statement;
264 array_copy_statement.
operands().resize(2);
265 array_copy_statement.
op0()=ptr;
266 \ array_copy_statement.
op1()=rhs;
268 function.source_location();
287 *type,
function.source_location());
310 const exprt &
function,
314 if(arguments.size() < 2)
317 error() <<
"input takes at least two arguments" <<
eom;
325 const exprt &
function,
329 if(arguments.size() < 2)
332 error() <<
"output takes at least two arguments" <<
eom;
348 error() <<
"atomic_begin does not expect an LHS" <<
eom;
352 if(!arguments.empty())
355 error() <<
"atomic_begin takes no arguments" <<
eom;
371 error() <<
"atomic_end does not expect an LHS" <<
eom;
375 if(!arguments.empty())
378 error() <<
"atomic_end takes no arguments" <<
eom;
393 error() <<
"do_cpp_new without lhs is yet to be implemented" <<
eom;
400 bool new_array = rhs.
get(ID_statement) == ID_cpp_new_array;
413 exprt tmp_symbol_expr;
420 ns.
lookup(new_array ?
"__new_array" :
"__new").symbol_expr();
428 "new has one or two parameters");
441 new_call.
lhs() = tmp_symbol_expr;
444 convert(new_call, dest, ID_cpp);
450 ns.
lookup(new_array ?
"__placement_new_array" :
"__placement_new")
459 "placement new has two or three parameters");
473 new_call.
lhs() = tmp_symbol_expr;
476 for(std::size_t i = 0; i < code_type.
parameters().size(); i++)
482 convert(new_call, dest, ID_cpp);
487 error() <<
"cpp_new expected to have 0 or 1 operands" <<
eom;
509 exprt initializer =
static_cast<const exprt &
>(rhs.
find(ID_initializer));
533 if(src.
id() == ID_typecast)
536 if(src.
id() != ID_address_of)
539 error() <<
"expected array-pointer as argument" <<
eom;
545 if(address_of_expr.object().id() != ID_index)
548 error() <<
"expected array-element as argument" <<
eom;
552 const auto &index_expr =
to_index_expr(address_of_expr.object());
554 if(index_expr.array().type().id() != ID_array)
557 error() <<
"expected array as argument" <<
eom;
561 return index_expr.array();
571 if(arguments.size() != 2)
574 error() <<
id <<
" expects two arguments" <<
eom;
578 codet array_op_statement(
id);
579 array_op_statement.
operands() = arguments;
584 if(
id == ID_array_equal)
595 if(result.
id() == ID_address_of)
599 result = address_of_expr.object();
602 while(result.
type().
id() == ID_array &&
622 auto source_location =
function.find_source_location();
623 source_location.add_pragma(
"disable:pointer-check");
624 source_location.add_pragma(
"disable:pointer-overflow-check");
625 source_location.add_pragma(
"disable:pointer-primitive-check");
628 if(arguments.size() != 2)
631 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
636 if(arguments[0].type().
id() != ID_pointer)
639 error() <<
"'" << identifier
640 <<
"' first argument expected to have `void *` type" <<
eom;
644 if(arguments[1].type().
id() != ID_unsignedbv)
647 error() <<
"'" << identifier
648 <<
"' second argument expected to have `size_t` type" <<
eom;
656 error() <<
"'" << identifier <<
"' not expected to have a LHS" <<
eom;
668 annotated_location.
set(
"user-provided",
false);
671 "assertion havoc_slice " +
from_expr(
ns, identifier, ok_expr));
676 const symbolt &nondet_contents =
677 new_tmp_symbol(array_type,
"nondet_contents", dest, source_location, mode);
686 codet array_replace(ID_array_replace, {arg0, arg1}, source_location);
705 error() <<
"'alloca' function called, but 'alloca' has not been declared "
706 <<
"with expected 'void *' return type." <<
eom;
710 alloca_type.parameters().size() != 1 ||
711 alloca_type.parameters()[0].type() !=
size_type())
714 error() <<
"'alloca' function called, but 'alloca' has not been declared "
715 <<
"with expected single 'size_t' parameter." <<
eom;
727 alloca_type.return_type(),
"alloca", dest, source_location, mode)
741 function.source_location().get_function() ==
"alloca" || !
targets.
prefix ||
752 alloca_type.return_type(),
753 id2string(
function.source_location().get_function()),
774 this_alloca_ptr, std::move(rhs), source_location));
780 exprt alloca_result =
787 std::move(alloca_result)};
789 std::move(dead_object_sym), std::move(not_null), source_location);
805 if(
function.get_bool(ID_C_invalid_object))
809 const irep_idt &identifier =
function.get_identifier();
815 error() <<
"function '" << identifier <<
"' not found" <<
eom;
819 if(symbol->
type.
id() != ID_code)
822 error() <<
"function '" << identifier <<
"' type mismatch: expected code"
860 identifier ==
CPROVER_PREFIX "assume" || identifier ==
"__VERIFIER_assume")
862 if(arguments.size() != 1)
865 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
871 annotated_location.
set(
"user-provided",
true);
874 annotated_location));
879 error() << identifier <<
" expected not to have LHS" <<
eom;
883 else if(identifier ==
"__VERIFIER_error")
885 if(!arguments.empty())
888 error() <<
"'" << identifier <<
"' expected to have no arguments" <<
eom;
893 annotated_location.
set(
"user-provided",
true);
900 error() << identifier <<
" expected not to have LHS" <<
eom;
906 annotated_location =
function.source_location();
907 annotated_location.
set(
"user-provided",
true);
909 dest.
instructions.back().labels.push_back(
"__VERIFIER_abort");
912 identifier ==
"assert" &&
915 if(arguments.size() != 1)
918 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
924 annotated_location.
set(
"user-provided",
true);
927 "assertion " +
from_expr(
ns, identifier, arguments.front()));
930 annotated_location));
935 error() << identifier <<
" expected not to have LHS" <<
eom;
944 if(arguments.size() != 2)
947 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
951 bool is_precondition = identifier ==
CPROVER_PREFIX "precondition";
952 bool is_postcondition = identifier ==
CPROVER_PREFIX "postcondition";
962 else if(is_postcondition)
968 annotated_location.
set(
969 "user-provided", !
function.source_location().is_built_in());
977 annotated_location));
982 error() << identifier <<
" expected not to have LHS" <<
eom;
988 if(arguments.size() != 1)
991 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
998 error() << identifier <<
" expected not to have LHS" <<
eom;
1002 codet havoc(ID_havoc_object);
1010 do_printf(lhs,
function, arguments, dest);
1014 do_scanf(lhs,
function, arguments, dest);
1017 identifier ==
CPROVER_PREFIX "input" || identifier ==
"__CPROVER::input")
1022 error() << identifier <<
" expected not to have LHS" <<
eom;
1026 do_input(
function, arguments, dest);
1029 identifier ==
CPROVER_PREFIX "output" || identifier ==
"__CPROVER::output")
1034 error() << identifier <<
" expected not to have LHS" <<
eom;
1042 identifier ==
"__CPROVER::atomic_begin" ||
1043 identifier ==
"java::org.cprover.CProver.atomicBegin:()V" ||
1044 identifier ==
"__VERIFIER_atomic_begin")
1050 identifier ==
"__CPROVER::atomic_end" ||
1051 identifier ==
"java::org.cprover.CProver.atomicEnd:()V" ||
1052 identifier ==
"__VERIFIER_atomic_end")
1076 if(lhs.
type().
id() == ID_c_bool)
1079 rhs.
set(ID_C_identifier, identifier);
1085 rhs.
set(ID_C_identifier, identifier);
1098 if(
function.type().get_bool(ID_C_incomplete))
1101 error() <<
"'" << identifier <<
"' is not declared, "
1102 <<
"missing type information required to construct call to "
1103 <<
"uninterpreted function" <<
eom;
1109 for(
const auto ¶meter : function_call_type.
parameters())
1110 domain.push_back(parameter.type());
1117 assignment.add_source_location() =
function.source_location();
1122 do_array_op(ID_array_equal, lhs,
function, arguments, dest);
1126 do_array_op(ID_array_set, lhs,
function, arguments, dest);
1130 do_array_op(ID_array_copy, lhs,
function, arguments, dest);
1134 do_array_op(ID_array_replace, lhs,
function, arguments, dest);
1137 identifier ==
"__assert_fail" || identifier ==
"_assert" ||
1138 identifier ==
"__assert_c99" || identifier ==
"_wassert")
1159 if(arguments.size() != 4 && arguments.size() != 3)
1162 error() <<
"'" << identifier <<
"' expected to have four arguments"
1171 annotated_location.
set(
"user-provided",
true);
1177 else if(identifier ==
"__assert_rtn" || identifier ==
"__assert")
1188 if(arguments.size() == 4)
1192 else if(arguments.size() == 3)
1199 error() <<
"'" << identifier <<
"' expected to have four arguments"
1205 annotated_location.
set(
"user-provided",
true);
1212 identifier ==
"__assert_func" || identifier ==
"__assert2" ||
1213 identifier ==
"__assert13")
1220 if(arguments.size() != 4)
1223 error() <<
"'" << identifier <<
"' expected to have four arguments"
1238 description =
"assertion";
1242 annotated_location.
set(
"user-provided",
true);
1250 if(arguments.empty())
1253 error() <<
"'" << identifier <<
"' expected to have at least one argument"
1258 codet fence(ID_fence);
1260 for(
const auto &argument : arguments)
1265 else if(identifier ==
"__builtin_prefetch")
1269 else if(identifier ==
"__builtin_unreachable")
1273 else if(identifier == ID_gcc_builtin_va_arg)
1281 if(arguments.size() != 1)
1284 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
1292 exprt list_arg_cast = list_arg;
1294 list_arg.
type().
id() == ID_pointer &&
1312 ID_C_va_arg_type,
to_code_type(
function.type()).return_type());
1314 std::move(assign),
function.source_location()));
1316 else if(identifier ==
"__builtin_va_copy")
1318 if(arguments.size() != 2)
1321 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
1331 error() <<
"va_copy argument expected to be lvalue" <<
eom;
1336 dest_expr, src_expr,
function.source_location()));
1338 else if(identifier ==
"__builtin_va_start" || identifier ==
"__va_start")
1342 if(arguments.size() != 2)
1345 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
1354 error() <<
"va_start argument expected to be lvalue" <<
eom;
1359 dest_expr.
type().
id() == ID_pointer &&
1368 rhs.add_to_operands(
1372 std::move(dest_expr), std::move(rhs),
function.source_location()));
1374 else if(identifier ==
"__builtin_va_end")
1377 if(arguments.size() != 1)
1380 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
1389 error() <<
"va_end argument expected to be lvalue" <<
eom;
1394 if(dest_expr.
type().
id() == ID_pointer)
1400 dest_expr, *zero,
function.source_location()));
1404 identifier ==
"__builtin_isgreater" ||
1405 identifier ==
"__builtin_isgreaterequal" ||
1406 identifier ==
"__builtin_isless" || identifier ==
"__builtin_islessequal" ||
1407 identifier ==
"__builtin_islessgreater" ||
1408 identifier ==
"__builtin_isunordered")
1413 arguments.size() != 2 ||
1420 error() <<
"'" << identifier
1421 <<
"' expected to have two float/double arguments" <<
eom;
1427 bool use_double = arguments[0].type() ==
double_type();
1428 if(arguments[0].type() != arguments[1].type())
1445 const typet &a_t = new_arguments[0].type();
1452 name += use_double ?
'd' :
'f';
1456 "builtin declaration should match constructed type");
1460 new_function.
type() = f_type;
1467 else if(identifier ==
"alloca" || identifier ==
"__builtin_alloca")
1469 do_alloca(lhs,
function, arguments, dest, mode);
exprt make_va_list(const exprt &expr)
floatbv_typet float_type()
signedbv_typet signed_int_type()
pointer_typet pointer_type(const typet &subtype)
signedbv_typet pointer_diff_type()
bitvector_typet char_type()
bitvector_typet c_index_type()
floatbv_typet double_type()
Operator to return the address of an object.
const typet & element_type() const
The type of the elements of the array.
const exprt & size() const
A goto_instruction_codet representing an assignment in the program.
goto_instruction_codet representation of a function call statement.
A goto_instruction_codet representing the declaration that an output of a particular description has ...
std::vector< parametert > parameterst
const typet & return_type() const
const parameterst & parameters() const
Data structure for representing an arbitrary statement in a program.
void set_statement(const irep_idt &statement)
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
bool starts_with(const char *s) const
equivalent of as_string().starts_with(s)
Base class for all expressions.
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
std::vector< exprt > operandst
bool is_one() const
Return whether the expression is a constant representing 1.
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
source_locationt & add_source_location()
const source_locationt & source_location() const
typet & type()
Return the type of the expression.
The Boolean constant false.
Application of (mathematical) function.
void do_havoc_slice(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest, const irep_idt &mode)
symbol_table_baset & symbol_table
void do_input(const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest)
void do_array_op(const irep_idt &id, const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
irep_idt get_string_constant(const exprt &expr)
void copy(const codet &code, goto_program_instruction_typet type, goto_programt &dest)
void do_prob_coin(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
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)
void do_atomic_end(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
virtual void do_function_call_symbol(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest, const irep_idt &mode)
add function calls to function queue for later processing
void clean_expr(exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used=true)
void do_output(const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest)
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 do_printf(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
exprt get_array_argument(const exprt &src)
void do_alloca(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest, const irep_idt &mode)
alloca allocates memory that is freed when leaving the function (and not the block,...
void do_scanf(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
void convert(const codet &code, goto_programt &dest, const irep_idt &mode)
converts 'code' and appends the result to 'dest'
void do_atomic_begin(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
static void replace_new_object(const exprt &object, exprt &dest)
virtual void do_cpp_new(const exprt &lhs, const side_effect_exprt &rhs, goto_programt &dest)
void do_prob_uniform(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
instructionst instructions
The list of instructions in the goto program.
static instructiont make_dead(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
void destructive_insert(const_targett target, goto_programt &p)
Inserts the given program p before target.
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
static instructiont make_atomic_end(const source_locationt &l=source_locationt::nil())
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
targett insert_after(const_targett target)
Insertion after the instruction pointed-to by the given instruction iterator target.
static instructiont make_other(const goto_instruction_codet &_code, const source_locationt &l=source_locationt::nil())
static instructiont make_atomic_begin(const source_locationt &l=source_locationt::nil())
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
The trinary if-then-else operator.
bool get_bool(const irep_idt &name) const
const irept & find(const irep_idt &name) const
const irep_idt & get(const irep_idt &name) const
void set(const irep_idt &name, const irep_idt &value)
const irep_idt & id() const
A type for mathematical functions (do not confuse with functions/methods in code)
std::vector< typet > domaint
source_locationt source_location
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
The null pointer constant.
The plus expression Associativity is not specified.
const typet & base_type() const
The type of the data what we point to.
A base class for a predicate that indicates that an address range is ok to read or write or both.
A side_effect_exprt that returns a non-deterministically chosen value.
An expression containing a side effect.
const irep_idt & get_statement() const
void set_comment(const irep_idt &comment)
void set_property_class(const irep_idt &property_class)
Expression to hold a symbol (variable)
void set_identifier(const irep_idt &identifier)
symbol_exprt & with_source_location(source_locationt location) &
Add the source location from location, if it is non-nil.
const irep_idt & get_identifier() const
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
exprt value
Initial value of symbol.
const typet & subtype() const
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
const source_locationt & source_location() const
source_locationt & add_source_location()
const exprt & op1() const =delete
std::optional< exprt > zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create the equivalent of zero for type type.
Expression Initialization.
bool is_assignable(const exprt &expr)
Returns true iff the argument is one of the following:
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
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.
const std::string & id2string(const irep_idt &d)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
API to expression classes for 'mathematical' expressions.
API to expression classes for Pointers.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
exprt object_size(const exprt &pointer)
exprt simplify_expr(exprt src, const namespacet &ns)
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
const codet & to_code(const exprt &expr)
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
bool is_constant(const typet &type)
This method tests, if the given typet is a constant.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const type_with_subtypet & to_type_with_subtype(const typet &type)