-
Notifications
You must be signed in to change notification settings - Fork 274
CONTRACTS: handle locals with composite types when checking assigns clauses #6818
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
CONTRACTS: handle locals with composite types when checking assigns clauses #6818
Conversation
9766e9f
to
78f92c9
Compare
@@ -190,6 +190,34 @@ class cfg_infot | |||
return locals.is_local(ident) || symbol.is_parameter; | |||
} | |||
|
|||
/// Returns true iff `expr` is a composite type access on a locally declared | |||
/// or parameter symbol, without any dereference operations. | |||
bool is_access_to_local_composite(const exprt &expr) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe typecasts and byte extract expressions are also possible left-hand sides in goto programs.
78f92c9
to
4bc8724
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6818 +/- ##
========================================
Coverage 77.00% 77.01%
========================================
Files 1594 1594
Lines 184345 184417 +72
========================================
+ Hits 141957 142021 +64
- Misses 42388 42396 +8
Continue to review full report at Codecov.
|
4838f54
to
632828a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @remi-delmas-3000! Only minor comments.
@@ -11,6 +11,7 @@ Date: September 2021 | |||
#ifndef CPROVER_GOTO_INSTRUMENT_CONTRACTS_UTILS_H | |||
#define CPROVER_GOTO_INSTRUMENT_CONTRACTS_UTILS_H | |||
|
|||
// clang-format off |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to add this only in this file? Our https://github.com/diffblue/cbmc/blob/develop/.clang-format doesn't handle includes properly already?
else | ||
{ | ||
throw unsupported_operation_exceptiont( | ||
"is_local_composite_access: unexpected assignment to member of '" + | ||
type.id_string() + "'"); | ||
} | ||
} | ||
else if(expr.id() == ID_if) | ||
{ | ||
return is_local_composite_access(to_if_expr(expr).true_case()) && | ||
is_local_composite_access(to_if_expr(expr).false_case()); | ||
} | ||
else if(expr.id() == ID_typecast) | ||
{ | ||
return is_local_composite_access(to_typecast_expr(expr).op()); | ||
} | ||
else if( | ||
expr.id() == ID_byte_extract_little_endian || | ||
expr.id() == ID_byte_extract_big_endian) | ||
{ | ||
return is_local_composite_access(to_byte_extract_expr(expr).op()); | ||
} | ||
else if(expr.id() == ID_complex_real) | ||
{ | ||
return is_local_composite_access(to_complex_real_expr(expr).op()); | ||
} | ||
else if(expr.id() == ID_complex_imag) | ||
{ | ||
return is_local_composite_access(to_complex_imag_expr(expr).op()); | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not express this cases using regression tests?
Detect and skip checking assignments to members of local symbols that have composite types. Added debug output prints about tracked locations, detected local statics, checked or skipped assignments.
632828a
to
d0b5fb4
Compare
We now detect and skip checking assignments to members of local symbols that have composite types (i.e. local objects are not explicitly tracked and assignments to them are implicitly allowed).
As a results OOB accesses to locals must be checked using
--pointer-checks
.Before, these assignments would cause assigns clause checking to systematically fail, because the targets are not tracked in the write set.
Added debug output prints (when
--verbosity 10
) to give users insight into which targets are tracked, which local statics are automatically included in the write set, which assignments are checked or skipped.