Skip to content
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

Field sensitivity: account for array size in all index expressions #8579

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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/field-sensitivity17/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
union U
{
unsigned char buf[2];
} s;

int main()
{
__CPROVER_assert(s.buf[0] == 0, "");
}
12 changes: 12 additions & 0 deletions regression/cbmc/field-sensitivity17/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--max-field-sensitivity-array-size 1
^VERIFICATION SUCCESSFUL$
^EXIT=0$
^SIGNAL=0$
--
--
The test is a minimized version of code generated using Kani. It should pass
irrespective of whether field sensitivity is applied to the array or not. (The
original example was unexpectedly failing with an array size of 65, but passed
with an array size of 64 or less.)
68 changes: 51 additions & 17 deletions src/goto-symex/field_sensitivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,34 +111,68 @@
const member_exprt member{tmp.get_original_expr(), comp};
auto recursive_member =
get_subexpression_at_offset(member, be.offset(), be.type(), ns);
if(
recursive_member.has_value() &&
(recursive_member->id() == ID_member ||
recursive_member->id() == ID_index))
if(!recursive_member.has_value())
continue;

// We need to inspect the access path as the resulting expression may

Check warning on line 117 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L115-L117

Added lines #L115 - L117 were not covered by tests
// involve index expressions. When array field sensitivity is disabled
// or the size of the array that is indexed into is larger than
// max_field_sensitivity_array_size then only the expression up to (but
// excluding) said index expression can be turned into an ssa_exprt.

Check warning on line 121 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L119-L121

Added lines #L119 - L121 were not covered by tests
exprt full_exprt = *recursive_member;
exprt *for_ssa = &full_exprt;
exprt *parent = for_ssa;

Check warning on line 124 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L124

Added line #L124 was not covered by tests
while(parent->id() == ID_typecast)
parent = &to_typecast_expr(*parent).op();
while(parent->id() == ID_member || parent->id() == ID_index)
{
tmp.type() = be.type();
tmp.set_expression(*recursive_member);
if(parent->id() == ID_member)
{

Check warning on line 130 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L130

Added line #L130 was not covered by tests
parent = &to_member_expr(*parent).compound();
}
else
{

Check warning on line 134 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L134

Added line #L134 was not covered by tests
parent = &to_index_expr(*parent).array();
#ifdef ENABLE_ARRAY_FIELD_SENSITIVITY
if(
!to_array_type(parent->type()).size().is_constant() ||
numeric_cast_v<mp_integer>(
to_constant_expr(to_array_type(parent->type()).size())) >
max_field_sensitivity_array_size)
{
for_ssa = parent;
}
#else
for_ssa = parent;
#endif // ENABLE_ARRAY_FIELD_SENSITIVITY

Check warning on line 147 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L147

Added line #L147 was not covered by tests
}
}

if(for_ssa->id() == ID_index || for_ssa->id() == ID_member)
{

Check warning on line 152 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L152

Added line #L152 was not covered by tests
tmp.type() = for_ssa->type();
tmp.set_expression(*for_ssa);
if(was_l2)
{
return apply(
ns, state, state.rename(std::move(tmp), ns).get(), write);
*for_ssa =
apply(ns, state, state.rename(std::move(tmp), ns).get(), write);
}
else
return apply(ns, state, std::move(tmp), write);
*for_ssa = apply(ns, state, std::move(tmp), write);

Check warning on line 162 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L162

Added line #L162 was not covered by tests
return full_exprt;
}
else if(
recursive_member.has_value() && recursive_member->id() == ID_typecast)
else if(for_ssa->id() == ID_typecast)
{
if(was_l2)
{
return apply(
ns,
state,
state.rename(std::move(*recursive_member), ns).get(),
write);
*for_ssa =
apply(ns, state, state.rename(*for_ssa, ns).get(), write);

Check warning on line 170 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L169-L170

Added lines #L169 - L170 were not covered by tests
}
else
return apply(ns, state, std::move(*recursive_member), write);
*for_ssa = apply(ns, state, std::move(*for_ssa), write);

Check warning on line 174 in src/goto-symex/field_sensitivity.cpp

View check run for this annotation

Codecov / codecov/patch

src/goto-symex/field_sensitivity.cpp#L174

Added line #L174 was not covered by tests
return full_exprt;
}
}
}
Expand Down
Loading