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();
291 *type,
function.source_location());
314 const exprt &
function,
318 if(arguments.size()<2)
321 error() <<
"input takes at least two arguments" <<
eom;
329 const exprt &
function,
333 if(arguments.size()<2)
336 error() <<
"output takes at least two arguments" <<
eom;
352 error() <<
"atomic_begin does not expect an LHS" <<
eom;
356 if(!arguments.empty())
359 error() <<
"atomic_begin takes no arguments" <<
eom;
375 error() <<
"atomic_end does not expect an LHS" <<
eom;
379 if(!arguments.empty())
382 error() <<
"atomic_end takes no arguments" <<
eom;
397 error() <<
"do_cpp_new without lhs is yet to be implemented" <<
eom;
403 static_cast<const exprt &
>(rhs.
find(ID_sizeof));
405 bool new_array=rhs.
get(ID_statement)==ID_cpp_new_array;
418 exprt tmp_symbol_expr;
425 ns.
lookup(new_array?
"__new_array":
"__new").symbol_expr();
430 const typet &return_type=
447 new_call.
lhs()=tmp_symbol_expr;
450 convert(new_call, dest, ID_cpp);
457 new_array?
"__placement_new_array":
"__placement_new").symbol_expr();
479 new_call.
lhs()=tmp_symbol_expr;
482 for(std::size_t i=0; i<code_type.
parameters().size(); i++)
488 convert(new_call, dest, ID_cpp);
493 error() <<
"cpp_new expected to have 0 or 1 operands" <<
eom;
516 static_cast<const exprt &
>(rhs.
find(ID_initializer));
540 if(src.
id()==ID_typecast)
543 if(src.
id()!=ID_address_of)
546 error() <<
"expected array-pointer as argument" <<
eom;
552 if(address_of_expr.object().id() != ID_index)
555 error() <<
"expected array-element as argument" <<
eom;
559 const auto &index_expr =
to_index_expr(address_of_expr.object());
561 if(index_expr.array().type().id() != ID_array)
564 error() <<
"expected array as argument" <<
eom;
568 return index_expr.array();
578 if(arguments.size()!=2)
581 error() <<
id <<
" expects two arguments" <<
eom;
585 codet array_op_statement(
id);
586 array_op_statement.
operands()=arguments;
591 if(
id == ID_array_equal)
602 if(result.
id() == ID_address_of)
606 result = address_of_expr.object();
609 while(result.
type().
id() == ID_array &&
625 const auto enum_expr = arguments.front();
626 const auto enum_type =
627 type_try_dynamic_cast<c_enum_tag_typet>(enum_expr.type());
633 for(
const auto &enum_value : enum_values)
636 disjuncts.push_back(
equal_exprt(enum_expr, std::move(val)));
655 auto source_location =
function.find_source_location();
656 source_location.add_pragma(
"disable:pointer-check");
657 source_location.add_pragma(
"disable:pointer-overflow-check");
658 source_location.add_pragma(
"disable:pointer-primitive-check");
661 if(arguments.size() != 2)
664 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
669 if(arguments[0].type().
id() != ID_pointer)
672 error() <<
"'" << identifier
673 <<
"' first argument expected to have `void *` type" <<
eom;
677 if(arguments[1].type().
id() != ID_unsignedbv)
680 error() <<
"'" << identifier
681 <<
"' second argument expected to have `size_t` type" <<
eom;
689 error() <<
"'" << identifier <<
"' not expected to have a LHS" <<
eom;
702 t->source_location_nonconst().set(
"user-provided",
false);
703 t->source_location_nonconst().set_property_class(ID_assertion);
704 t->source_location_nonconst().set_comment(
705 "assertion havoc_slice " +
from_expr(
ns, identifier, ok_expr));
709 const symbolt &nondet_contents =
710 new_tmp_symbol(array_type,
"nondet_contents", dest, source_location, mode);
719 codet array_replace(ID_array_replace, {arg0, arg1}, source_location);
731 if(
function.get_bool(ID_C_invalid_object))
735 const irep_idt &identifier=
function.get_identifier();
741 error() <<
"error: function '" << identifier <<
"' not found" <<
eom;
745 if(symbol->
type.
id()!=ID_code)
748 error() <<
"error: function '" << identifier
749 <<
"' type mismatch: expected code" <<
eom;
774 identifier ==
CPROVER_PREFIX "assume" || identifier ==
"__VERIFIER_assume")
776 if(arguments.size()!=1)
779 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
786 function.source_location()));
788 t->source_location_nonconst().set(
"user-provided",
true);
793 error() << identifier <<
" expected not to have LHS" <<
eom;
797 else if(identifier==
"__VERIFIER_error")
799 if(!arguments.empty())
802 error() <<
"'" << identifier <<
"' expected to have no arguments" <<
eom;
809 t->source_location_nonconst().set(
"user-provided",
true);
810 t->source_location_nonconst().set_property_class(ID_assertion);
815 error() << identifier <<
" expected not to have LHS" <<
eom;
823 a->source_location_nonconst().set(
"user-provided",
true);
826 identifier ==
"assert" &&
829 if(arguments.size()!=1)
832 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
839 function.source_location()));
840 t->source_location_nonconst().set(
"user-provided",
true);
841 t->source_location_nonconst().set_property_class(ID_assertion);
842 t->source_location_nonconst().set_comment(
843 "assertion " +
from_expr(
ns, identifier, arguments.front()));
848 error() << identifier <<
" expected not to have LHS" <<
eom;
861 if(arguments.size()!=2)
864 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
868 bool is_precondition=
870 bool is_postcondition = identifier ==
CPROVER_PREFIX "postcondition";
878 function.source_location()));
882 t->source_location_nonconst().set_property_class(ID_precondition);
884 else if(is_postcondition)
886 t->source_location_nonconst().set_property_class(ID_postcondition);
890 t->source_location_nonconst().set(
891 "user-provided", !
function.source_location().is_built_in());
892 t->source_location_nonconst().set_property_class(ID_assertion);
895 t->source_location_nonconst().set_comment(description);
900 error() << identifier <<
" expected not to have LHS" <<
eom;
906 if(arguments.size()!=1)
909 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
916 error() << identifier <<
" expected not to have LHS" <<
eom;
920 codet havoc(ID_havoc_object);
928 do_printf(lhs,
function, arguments, dest);
932 do_scanf(lhs,
function, arguments, dest);
935 identifier==
"__CPROVER::input")
940 error() << identifier <<
" expected not to have LHS" <<
eom;
944 do_input(
function, arguments, dest);
947 identifier==
"__CPROVER::output")
952 error() << identifier <<
" expected not to have LHS" <<
eom;
959 identifier==
"__CPROVER::atomic_begin" ||
960 identifier==
"java::org.cprover.CProver.atomicBegin:()V" ||
961 identifier==
"__VERIFIER_atomic_begin")
966 identifier==
"__CPROVER::atomic_end" ||
967 identifier==
"java::org.cprover.CProver.atomicEnd:()V" ||
968 identifier==
"__VERIFIER_atomic_end")
991 if(lhs.
type().
id()==ID_c_bool)
994 rhs.
set(ID_C_identifier, identifier);
1000 rhs.
set(ID_C_identifier, identifier);
1013 if(
function.type().get_bool(ID_C_incomplete))
1016 error() <<
"'" << identifier <<
"' is not declared, "
1017 <<
"missing type information required to construct call to "
1018 <<
"uninterpreted function" <<
eom;
1024 for(
const auto ¶meter : function_call_type.
parameters())
1025 domain.push_back(parameter.type());
1032 assignment.add_source_location()=
function.source_location();
1037 do_array_op(ID_array_equal, lhs,
function, arguments, dest);
1041 do_array_op(ID_array_set, lhs,
function, arguments, dest);
1045 do_array_op(ID_array_copy, lhs,
function, arguments, dest);
1049 do_array_op(ID_array_replace, lhs,
function, arguments, dest);
1051 else if(identifier==
"__assert_fail" ||
1052 identifier==
"_assert" ||
1053 identifier==
"__assert_c99" ||
1054 identifier==
"_wassert")
1075 if(arguments.size()!=4 &&
1076 arguments.size()!=3)
1079 error() <<
"'" << identifier <<
"' expected to have four arguments"
1090 t->source_location_nonconst().set(
"user-provided",
true);
1091 t->source_location_nonconst().set_property_class(ID_assertion);
1092 t->source_location_nonconst().set_comment(description);
1095 else if(identifier==
"__assert_rtn" ||
1096 identifier==
"__assert")
1107 if(arguments.size()==4)
1112 else if(arguments.size()==3)
1120 error() <<
"'" << identifier <<
"' expected to have four arguments"
1128 t->source_location_nonconst().set(
"user-provided",
true);
1129 t->source_location_nonconst().set_property_class(ID_assertion);
1130 t->source_location_nonconst().set_comment(description);
1133 else if(identifier==
"__assert_func")
1138 if(arguments.size()!=4)
1141 error() <<
"'" << identifier <<
"' expected to have four arguments"
1156 description=
"assertion";
1162 t->source_location_nonconst().set(
"user-provided",
true);
1163 t->source_location_nonconst().set_property_class(ID_assertion);
1164 t->source_location_nonconst().set_comment(description);
1169 if(arguments.empty())
1172 error() <<
"'" << identifier <<
"' expected to have at least one argument"
1177 codet fence(ID_fence);
1179 for(
const auto &argument : arguments)
1184 else if(identifier==
"__builtin_prefetch")
1188 else if(identifier==
"__builtin_unreachable")
1192 else if(identifier==ID_gcc_builtin_va_arg)
1200 if(arguments.size()!=1)
1203 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
1211 exprt list_arg_cast = list_arg;
1213 list_arg.
type().
id() == ID_pointer &&
1231 ID_C_va_arg_type,
to_code_type(
function.type()).return_type());
1233 std::move(assign),
function.source_location()));
1235 else if(identifier==
"__builtin_va_copy")
1237 if(arguments.size()!=2)
1240 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
1250 error() <<
"va_copy argument expected to be lvalue" <<
eom;
1255 dest_expr, src_expr,
function.source_location()));
1257 else if(identifier ==
"__builtin_va_start" || identifier ==
"__va_start")
1261 if(arguments.size()!=2)
1264 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
1273 error() <<
"va_start argument expected to be lvalue" <<
eom;
1278 dest_expr.
type().
id() == ID_pointer &&
1287 rhs.add_to_operands(
1291 std::move(dest_expr), std::move(rhs),
function.source_location()));
1293 else if(identifier==
"__builtin_va_end")
1296 if(arguments.size()!=1)
1299 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
1308 error() <<
"va_end argument expected to be lvalue" <<
eom;
1313 if(dest_expr.
type().
id() == ID_pointer)
1319 dest_expr, *zero,
function.source_location()));
1323 identifier ==
"__builtin_isgreater" ||
1324 identifier ==
"__builtin_isgreaterequal" ||
1325 identifier ==
"__builtin_isless" || identifier ==
"__builtin_islessequal" ||
1326 identifier ==
"__builtin_islessgreater" ||
1327 identifier ==
"__builtin_isunordered")
1331 if(arguments.size()!=2 ||
1338 error() <<
"'" << identifier
1339 <<
"' expected to have two float/double arguments" <<
eom;
1345 bool use_double=arguments[0].type()==
double_type();
1346 if(arguments[0].type()!=arguments[1].type())
1363 const typet &a_t=new_arguments[0].type();
1370 name+=use_double?
'd':
'f';
1374 new_function.
type()=f_type;
1383 new_symbol.
name=name;
1384 new_symbol.
type=f_type;
1385 new_symbol.
location=
function.source_location();
exprt make_va_list(const exprt &expr)
floatbv_typet float_type()
unsignedbv_typet size_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
const memberst & members() const
std::vector< c_enum_membert > memberst
A codet representing an assignment in the program.
codet representation of a function call statement.
A codet representing the declaration that an output of a particular description has a value which cor...
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)
A constant literal expression.
const irep_idt & get_value() const
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
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)
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)
void do_enum_is_in_range(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest)
Converts calls to the built in enum_is_in_range function to a test that the given enum value is in th...
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_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::iterator targett
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.
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_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
static instructiont make_other(const codet &_code, const source_locationt &l=source_locationt::nil())
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
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
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
Expression to hold a symbol (variable)
void set_identifier(const irep_idt &identifier)
const irep_idt & get_identifier() const
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
irep_idt base_name
Base (non-scoped) name.
source_locationt location
Source code location of definition of symbol.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
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
bool has_prefix(const std::string &s, const std::string &prefix)
optionalt< 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.
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 PRECONDITION(CONDITION)
const codet & to_code(const exprt &expr)
exprt disjunction(const exprt::operandst &op)
1) generates a disjunction for two or more operands 2) for one operand, returns the operand 3) return...
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)