-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <assert.h> | ||
|
||
typedef struct stritem | ||
{ | ||
unsigned nkey; | ||
unsigned cas[]; | ||
} item; | ||
|
||
int foo(item *it) | ||
{ | ||
assert(it->cas[0] == 0); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
main.c | ||
--function foo --bounds-check --pointer-check | ||
^\[foo.assertion.1\] line \d+ assertion it->cas\[0\] == 0: FAILURE$ | ||
^\[foo.array_bounds.3\] line \d+ array.cas upper bound in it->cas\[\(.*\)0\]: FAILURE$ | ||
^\[foo.array_bounds.2\] line \d+ array.cas dynamic object upper bound in it->cas\[\(.*\)0\]: FAILURE$ | ||
^\[foo.pointer_dereference.2\] line \d+ dereference failure: pointer invalid in it->cas: SUCCESS$ | ||
^\[foo.pointer_dereference.6\] line \d+ dereference failure: pointer outside object bounds in it->cas: FAILURE$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2672,7 +2672,14 @@ void smt2_convt::convert_struct(const struct_exprt &expr) | |
|
||
// may need to flatten array-theory arrays in there | ||
if(op.type().id() == ID_array) | ||
flatten_array(op); | ||
{ | ||
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 commentThe 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 commentThe 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. |
||
else | ||
convert_expr(op); | ||
|
||
|
@@ -4526,7 +4533,11 @@ void smt2_convt::convert_type(const typet &type) | |
{ | ||
if(use_datatypes) | ||
{ | ||
out << datatype_map.at(type); | ||
const typet &struct_type = type.id() == ID_struct_tag | ||
? ns.follow_tag(to_struct_tag_type(type)) | ||
: type; | ||
CHECK_RETURN(datatype_map.count(struct_type) > 0); | ||
out << datatype_map.at(struct_type); | ||
} | ||
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.
I wasn't properly taking this situation into account when writing this.