Skip to content

codet now inherits from irept, not exprt #2825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions src/analyses/local_safe_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Author: Diffblue Ltd

#include "local_safe_pointers.h"

#include <util/base_type.h>
#include <util/expr_iterator.h>
#include <util/expr_util.h>
#include <util/format_expr.h>
Expand Down Expand Up @@ -81,7 +82,8 @@ static optionalt<goto_null_checkt> get_null_checked_expr(const exprt &expr)
/// \param goto_program: program to analyse
void local_safe_pointerst::operator()(const goto_programt &goto_program)
{
std::set<exprt, type_comparet> checked_expressions(type_comparet{});
std::set<exprt, base_type_comparet> checked_expressions(
base_type_comparet{ns});

for(const auto &instruction : goto_program.instructions)
{
Expand All @@ -96,7 +98,8 @@ void local_safe_pointerst::operator()(const goto_programt &goto_program)
checked_expressions = findit->second;
else
{
checked_expressions = std::set<exprt, type_comparet>(type_comparet{});
checked_expressions =
std::set<exprt, base_type_comparet>(base_type_comparet{ns});
}
}

Expand Down Expand Up @@ -185,11 +188,8 @@ void local_safe_pointerst::operator()(const goto_programt &goto_program)
/// \param out: stream to write output to
/// \param goto_program: GOTO program analysed (the same one passed to
/// operator())
/// \param ns: namespace
void local_safe_pointerst::output(
std::ostream &out,
const goto_programt &goto_program,
const namespacet &ns)
std::ostream &out, const goto_programt &goto_program)
{
forall_goto_program_instructions(i_it, goto_program)
{
Expand Down Expand Up @@ -229,11 +229,8 @@ void local_safe_pointerst::output(
/// \param out: stream to write output to
/// \param goto_program: GOTO program analysed (the same one passed to
/// operator())
/// \param ns: namespace
void local_safe_pointerst::output_safe_dereferences(
std::ostream &out,
const goto_programt &goto_program,
const namespacet &ns)
std::ostream &out, const goto_programt &goto_program)
{
forall_goto_program_instructions(i_it, goto_program)
{
Expand All @@ -250,17 +247,12 @@ void local_safe_pointerst::output_safe_dereferences(
out << "{";
bool first = true;
i_it->apply([&first, &out](const exprt &e) {
for(auto subexpr_it = e.depth_begin(), subexpr_end = e.depth_end();
subexpr_it != subexpr_end;
++subexpr_it)
if(e.id() == ID_dereference)
{
if(subexpr_it->id() == ID_dereference)
{
if(!first)
out << ", ";
first = true;
format_rec(out, to_dereference_expr(*subexpr_it).pointer());
}
if(!first)
out << ", ";
first = true;
format_rec(out, to_dereference_expr(e).pointer());
}
});
out << "}";
Expand All @@ -281,6 +273,17 @@ bool local_safe_pointerst::is_non_null_at_program_point(
auto findit = non_null_expressions.find(program_point->location_number);
if(findit == non_null_expressions.end())
return false;
const exprt *tocheck = &expr;
while(tocheck->id() == ID_typecast)
tocheck = &tocheck->op0();
return findit->second.count(*tocheck) != 0;
}

return findit->second.count(skip_typecast(expr)) != 0;
bool local_safe_pointerst::base_type_comparet::operator()(
const exprt &e1, const exprt &e2) const
{
if(base_type_eq(e1, e2, ns))
return false;
else
return e1 < e2;
}
2 changes: 0 additions & 2 deletions src/ansi-c/c_typecheck_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ void c_typecheck_baset::typecheck_code(codet &code)
throw 0;
}

code.type() = empty_typet();

const irep_idt &statement=code.get_statement();

if(statement==ID_expression)
Expand Down
4 changes: 2 additions & 2 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ void c_typecheck_baset::typecheck_expr_sizeof(exprt &expr)
ID_statement_expression, void_type(), expr.source_location());
auto decl_block=code_blockt::from_list(clean_code);
decl_block.set_statement(ID_decl_block);
side_effect_expr.copy_to_operands(decl_block);
side_effect_expr.get_sub().push_back(decl_block);
clean_code.clear();

// We merge the side-effect into the operand of the typecast,
Expand Down Expand Up @@ -1024,7 +1024,7 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr)
ID_statement_expression, void_type(), expr.source_location());
auto decl_block=code_blockt::from_list(clean_code);
decl_block.set_statement(ID_decl_block);
side_effect_expr.copy_to_operands(decl_block);
side_effect_expr.get_sub().push_back(decl_block);
clean_code.clear();

// We merge the side-effect into the operand of the typecast,
Expand Down
Loading