Skip to content

Handle array_{copy,replace,set} in dependence graph #6710

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

Merged
Merged
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
9 changes: 9 additions & 0 deletions regression/cbmc/Bool5/full-slice.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--full-slice
Generated 4 VCC\(s\), 0 remaining after simplification
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
63 changes: 56 additions & 7 deletions src/analyses/goto_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,17 @@ void rw_range_sett::get_objects_rec(const typet &type)
}
}

void rw_range_sett::get_array_objects(
const irep_idt &,
goto_programt::const_targett,
get_modet mode,
const exprt &pointer)
{
object_descriptor_exprt ode;
ode.build(dereference_exprt{skip_typecast(pointer)}, ns);
get_objects_rec(mode, ode.root_object(), -1, -1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪄 magic numbers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point! These are used throughout goto_rw, so I'll post a follow-up PR that fix this throughout this piece of code.

}

void rw_range_set_value_sett::get_objects_dereference(
get_modet mode,
const dereference_exprt &deref,
Expand Down Expand Up @@ -737,6 +748,50 @@ static void goto_rw_assign(
rw_set.get_objects_rec(function, target, rw_range_sett::get_modet::READ, rhs);
}

static void goto_rw_other(
const irep_idt &function,
goto_programt::const_targett target,
const codet &code,
rw_range_sett &rw_set)
{
const irep_idt &statement = code.get_statement();

if(statement == ID_printf)
{
// if it's printf, mark the operands as read here
for(const auto &op : code.operands())
{
rw_set.get_objects_rec(
function, target, rw_range_sett::get_modet::READ, op);
}
}
else if(statement == ID_array_equal)
{
// mark the dereferenced operands as being read
for(const auto &op : code.operands())
{
rw_set.get_array_objects(
function, target, rw_range_sett::get_modet::READ, op);
}
}
else if(statement == ID_array_set)
{
PRECONDITION(code.operands().size() == 2);
rw_set.get_array_objects(
function, target, rw_range_sett::get_modet::LHS_W, code.op0());
rw_set.get_objects_rec(
function, target, rw_range_sett::get_modet::READ, code.op1());
}
else if(statement == ID_array_copy || statement == ID_array_replace)
{
PRECONDITION(code.operands().size() == 2);
rw_set.get_array_objects(
function, target, rw_range_sett::get_modet::LHS_W, code.op0());
rw_set.get_array_objects(
function, target, rw_range_sett::get_modet::READ, code.op1());
}
}

static void goto_rw(
const irep_idt &function,
goto_programt::const_targett target,
Expand Down Expand Up @@ -787,13 +842,7 @@ void goto_rw(
break;

case OTHER:
// if it's printf, mark the operands as read here
if(target->get_other().get_statement() == ID_printf)
{
for(const auto &op : target->get_other().operands())
rw_set.get_objects_rec(
function, target, rw_range_sett::get_modet::READ, op);
}
goto_rw_other(function, target, target->get_other(), rw_set);
break;

case SKIP:
Expand Down
18 changes: 18 additions & 0 deletions src/analyses/goto_rw.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ class rw_range_sett
get_objects_rec(type);
}

virtual void get_array_objects(
const irep_idt &,
goto_programt::const_targett,
get_modet,
const exprt &);

void output(std::ostream &out) const;

protected:
Expand Down Expand Up @@ -288,6 +294,18 @@ class rw_range_set_value_sett:public rw_range_sett
rw_range_sett::get_objects_rec(type);
}

void get_array_objects(
const irep_idt &_function,
goto_programt::const_targett _target,
get_modet mode,
const exprt &pointer) override
{
function = _function;
target = _target;

rw_range_sett::get_array_objects(_function, _target, mode, pointer);
}

protected:
value_setst &value_sets;
irep_idt function;
Expand Down
3 changes: 3 additions & 0 deletions src/analyses/reaching_definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ void rd_range_domaint::transform(
// initial (non-deterministic) value
else if(from->is_decl())
transform_assign(ns, from, function_from, from, *rd);
// array_set, array_copy, array_replace have side effects
else if(from->is_other())
transform_assign(ns, from, function_from, from, *rd);
}

/// Computes an instance obtained from a `*this` by transformation over `DEAD v`
Expand Down