-
Notifications
You must be signed in to change notification settings - Fork 273
Stop asserting positive array size #4928
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
base: develop
Are you sure you want to change the base?
Conversation
@@ -163,7 +163,6 @@ void symbol_factoryt::gen_nondet_array_init( | |||
const auto &size = array_type.size(); | |||
PRECONDITION(size.id() == ID_constant); | |||
auto const array_size = numeric_cast_v<size_t>(to_constant_expr(size)); | |||
DATA_INVARIANT(array_size > 0, "Arrays should have positive size"); |
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 wasn't properly taking this situation into account when writing this.
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 4ad15b4).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/119815198
Codecov Report
@@ Coverage Diff @@
## develop #4928 +/- ##
==========================================
- Coverage 69.29% 69.2% -0.1%
==========================================
Files 1306 1307 +1
Lines 108263 108058 -205
==========================================
- Hits 75023 74777 -246
- Misses 33240 33281 +41
Continue to review full report at Codecov.
|
8cb270e
to
6fd4b0e
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.
This PR failed Diffblue compatibility checks (cbmc commit: b6a8ea3).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/119982431
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.
when generating non-deterministic arrays. Zero-sized arrays are (unfortunately) legal C construct (as for example the regression test shows).
6fd4b0e
to
80b914e
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 80b914e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/119990011
src/solvers/smt2/smt2_conv.cpp
Outdated
CHECK_RETURN_WITH_DIAGNOSTICS(size != 0, "can't convert zero-sized array"); | ||
|
||
if(size == 0) | ||
return; |
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 is suspicious -- this produces an SMT file that might now parse.
Did you want to make that a precondition, and then check at the call site?
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 reverted here to the original CHECK_RETURN
and pushed the check to the above convert_struct
.
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.
The SMT-Lib2 file would not parse!
It should now (I had to fix another, seemingly unrelated, bug in the last commit). I added a test that runs |
src/solvers/smt2/smt2_conv.cpp
Outdated
{ | ||
const array_typet &array_type = to_array_type(op.type()); | ||
const auto &size_expr = array_type.size(); | ||
PRECONDITION(size_expr.id() == ID_constant); |
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.
Not really a precondition, check-return?
df3f3b7
to
fbd8e10
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.
Looks sensible
fbd8e10
to
4a28b11
Compare
4a28b11
to
bc5d042
Compare
when converting to SMT2 queries.
bc5d042
to
30923ab
Compare
@kroening |
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 30923ab).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/121222947
const array_typet &array_type = to_array_type(op.type()); | ||
const auto &size_expr = array_type.size(); | ||
CHECK_RETURN(size_expr.id() == ID_constant); | ||
|
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 prevents using arrays with variable size.
|
||
if(numeric_cast_v<mp_integer>(to_constant_expr(size_expr)) != 0) | ||
flatten_array(op); | ||
} |
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.
In principle, this check would now need to be done in front of every call to flatten array, to make that a precondition of that function.
I think this is the wrong approach. I would let flatten_array handle this case.
@kroening Is this something that has value, and we should rework to get in Or has this been sunset on the basis of other changes (I can see there are merge conflicts). I'm inclined to believe that there's not a lot of enthusiasm for this to get in (given that the last update on this was on 2019) but figured I should ask before I close the PR. |
It certainly makes sense to systematically check that we can do zero-sized arrays with all the solver back-ends. The PR itself is not quite done yet, and would need a bit of work. |
when generating non-deterministic arrays. Zero-sized arrays are (unfortunately)
legal C construct (as for example the regression test shows).