-
Notifications
You must be signed in to change notification settings - Fork 274
Stop assertion size-of-expr for pointer-checks #4936
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
@@ -1113,7 +1113,8 @@ void goto_checkt::pointer_validity_check( | |||
const exprt &pointer=expr.pointer(); | |||
|
|||
auto size_of_expr_opt = size_of_expr(expr.type(), ns); | |||
CHECK_RETURN(size_of_expr_opt.has_value()); | |||
if(!size_of_expr_opt.has_value()) | |||
return; // in the case of `void*` |
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.
Shouldn't size_of_expr()
also work for void pointers? In that case we should fix size_of_expr()
if possible.
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.
But even if we implement size-of for void
the result will be 0
, right? I'm not sure we should build the address-check
in that case.
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.
sizeof(void)
is undefined in C, some compilers set it to 1 just because there's too much code out there that assumes that void* == char*
. For example, gcc
does this but warns against it with -Wpointer-arith
(in the -Wpedantic
group):
test.c:1:16: warning: invalid application of ‘sizeof’ to a void type [-Wpointer-arith]
int x = sizeof(void);
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.
Ah, I see. It's surprising that we get a dereference expression of a void pointer here.
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.
__CPROVER__start {
char tmp;
void *arg;
if(NONDET(__CPROVER_bool))
arg = NULL;
else
{
arg = (void *)&tmp;
*((void *)&tmp) = NONDET(void);
}
foo(arg);
}
This is what the entry-point looks like.
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.
Wouldn't address_check
below with a zero-sized object still do some good?
Since these can be void-pointers. In this case we simply skip introducing the address-check altogether.
5ce002d
to
199b231
Compare
What is the semantics of a valid |
Well if anything it should be legal to allocate memory, cast it to |
for the SMT2 queries.
Codecov Report
@@ Coverage Diff @@
## develop #4936 +/- ##
===========================================
+ Coverage 69.26% 69.26% +<.01%
===========================================
Files 1307 1307
Lines 108087 108091 +4
===========================================
+ Hits 74866 74872 +6
+ Misses 33221 33219 -2
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.
This PR failed Diffblue compatibility checks (cbmc commit: faf21d0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/120033995
Status will be re-evaluated on next push.
Common spurious failures include: the cbmc commit has disappeared in the mean time (e.g. in a force-push); the author is not in the list of contributors (e.g. first-time contributors); compatibility was already broken by an earlier merge.
The problem is that there's no "valid" semantics for what a
so in that case, what the void* is supposed to be pointing to depends on what we set the handler to... There are lots of similar cases where we have instances of several parameters have nontrivial dependencies between each other, that was (for me) a big part of the motivation for |
Note that it is valid to allocate zero bytes; so to make the first part of your statement work, the would need to make this pass for the case of a zero-sized object. |
I.e., my proposal is to treat the case of |
@@ -1113,7 +1113,8 @@ void goto_checkt::pointer_validity_check( | |||
const exprt &pointer=expr.pointer(); | |||
|
|||
auto size_of_expr_opt = size_of_expr(expr.type(), ns); | |||
CHECK_RETURN(size_of_expr_opt.has_value()); | |||
if(!size_of_expr_opt.has_value()) | |||
return; // in the case of `void*` |
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.
Wouldn't address_check
below with a zero-sized object still do some good?
else if(src_type.id() == ID_empty) | ||
{ | ||
convert_expr(src); | ||
} |
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.
This might actually fix some of the broken-smt-backend
tests - would you mind testing that?
Closing as superseded by #5427. |
Since these can be void-pointers. In this case we simply skip introducing the
address-check altogether. See #4930.