-
Notifications
You must be signed in to change notification settings - Fork 273
Skip checking frame conditions for local variables #6279
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
Conversation
162103b
to
164cdb6
Compare
Codecov Report
@@ Coverage Diff @@
## develop #6279 +/- ##
===========================================
+ Coverage 75.90% 75.97% +0.06%
===========================================
Files 1492 1503 +11
Lines 162714 163159 +445
===========================================
+ Hits 123511 123962 +451
+ Misses 39203 39197 -6
Continue to review full report at Codecov.
|
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.
Just one comment below.
Other than that, can we add a test case where we assign to a local variable with the same name as the global variable and make sure that things work correctly? Something like:
int x;
void pure()
__CPROVER_assigns()
{
int x;
x++;
}
regression/contracts/chain.sh
Outdated
@@ -44,4 +44,4 @@ elif echo $args_inst | grep -q -- "--dump-c" ; then | |||
rm "${name}-mod.c" | |||
fi | |||
$goto_instrument --show-goto-functions "${name}-mod.gb" | |||
$cbmc "${name}-mod.gb" ${args_cbmc} | |||
$cbmc "${name}-mod.gb" ${args_cbmc} --pointer-primitive-check |
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 think this would make it impossible to test certain behaviors on invalid pointers. Can we add this to the specific test that requires it? We can do so by adding _ --pointer-primitive-check
to the list of flags (note the underscore). For example:
--apply-loop-contracts _ --unsigned-overflow-check |
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 moved the flag to specific test cases. However, which behaviors would we want to test on invalid pointers? If CPROVER API says we can't use these primitives with invalid pointers, we should only use function contracts with --pointer-primitive-check
, right?
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.
We may not specifically be checking any behavior for invalid pointers (although we might want to, in some form, in the future, see: #6238), but within the "contracts" regression suite, we shouldn't necessarily have to always create allocated pointers. Some property checks work just fine with uninitialized pointers and that might be sufficient for some cases.
One last question I have is regarding the need for this check. The memory primitives documentation (http://cprover.diffblue.com/memory-primitives.html) says that the check is necessary only for memory primitives. We don't seem to use them in the test cases directly. Do we generate them during instrumentation?
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.
Do we generate them during instrumentation?
Yes, we do. We rely on them to check frame conditions. We use __CPROVER_same_object
, __CPROVER_POINTER_OFFSET
, and __CPROVER_OBJECT_SIZE
. For instance, take a look at this
cbmc/src/goto-instrument/contracts/assigns.cpp
Lines 68 to 69 in b60259a
// __CPROVER_same_object(lhs, target) | |
condition.push_back(same_object(lhs_ptr, target)); |
164cdb6
to
941f001
Compare
Done! Could you take another look? @SaswatPadhi |
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.
Thanks for adding the new test case.
LGTM modulo a minor comment below.
It avoids unnecessary assertions (improving performance) and it prevents cases where memory primitives are invoked with dead objects. Signed-off-by: Felipe R. Monteiro <[email protected]>
CBMC relies on memory primitives to check frame conditions. We should ensure that regression tests for contracts do not use these primitives with invalid pointers. Signed-off-by: Felipe R. Monteiro <[email protected]>
Signed-off-by: Felipe R. Monteiro <[email protected]>
Signed-off-by: Felipe R. Monteiro <[email protected]>
4d35e6c
to
c305f90
Compare
Resolves #6154
It avoids unnecessary assertions (improving performance) and it prevents cases where memory primitives are invoked with dead objects.