38 exprt normalized_expr = expr;
41 bool checked_when_taken =
true;
44 while(normalized_expr.
id() == ID_not)
47 checked_when_taken = !checked_when_taken;
50 if(normalized_expr.
id() == ID_equal)
52 normalized_expr.
id(ID_notequal);
53 checked_when_taken = !checked_when_taken;
56 if(normalized_expr.
id() == ID_notequal)
61 if(op0.
type().
id() == ID_pointer &&
64 return { { checked_when_taken, op1 } };
67 if(op1.
type().
id() == ID_pointer &&
70 return { { checked_when_taken, op0 } };
84 std::set<exprt, type_comparet> checked_expressions(
type_comparet{});
89 if(instruction.incoming_edges.size() > 1)
90 checked_expressions.clear();
92 else if(instruction.is_target())
96 checked_expressions = findit->second;
99 checked_expressions = std::set<exprt, type_comparet>(
type_comparet{});
104 if(!checked_expressions.empty())
107 instruction.location_number, checked_expressions);
110 switch(instruction.type())
131 if(assume_check->checked_when_taken)
132 checked_expressions.insert(assume_check->checked_expr);
138 if(!instruction.is_backwards_goto())
142 auto target_emplace_result =
144 instruction.get_target()->location_number, checked_expressions);
148 if(target_emplace_result.second)
151 auto conditional_check =
156 if(conditional_check->checked_when_taken)
158 target_emplace_result.first->second.insert(
159 conditional_check->checked_expr);
162 checked_expressions.insert(conditional_check->checked_expr);
178 checked_expressions.clear();
194 for(
const auto &instruction : goto_program.
instructions)
196 out <<
"**** " << instruction.location_number <<
" "
197 << instruction.source_location() <<
"\n";
199 out <<
"Non-null expressions: ";
208 for(
const exprt &expr : findit->second)
219 instruction.output(out);
238 for(
const auto &instruction : goto_program.
instructions)
240 out <<
"**** " << instruction.location_number <<
" "
241 << instruction.source_location() <<
"\n";
243 out <<
"Safe (known-not-null) dereferences: ";
252 instruction.apply([&first, &out](
const exprt &e) {
254 subexpr_it != subexpr_end;
257 if(subexpr_it->id() == ID_dereference)
262 format_rec(out, to_dereference_expr(*subexpr_it).pointer());
270 instruction.output(out);
Base class for all expressions.
depth_iteratort depth_end()
depth_iteratort depth_begin()
typet & type()
Return the type of the expression.
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
instructionst::const_iterator const_targett
const irep_idt & id() const
void output_safe_dereferences(std::ostream &stream, const goto_programt &program, const namespacet &ns)
Output safely dereferenced expressions per instruction in human-readable format.
void operator()(const goto_programt &goto_program)
Compute safe dereference expressions for a given GOTO program.
bool is_non_null_at_program_point(const exprt &expr, goto_programt::const_targett program_point)
Return true if the local-safe-pointers analysis has determined expr cannot be null as of program_poin...
void output(std::ostream &stream, const goto_programt &program, const namespacet &ns)
Output non-null expressions per instruction in human-readable format.
std::map< unsigned, std::set< exprt, type_comparet > > non_null_expressions
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
The null pointer constant.
Forward depth-first search iterators These iterators' copy operations are expensive,...
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
Deprecated expression utility functions.
static std::optional< goto_null_checkt > get_null_checked_expr(const exprt &expr)
Check if expr tests if a pointer is null.
Local safe pointer analysis.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const notequal_exprt & to_notequal_expr(const exprt &expr)
Cast an exprt to an notequal_exprt.
const not_exprt & to_not_expr(const exprt &expr)
Cast an exprt to an not_exprt.
Return structure for get_null_checked_expr and get_conditional_checked_expr
bool checked_when_taken
If true, the given GOTO/ASSUME tests that a pointer expression is non-null on the taken branch or pas...
exprt checked_expr
Null-tested pointer expression.
Comparator that regards type-equal expressions as equal, and otherwise uses the natural (operator<) o...