Go to the documentation of this file.
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 &&
59 lhs.
type().
id()!=ID_signedbv)
62 error() <<
"'" << identifier <<
"' expected other type" <<
eom;
66 if(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;
79 error() <<
"'" << identifier
80 <<
"' expected operands to be constant literals" <<
eom;
91 error() <<
"error converting operands" <<
eom;
98 error() <<
"expected lower bound to be smaller or equal to the "
99 <<
"upper bound" <<
eom;
103 rhs.copy_to_operands(arguments[0], arguments[1]);
116 const irep_idt &identifier =
function.get_identifier();
119 if(arguments.size()!=2)
122 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
129 error() <<
"'" << identifier <<
"' expected to have LHS" <<
eom;
138 error() <<
"'" << identifier <<
"' expected bool" <<
eom;
142 if(arguments[0].type().
id()!=ID_unsignedbv ||
143 arguments[0].
id()!=ID_constant)
146 error() <<
"'" << identifier <<
"' expected first operand to be "
147 <<
"a constant literal of type unsigned long" <<
eom;
152 arguments[1].type().
id() != ID_unsignedbv ||
153 arguments[1].
id() != ID_constant)
156 error() <<
"'" << identifier <<
"' expected second operand to be "
157 <<
"a constant literal of type unsigned long" <<
eom;
168 error() <<
"error converting operands" <<
eom;
175 error() <<
"probability has to be smaller than 1" <<
eom;
182 error() <<
"denominator may not be zero" <<
eom;
186 rationalt numerator(num), denominator(den);
187 rationalt prob = numerator / denominator;
202 const irep_idt &f_id =
function.get_identifier();
206 codet printf_code(ID_printf, arguments,
function.source_location());
216 const irep_idt &f_id =
function.get_identifier();
220 if(arguments.empty())
223 error() <<
"scanf takes at least one argument" <<
eom;
235 std::size_t argument_number=1;
237 for(
const auto &t : token_list)
243 if(argument_number<arguments.size())
249 if(type->id() == ID_array)
258 *type,
"scanf_string", dest,
function.source_location());
266 codet array_copy_statement;
268 array_copy_statement.
operands().resize(2);
269 array_copy_statement.
op0()=ptr;
270 \ array_copy_statement.
op1()=rhs;
272 function.source_location();
279 type->subtype(),
function.source_location());
290 *type,
function.source_location());
313 const exprt &
function,
317 if(arguments.size()<2)
320 error() <<
"input takes at least two arguments" <<
eom;
328 const exprt &
function,
332 if(arguments.size()<2)
335 error() <<
"output takes at least two arguments" <<
eom;
351 error() <<
"atomic_begin does not expect an LHS" <<
eom;
355 if(!arguments.empty())
358 error() <<
"atomic_begin takes no arguments" <<
eom;
374 error() <<
"atomic_end does not expect an LHS" <<
eom;
378 if(!arguments.empty())
381 error() <<
"atomic_end takes no arguments" <<
eom;
396 error() <<
"do_cpp_new without lhs is yet to be implemented" <<
eom;
402 static_cast<const exprt &
>(rhs.
find(ID_sizeof));
404 bool new_array=rhs.
get(ID_statement)==ID_cpp_new_array;
417 exprt tmp_symbol_expr;
424 ns.
lookup(new_array?
"__new_array":
"__new").symbol_expr();
429 const typet &return_type=
445 new_call.
lhs()=tmp_symbol_expr;
448 convert(new_call, dest, ID_cpp);
455 new_array?
"__placement_new_array":
"__placement_new").symbol_expr();
476 new_call.
lhs()=tmp_symbol_expr;
479 for(std::size_t i=0; i<code_type.
parameters().size(); i++)
485 convert(new_call, dest, ID_cpp);
490 error() <<
"cpp_new expected to have 0 or 1 operands" <<
eom;
513 static_cast<const exprt &
>(rhs.
find(ID_initializer));
536 if(src.
id()==ID_typecast)
539 if(src.
id()!=ID_address_of)
542 error() <<
"expected array-pointer as argument" <<
eom;
548 if(address_of_expr.object().id() != ID_index)
551 error() <<
"expected array-element as argument" <<
eom;
555 const auto &index_expr =
to_index_expr(address_of_expr.object());
557 if(index_expr.array().type().id() != ID_array)
560 error() <<
"expected array as argument" <<
eom;
564 return index_expr.array();
574 if(arguments.size()!=2)
577 error() <<
id <<
" expects two arguments" <<
eom;
581 codet array_op_statement(
id);
582 array_op_statement.
operands()=arguments;
587 if(
id == ID_array_equal)
598 if(result.
id() == ID_address_of)
602 result = address_of_expr.object();
605 while(result.
type().
id() == ID_array &&
621 if(
function.get_bool(ID_C_invalid_object))
625 const irep_idt &identifier=
function.get_identifier();
631 error() <<
"error: function '" << identifier <<
"' not found" <<
eom;
635 if(symbol->
type.
id()!=ID_code)
638 error() <<
"error: function '" << identifier
639 <<
"' type mismatch: expected code" <<
eom;
660 identifier==
"__VERIFIER_assume")
662 if(arguments.size()!=1)
665 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
672 function.source_location()));
674 t->source_location.set(
"user-provided",
true);
679 error() << identifier <<
" expected not to have LHS" <<
eom;
683 else if(identifier==
"__VERIFIER_error")
685 if(!arguments.empty())
688 error() <<
"'" << identifier <<
"' expected to have no arguments" <<
eom;
695 t->source_location.set(
"user-provided",
true);
696 t->source_location.set_property_class(ID_assertion);
701 error() << identifier <<
" expected not to have LHS" <<
eom;
709 a->source_location.set(
"user-provided",
true);
712 identifier ==
"assert" &&
715 if(arguments.size()!=1)
718 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
725 function.source_location()));
726 t->source_location.set(
"user-provided",
true);
727 t->source_location.set_property_class(ID_assertion);
728 t->source_location.set_comment(
729 "assertion " +
from_expr(
ns, identifier, arguments.front()));
734 error() << identifier <<
" expected not to have LHS" <<
eom;
743 if(arguments.size()!=2)
746 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
750 bool is_precondition=
752 bool is_postcondition = identifier ==
CPROVER_PREFIX "postcondition";
760 function.source_location()));
764 t->source_location.set_property_class(ID_precondition);
766 else if(is_postcondition)
768 t->source_location.set_property_class(ID_postcondition);
772 t->source_location.set(
774 !
function.source_location().is_built_in());
775 t->source_location.set_property_class(ID_assertion);
778 t->source_location.set_comment(description);
783 error() << identifier <<
" expected not to have LHS" <<
eom;
789 if(arguments.size()!=1)
792 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
799 error() << identifier <<
" expected not to have LHS" <<
eom;
803 codet havoc(ID_havoc_object);
811 do_printf(lhs,
function, arguments, dest);
815 do_scanf(lhs,
function, arguments, dest);
818 identifier==
"__CPROVER::input")
823 error() << identifier <<
" expected not to have LHS" <<
eom;
827 do_input(
function, arguments, dest);
830 identifier==
"__CPROVER::output")
835 error() << identifier <<
" expected not to have LHS" <<
eom;
842 identifier==
"__CPROVER::atomic_begin" ||
843 identifier==
"java::org.cprover.CProver.atomicBegin:()V" ||
844 identifier==
"__VERIFIER_atomic_begin")
849 identifier==
"__CPROVER::atomic_end" ||
850 identifier==
"java::org.cprover.CProver.atomicEnd:()V" ||
851 identifier==
"__VERIFIER_atomic_end")
874 if(lhs.
type().
id()==ID_c_bool)
877 rhs.
set(ID_C_identifier, identifier);
883 rhs.
set(ID_C_identifier, identifier);
904 do_array_op(ID_array_equal, lhs,
function, arguments, dest);
908 do_array_op(ID_array_set, lhs,
function, arguments, dest);
912 do_array_op(ID_array_copy, lhs,
function, arguments, dest);
916 do_array_op(ID_array_replace, lhs,
function, arguments, dest);
918 else if(identifier==
"__assert_fail" ||
919 identifier==
"_assert" ||
920 identifier==
"__assert_c99" ||
921 identifier==
"_wassert")
942 if(arguments.size()!=4 &&
946 error() <<
"'" << identifier <<
"' expected to have four arguments"
957 t->source_location.set(
"user-provided",
true);
958 t->source_location.set_property_class(ID_assertion);
959 t->source_location.set_comment(description);
962 else if(identifier==
"__assert_rtn" ||
963 identifier==
"__assert")
974 if(arguments.size()==4)
979 else if(arguments.size()==3)
987 error() <<
"'" << identifier <<
"' expected to have four arguments"
995 t->source_location.set(
"user-provided",
true);
996 t->source_location.set_property_class(ID_assertion);
997 t->source_location.set_comment(description);
1000 else if(identifier==
"__assert_func")
1005 if(arguments.size()!=4)
1008 error() <<
"'" << identifier <<
"' expected to have four arguments"
1023 description=
"assertion";
1029 t->source_location.set(
"user-provided",
true);
1030 t->source_location.set_property_class(ID_assertion);
1031 t->source_location.set_comment(description);
1036 if(arguments.empty())
1039 error() <<
"'" << identifier <<
"' expected to have at least one argument"
1044 codet fence(ID_fence);
1051 else if(identifier==
"__builtin_prefetch")
1055 else if(identifier==
"__builtin_unreachable")
1059 else if(identifier==ID_gcc_builtin_va_arg)
1067 if(arguments.size()!=1)
1070 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
1078 exprt list_arg_cast = list_arg;
1080 list_arg.
type().
id() == ID_pointer &&
1098 ID_C_va_arg_type,
to_code_type(
function.type()).return_type());
1100 std::move(assign),
function.source_location()));
1102 else if(identifier==
"__builtin_va_copy")
1104 if(arguments.size()!=2)
1107 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
1117 error() <<
"va_copy argument expected to be lvalue" <<
eom;
1122 dest_expr, src_expr,
function.source_location()));
1124 else if(identifier ==
"__builtin_va_start" || identifier ==
"__va_start")
1128 if(arguments.size()!=2)
1131 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
1140 error() <<
"va_start argument expected to be lvalue" <<
eom;
1145 dest_expr.
type().
id() == ID_pointer &&
1154 rhs.add_to_operands(
1158 std::move(dest_expr), std::move(rhs),
function.source_location()));
1160 else if(identifier==
"__builtin_va_end")
1163 if(arguments.size()!=1)
1166 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
1175 error() <<
"va_end argument expected to be lvalue" <<
eom;
1180 if(dest_expr.
type().
id() == ID_pointer)
1186 dest_expr, *zero,
function.source_location()));
1190 identifier ==
"__builtin_isgreater" ||
1191 identifier ==
"__builtin_isgreaterequal" ||
1192 identifier ==
"__builtin_isless" || identifier ==
"__builtin_islessequal" ||
1193 identifier ==
"__builtin_islessgreater" ||
1194 identifier ==
"__builtin_isunordered")
1198 if(arguments.size()!=2 ||
1205 error() <<
"'" << identifier
1206 <<
"' expected to have two float/double arguments" <<
eom;
1212 bool use_double=arguments[0].type()==
double_type();
1213 if(arguments[0].type()!=arguments[1].type())
1230 const typet &a_t=new_arguments[0].type();
1237 name+=use_double?
'd':
'f';
1241 new_function.
type()=f_type;
1250 new_symbol.
name=name;
1251 new_symbol.
type=f_type;
1252 new_symbol.
location=
function.source_location();
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
#define UNREACHABLE
This should be used to mark dead code.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
static exprt conditional_cast(const exprt &expr, const typet &type)
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
virtual void do_cpp_new(const exprt &lhs, const side_effect_exprt &rhs, goto_programt &dest)
const typet & subtype() const
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
void do_output(const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest)
static void replace_new_object(const exprt &object, exprt &dest)
void convert(const codet &code, goto_programt &dest, const irep_idt &mode)
converts 'code' and appends the result to 'dest'
void copy(const codet &code, goto_program_instruction_typet type, goto_programt &dest)
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
std::vector< parametert > parameterst
void clean_expr(exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used=true)
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
exprt get_array_argument(const exprt &src)
void cpp_new_initializer(const exprt &lhs, const side_effect_exprt &rhs, goto_programt &dest)
builds a goto program for object initialization after new
typet type
Type of symbol.
Operator to dereference a pointer.
void do_atomic_end(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
const irept & find(const irep_namet &name) const
targett add(instructiont &&instruction)
Adds a given instruction at the end.
The plus expression Associativity is not specified.
Base class for all expressions.
const exprt & op1() const =delete
irep_idt base_name
Base (non-scoped) name.
Expression to hold a symbol (variable)
bitvector_typet index_type()
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
optionalt< exprt > zero_initializer(const typet &type, const source_locationt &source_location, const namespacet &ns)
Create the equivalent of zero for type type.
symbolt & new_tmp_symbol(const typet &type, const std::string &suffix, goto_programt &dest, const source_locationt &, const irep_idt &mode)
const codet & to_code(const exprt &expr)
const exprt & size() const
A codet representing the declaration that an output of a particular description has a value which cor...
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
codet representation of a function call statement.
bool get_bool(const irep_namet &name) const
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Expression Initialization.
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
signedbv_typet signed_int_type()
void do_scanf(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
const std::string & id2string(const irep_idt &d)
source_locationt source_location
irep_idt get_string_constant(const exprt &expr)
#define PRECONDITION(CONDITION)
const source_locationt & source_location() const
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
floatbv_typet float_type()
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
Application of (mathematical) function.
pointer_typet pointer_type(const typet &subtype)
static instructiont make_atomic_begin(const source_locationt &l=source_locationt::nil())
exprt object_size(const exprt &pointer)
const irep_idt & id() const
std::vector< exprt > operandst
The Boolean constant false.
const parameterst & parameters() const
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
source_locationt & add_source_location()
floatbv_typet double_type()
const irep_idt & get_statement() const
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
A side_effect_exprt that returns a non-deterministically chosen value.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
Deprecated expression utility functions.
exprt value
Initial value of symbol.
void do_input(const exprt &rhs, const exprt::operandst &arguments, goto_programt &dest)
void do_printf(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
void do_atomic_begin(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
const irep_idt & get(const irep_namet &name) const
source_locationt location
Source code location of definition of symbol.
void set(const irep_namet &name, const irep_idt &value)
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
static instructiont make_other(const codet &_code, const source_locationt &l=source_locationt::nil())
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
A generic container class for the GOTO intermediate representation of one function.
void do_array_op(const irep_idt &id, const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
Extract class identifier.
symbol_table_baset & symbol_table
bool is_one() const
Return whether the expression is a constant representing 1.
const typet & return_type() const
bool has_prefix(const std::string &s, const std::string &prefix)
void set_statement(const irep_idt &statement)
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
#define forall_expr(it, expr)
Operator to return the address of an object.
source_locationt & add_source_location()
Semantic type conversion.
signedbv_typet pointer_diff_type()
unsignedbv_typet size_type()
A codet representing an assignment in the program.
bool is_constant(const typet &type)
This method tests, if the given typet is a constant.
const source_locationt & source_location() const
exprt make_va_list(const exprt &expr)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
void set_identifier(const irep_idt &identifier)
irep_idt name
The unique identifier.
instructionst::iterator targett
An expression containing a side effect.
void do_prob_uniform(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
void do_prob_coin(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
static instructiont make_atomic_end(const source_locationt &l=source_locationt::nil())
bool is_lvalue(const exprt &expr)
Returns true iff the argument is (syntactically) an lvalue.
API to expression classes for 'mathematical' expressions.
Data structure for representing an arbitrary statement in a program.
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.