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 const auto enum_expr = arguments.front();
622 const auto enum_type =
623 type_try_dynamic_cast<c_enum_tag_typet>(enum_expr.type());
629 for(
const auto &enum_value : enum_values)
632 disjuncts.push_back(
equal_exprt(enum_expr, std::move(val)));
647 if(
function.get_bool(ID_C_invalid_object))
651 const irep_idt &identifier=
function.get_identifier();
657 error() <<
"error: function '" << identifier <<
"' not found" <<
eom;
661 if(symbol->
type.
id()!=ID_code)
664 error() <<
"error: function '" << identifier
665 <<
"' type mismatch: expected code" <<
eom;
686 identifier==
"__VERIFIER_assume")
688 if(arguments.size()!=1)
691 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
698 function.source_location()));
700 t->source_location.set(
"user-provided",
true);
705 error() << identifier <<
" expected not to have LHS" <<
eom;
709 else if(identifier==
"__VERIFIER_error")
711 if(!arguments.empty())
714 error() <<
"'" << identifier <<
"' expected to have no arguments" <<
eom;
721 t->source_location.set(
"user-provided",
true);
722 t->source_location.set_property_class(ID_assertion);
727 error() << identifier <<
" expected not to have LHS" <<
eom;
735 a->source_location.set(
"user-provided",
true);
738 identifier ==
"assert" &&
741 if(arguments.size()!=1)
744 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
751 function.source_location()));
752 t->source_location.set(
"user-provided",
true);
753 t->source_location.set_property_class(ID_assertion);
754 t->source_location.set_comment(
755 "assertion " +
from_expr(
ns, identifier, arguments.front()));
760 error() << identifier <<
" expected not to have LHS" <<
eom;
773 if(arguments.size()!=2)
776 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
780 bool is_precondition=
782 bool is_postcondition = identifier ==
CPROVER_PREFIX "postcondition";
790 function.source_location()));
794 t->source_location.set_property_class(ID_precondition);
796 else if(is_postcondition)
798 t->source_location.set_property_class(ID_postcondition);
802 t->source_location.set(
804 !
function.source_location().is_built_in());
805 t->source_location.set_property_class(ID_assertion);
808 t->source_location.set_comment(description);
813 error() << identifier <<
" expected not to have LHS" <<
eom;
819 if(arguments.size()!=1)
822 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
829 error() << identifier <<
" expected not to have LHS" <<
eom;
833 codet havoc(ID_havoc_object);
841 do_printf(lhs,
function, arguments, dest);
845 do_scanf(lhs,
function, arguments, dest);
848 identifier==
"__CPROVER::input")
853 error() << identifier <<
" expected not to have LHS" <<
eom;
857 do_input(
function, arguments, dest);
860 identifier==
"__CPROVER::output")
865 error() << identifier <<
" expected not to have LHS" <<
eom;
872 identifier==
"__CPROVER::atomic_begin" ||
873 identifier==
"java::org.cprover.CProver.atomicBegin:()V" ||
874 identifier==
"__VERIFIER_atomic_begin")
879 identifier==
"__CPROVER::atomic_end" ||
880 identifier==
"java::org.cprover.CProver.atomicEnd:()V" ||
881 identifier==
"__VERIFIER_atomic_end")
904 if(lhs.
type().
id()==ID_c_bool)
907 rhs.
set(ID_C_identifier, identifier);
913 rhs.
set(ID_C_identifier, identifier);
926 if(
function.type().get_bool(ID_C_incomplete))
929 error() <<
"'" << identifier <<
"' is not declared, "
930 <<
"missing type information required to construct call to "
931 <<
"uninterpreted function" <<
eom;
937 for(
const auto ¶meter : function_call_type.
parameters())
938 domain.push_back(parameter.type());
945 assignment.add_source_location()=
function.source_location();
950 do_array_op(ID_array_equal, lhs,
function, arguments, dest);
954 do_array_op(ID_array_set, lhs,
function, arguments, dest);
958 do_array_op(ID_array_copy, lhs,
function, arguments, dest);
962 do_array_op(ID_array_replace, lhs,
function, arguments, dest);
964 else if(identifier==
"__assert_fail" ||
965 identifier==
"_assert" ||
966 identifier==
"__assert_c99" ||
967 identifier==
"_wassert")
988 if(arguments.size()!=4 &&
992 error() <<
"'" << identifier <<
"' expected to have four arguments"
1003 t->source_location.set(
"user-provided",
true);
1004 t->source_location.set_property_class(ID_assertion);
1005 t->source_location.set_comment(description);
1008 else if(identifier==
"__assert_rtn" ||
1009 identifier==
"__assert")
1020 if(arguments.size()==4)
1025 else if(arguments.size()==3)
1033 error() <<
"'" << identifier <<
"' expected to have four arguments"
1041 t->source_location.set(
"user-provided",
true);
1042 t->source_location.set_property_class(ID_assertion);
1043 t->source_location.set_comment(description);
1046 else if(identifier==
"__assert_func")
1051 if(arguments.size()!=4)
1054 error() <<
"'" << identifier <<
"' expected to have four arguments"
1069 description=
"assertion";
1075 t->source_location.set(
"user-provided",
true);
1076 t->source_location.set_property_class(ID_assertion);
1077 t->source_location.set_comment(description);
1082 if(arguments.empty())
1085 error() <<
"'" << identifier <<
"' expected to have at least one argument"
1090 codet fence(ID_fence);
1092 for(
const auto &argument : arguments)
1097 else if(identifier==
"__builtin_prefetch")
1101 else if(identifier==
"__builtin_unreachable")
1105 else if(identifier==ID_gcc_builtin_va_arg)
1113 if(arguments.size()!=1)
1116 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
1124 exprt list_arg_cast = list_arg;
1126 list_arg.
type().
id() == ID_pointer &&
1144 ID_C_va_arg_type,
to_code_type(
function.type()).return_type());
1146 std::move(assign),
function.source_location()));
1148 else if(identifier==
"__builtin_va_copy")
1150 if(arguments.size()!=2)
1153 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
1163 error() <<
"va_copy argument expected to be lvalue" <<
eom;
1168 dest_expr, src_expr,
function.source_location()));
1170 else if(identifier ==
"__builtin_va_start" || identifier ==
"__va_start")
1174 if(arguments.size()!=2)
1177 error() <<
"'" << identifier <<
"' expected to have two arguments" <<
eom;
1186 error() <<
"va_start argument expected to be lvalue" <<
eom;
1191 dest_expr.
type().
id() == ID_pointer &&
1200 rhs.add_to_operands(
1204 std::move(dest_expr), std::move(rhs),
function.source_location()));
1206 else if(identifier==
"__builtin_va_end")
1209 if(arguments.size()!=1)
1212 error() <<
"'" << identifier <<
"' expected to have one argument" <<
eom;
1221 error() <<
"va_end argument expected to be lvalue" <<
eom;
1226 if(dest_expr.
type().
id() == ID_pointer)
1232 dest_expr, *zero,
function.source_location()));
1236 identifier ==
"__builtin_isgreater" ||
1237 identifier ==
"__builtin_isgreaterequal" ||
1238 identifier ==
"__builtin_isless" || identifier ==
"__builtin_islessequal" ||
1239 identifier ==
"__builtin_islessgreater" ||
1240 identifier ==
"__builtin_isunordered")
1244 if(arguments.size()!=2 ||
1251 error() <<
"'" << identifier
1252 <<
"' expected to have two float/double arguments" <<
eom;
1258 bool use_double=arguments[0].type()==
double_type();
1259 if(arguments[0].type()!=arguments[1].type())
1276 const typet &a_t=new_arguments[0].type();
1283 name+=use_double?
'd':
'f';
1287 new_function.
type()=f_type;
1296 new_symbol.
name=name;
1297 new_symbol.
type=f_type;
1298 new_symbol.
location=
function.source_location();
exprt make_va_list(const exprt &expr)
floatbv_typet float_type()
bitvector_typet index_type()
unsignedbv_typet size_type()
signedbv_typet signed_int_type()
pointer_typet pointer_type(const typet &subtype)
signedbv_typet pointer_diff_type()
floatbv_typet double_type()
Extract class identifier.
Operator to return the address of an object.
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.
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)
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
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...
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())
void set(const irep_namet &name, const irep_idt &value)
bool get_bool(const irep_namet &name) const
const irept & find(const irep_namet &name) const
const irep_idt & id() const
const irep_idt & get(const irep_namet &name) 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.
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.
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
const typet & subtype() 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.
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
bool is_lvalue(const exprt &expr)
Returns true iff the argument is (syntactically) an lvalue.
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 address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
exprt object_size(const exprt &pointer)
#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 pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.