46 it->id() == ID_symbol &&
112 if((description.find(
113 "dereference failure: pointer outside object bounds in") !=
120 if(description.find(
"pointer NULL") != std::string::npos)
126 if(description.find(
"preserved") != std::string::npos)
132 if(description.find(
"invariant before entry") != std::string::npos)
138 if(description.find(
"assignable") != std::string::npos)
149 std::list<loop_idt> result;
159 for(
const auto &step : goto_trace.
steps)
173 result.front() == loop_id,
"Leaving a loop we haven't entered.");
178 INVARIANT(!result.empty(),
"The assignable violation is not in a loop.");
186 std::list<loop_idt> result;
202 it != to_function.body.instructions.end();
205 if(it->location_number == violation->location_number)
212 to != to_function.body.instructions.end(),
213 "There must be a violation in a trace.");
216 const auto reachable_vector =
217 dependence_graph.
get_reachable(dependence_graph[to].get_node_id(),
false);
218 const std::set<size_t> reachable_set =
219 std::set<size_t>(reachable_vector.begin(), reachable_vector.end());
223 for(
const auto &step : goto_trace.
steps)
230 irep_idt from_fun_name = step.function_id;
235 from_function.body.instructions.begin();
236 it != from_function.body.instructions.end();
239 if(it->location_number == step.pc->location_number)
246 from != from_function.body.instructions.end(),
247 "Failed to find the location number of the loop havoc.");
251 if(reachable_set.count(dependence_graph[from].get_node_id()))
265 unsigned location_number_of_target)
268 loop_id,
function, location_number_of_target))
274 loop_id,
function, location_number_of_target))
285 unsigned location_number_of_target)
291 unsigned location_number_of_havocing = 0;
292 for(
auto it =
function.body.instructions.begin();
293 it !=
function.body.instructions.end();
301 location_number_of_havocing = it->location_number;
305 if(location_number_of_havocing != 0 && it->is_goto())
307 if((location_number_of_havocing < location_number_of_target &&
308 location_number_of_target < it->location_number))
312 location_number_of_havocing = 0;
321 unsigned location_number_of_target)
327 unsigned location_number_of_havocing = 0;
330 it !=
function.body.instructions.end();
338 location_number_of_havocing = it->location_number;
347 location_number_of_havocing != 0,
348 "We must have entered the transformed loop before reaching the end");
352 if((location_number_of_havocing < location_number_of_target &&
353 location_number_of_target < it->location_number))
368 std::unordered_map<exprt, mp_integer, irep_hash> object_sizes;
369 std::unordered_map<exprt, mp_integer, irep_hash> havoced_values;
370 std::unordered_map<exprt, mp_integer, irep_hash> havoced_pointer_offsets;
373 std::unordered_map<exprt, mp_integer, irep_hash> loop_entry_values;
374 std::unordered_map<exprt, mp_integer, irep_hash> loop_entry_offsets;
377 std::set<exprt> live_variables;
379 bool entered_loop =
false;
382 for(
const auto &step : goto_trace.
steps)
389 if(!step.full_lhs_value.is_nil())
393 entered_loop = step.full_lhs_value ==
true_exprt();
405 step.pc->source_location().get_function() ==
408 (step.full_lhs.type().id() == ID_unsignedbv ||
409 step.full_lhs.type().id() == ID_signedbv ||
410 step.full_lhs.type().id() == ID_pointer) &&
411 step.full_lhs.id() == ID_symbol)
414 expr_try_dynamic_cast<symbol_exprt>(step.full_lhs);
417 if(
id2string(symbol->get_identifier()) !=
"malloc::malloc_size")
419 live_variables.emplace(step.full_lhs);
425 step.full_lhs.type().id() == ID_unsignedbv ||
426 step.full_lhs.type().id() == ID_signedbv)
428 bool is_signed = step.full_lhs.type().id() == ID_signedbv;
429 const auto &bv_type =
430 type_try_dynamic_cast<bitvector_typet>(step.full_lhs.type());
431 const auto width = bv_type->get_width();
437 step.full_lhs_value.get_string(ID_value), width,
is_signed);
445 step.full_lhs_value.get_string(ID_value), width,
is_signed);
452 step.full_lhs_value) &&
456 const auto &pointer_constant_expr =
457 expr_try_dynamic_cast<annotated_pointer_constant_exprt>(
458 step.full_lhs_value);
461 pointer_constant_expr->symbolic_pointer());
462 if(pointer_constant_expr->symbolic_pointer().id() == ID_typecast)
465 pointer_constant_expr->symbolic_pointer().operands()[0]);
474 underlying_array.
id() == ID_address_of ||
475 underlying_array.
id() == ID_index ||
476 underlying_array.
id() == ID_typecast)
478 underlying_array = underlying_array.
operands()[0];
493 expr_dynamic_cast<constant_exprt>(pointer_arithmetic.
offset);
502 loop_entry_offsets[step.full_lhs] = offset;
509 havoced_pointer_offsets[step.full_lhs] = offset;
541 havoced_pointer_offsets,
572 if(fun_entry.second.body_available())
601 checker = std::make_unique<
611 const resultt result = (*checker)();
626 return std::optional<cext>();
631 INVARIANT(
false,
"Verification failed during loop contract synthesis.");
647 if(it_property->second.description.find(
"assignable") != std::string::npos)
649 target_violation = it_property;
660 target_violation = it_property;
669 return std::optional<cext>();
691 log.
debug() <<
"Violation description: "
694 const auto &trace = checker->get_traces()[target_violation->first];
698 cext result(violation_type);
701 target_violation->second.pc->condition().find(ID_checked_assigns));
711 const std::list<loop_idt> cause_loop_ids =
714 if(cause_loop_ids.empty())
719 return cext(violation_type);
722 log.
debug() <<
"Found cause loop with function id: "
723 << cause_loop_ids.front().function_id
724 <<
", and loop number: " << cause_loop_ids.front().loop_number
734 cause_loop_ids.front(),
736 target_violation->second.pc->location_number);
744 cause_loop_ids.front().loop_number,
747 ->source_location());
748 return_cex.violated_predicate = target_violation->second.pc->condition();
749 return_cex.cause_loop_ids = cause_loop_ids;
750 return_cex.violation_location = violation_location;
751 return_cex.violation_type = violation_type;
757 target_violation->second.pc->condition());
void add_failed_symbols(symbol_table_baset &symbol_table)
Create a failed-dereference symbol for all symbols in the given table that need one (i....
Goto verifier for verifying all properties that stores traces.
void cprover_c_library_factory(const std::set< irep_idt > &functions, const symbol_table_baset &symbol_table, symbol_table_baset &dest_symbol_table, message_handlert &message_handler)
static bool contains_symbol_prefix(const exprt &expr, const std::string &prefix)
static const exprt & get_checked_pointer_from_null_pointer_check(const exprt &violation)
Verifier for Counterexample-Guided Synthesis.
std::optional< cext > verify()
Verify goto_model.
irep_idt target_violation_id
void restore_functions()
Restore transformed functions to original functions.
const std::map< loop_idt, std::set< exprt > > & assigns_map
cext build_cex(const goto_tracet &goto_trace, const source_locationt &loop_entry_loc)
cext::violation_locationt get_violation_location(const loop_idt &loop_id, const goto_functiont &function, unsigned location_number_of_target)
std::list< loop_idt > get_cause_loop_id(const goto_tracet &goto_trace, const goto_programt::const_targett violation)
std::unordered_set< goto_programt::const_targett, const_target_hash > loop_havoc_set
Loop havoc instructions instrumented during applying loop contracts.
bool is_instruction_in_transformed_loop(const loop_idt &loop_id, const goto_functiont &function, unsigned location_number_of_target)
Decide whether the target instruction is in the body of the transformed loop specified by loop_id.
const invariant_mapt & invariant_candidates
std::unordered_map< goto_programt::const_targett, unsigned, const_target_hash > original_loop_number_map
Map from instrumented instructions for loop contracts to their original loop numbers.
cext::violation_typet extract_violation_type(const std::string &description)
std::unordered_map< irep_idt, goto_programt > original_functions
Map from function names to original functions.
void preprocess_goto_model()
Preprocess the goto model to prepare for verification.
propertiest properties
Result counterexample.
std::list< loop_idt > get_cause_loop_id_for_assigns(const goto_tracet &goto_trace)
bool is_instruction_in_transformed_loop_condition(const loop_idt &loop_id, const goto_functiont &function, unsigned location_number_of_target)
Decide whether the target instruction is between the loop-havoc and the evaluation of the loop guard.
Formatted counterexample.
std::list< loop_idt > cause_loop_ids
@ cex_not_hold_upon_entry
void apply_loop_contracts(const std::set< std::string > &to_exclude_from_nondet_init={})
Applies loop contract transformations.
A constant literal expression.
const irep_idt & get_value() const
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.
depth_iteratort depth_end()
depth_iteratort depth_begin()
typet & type()
Return the type of the expression.
The Boolean constant false.
function_mapt function_map
::goto_functiont goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
const goto_functionst::goto_functiont & get_goto_function(const irep_idt &id) override
Get a GOTO function by name, or throw if no such function exists.
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
instructionst::const_iterator const_targett
goto_trace_stept & get_last_step()
Retrieves the final step in the trace for manipulation (used to fill a trace from code,...
std::vector< node_indext > get_reachable(node_indext src, bool forwards) const
Run depth-first search on the graph, starting from a single source node.
const irep_idt & id() const
void set_verbosity(unsigned _verbosity)
unsigned get_verbosity() const
message_handlert & get_message_handler()
A numerical identifier for the object a pointer points to.
const irep_idt & get_function() const
const irep_idt & get_identifier() const
The Boolean constant true.
Verify and use annotated invariants and pre/post-conditions.
void cprover_cpp_library_factory(const std::set< irep_idt > &functions, const symbol_table_baset &symbol_table, symbol_table_baset &dest_symbol_table, message_handlert &message_handler)
Field-Sensitive Program Dependence Analysis, Litvak et al., FSE 2010.
bool is_null_pointer(const constant_exprt &expr)
Returns true if expr has a pointer type and a value NULL; it also returns true when expr has value ze...
void goto_convert(const codet &code, symbol_table_baset &symbol_table, goto_programt &dest, message_handlert &message_handler, const irep_idt &mode)
Goto Programs with Functions.
Utilities for building havoc code for expressions.
Specify write set in function contracts.
const std::string & id2string(const irep_idt &d)
void link_to_library(goto_modelt &goto_model, message_handlert &message_handler, const std::function< void(const std::set< irep_idt > &, const symbol_tablet &, symbol_tablet &, message_handlert &)> &library)
Complete missing function definitions using the library.
Goto Checker using Multi-Path Symbolic Execution.
bool can_cast_expr< annotated_pointer_constant_exprt >(const exprt &base)
const pointer_object_exprt & to_pointer_object_expr(const exprt &expr)
Cast an exprt to a pointer_object_exprt.
std::optional< mp_integer > pointer_offset_size(const typet &type, const namespacet &ns)
Compute the size of a type in bytes, rounding up to full bytes.
exprt object_size(const exprt &pointer)
Various predicates over pointers in programs.
#define SYMEX_DYNAMIC_PREFIX
bool process_goto_program(goto_modelt &goto_model, const optionst &options, messaget &log)
Common processing and simplification of goto_programts.
@ FAIL
The property was violated.
resultt
The result of goto verifying.
@ UNKNOWN
No property was violated, neither was there an error.
@ PASS
No properties were violated.
@ ERROR
An error occurred during goto checking.
void remove_asm(goto_functionst &goto_functions, symbol_tablet &symbol_table, message_handlert &message_handler)
Replaces inline assembly instructions in the goto program (i.e., instructions of kind OTHER with a co...
bool has_asm(const goto_functionst &goto_functions)
returns true iff the given goto functions use asm instructions
Remove 'asm' statements by compiling them into suitable standard goto program instructions.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
void label_properties(goto_modelt &goto_model)
Set the properties to check.
exprt simplify_expr(exprt src, const namespacet &ns)
#define UNREACHABLE
This should be used to mark dead code.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const not_exprt & to_not_expr(const exprt &expr)
Cast an exprt to an not_exprt.
bool can_cast_expr< constant_exprt >(const exprt &base)
const equal_exprt & to_equal_expr(const exprt &expr)
Cast an exprt to an equal_exprt.
bool can_cast_type< array_typet >(const typet &type)
Check whether a reference to a typet is a array_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
Loop contract configurations.
Loop id used to identify loops.
bool is_signed(const typet &t)
Convenience function – is the type signed?
bool is_assignment_to_instrumented_variable(const goto_programt::const_targett &target, std::string var_name)
Return true if target is an assignment to an instrumented variable with name var_name.
goto_programt::targett get_loop_head(const unsigned int target_loop_number, goto_functiont &function)
Find and return the first instruction of the natural loop with loop_number in function.
bool is_transformed_loop_head(const goto_programt::const_targett &target)
Return true if target is the head of some transformed loop.
bool is_transformed_loop_end(const goto_programt::const_targett &target)
Return true if target is the end of some transformed loop.
void annotate_invariants(const invariant_mapt &invariant_map, goto_modelt &goto_model)
Annotate the invariants in invariant_map to their corresponding loops.
void annotate_assigns(const std::map< loop_idt, std::set< exprt >> &assigns_map, goto_modelt &goto_model)
Annotate the assigns in assigns_map to their corresponding loops.