-
Notifications
You must be signed in to change notification settings - Fork 274
Loop-less initialization of primitive arrays #3649
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
Will also be used in java_object_factory
e30da83
to
997d692
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: 997d692).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/95984671
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: 65af890).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/95985244
/// loop. | ||
/// The code produced is of the form (supposing an array of type OBJ): | ||
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
/// struct java.lang.Integer **array_data_init; |
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.
🚫 OBJ?
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.
fixed
@@ -0,0 +1,16 @@ | |||
class NondetArrayPrimitive | |||
{ | |||
void intArray(int[] array) |
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.
Is there a test for non-primitive arrays too?
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.
And byte, char, short, long, double...
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.
Added tests for all primitive types.
Not for non-primitive types as this PR doesn't change behaviour for those.
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 doesn't change behaviour for those.
Is there a test that checks that?
/// Create code to nondeterministically initialize arrays of primitive type. | ||
/// The code produced is of the form: | ||
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
/// int (*array_data_init)[max_length_expr]; |
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 int? Shouldn't it be the primitive type? Or otherwise say 'example'.
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.
fixed
{ | ||
array_typet array_type(element_type, max_length_expr); | ||
|
||
// int (*array_data_init)[max_length_expr]; |
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 int? What about byte, long, ...?
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.
fixed
Makes gen_nondet_array_init smaller and clarifies process.
Get rid of the initilization loop for nondet arrays, so the size of nondeterministic arrays of primitive types no longer depend on the max unwind value.
Array variable name is now of type "dynamic_object" for primitive arrays. "dynamic_N_array" is a name generated by symex_cpp_new when loop-initializing arrays (in remove_java_newt::lower_java_new_array). We no longer loop-initialize primitive arrays.
65af890
to
2d24bbd
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: 2d24bbd).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/95995687
Nondeterministic primitive arrays are now initialized using a single
NONDET
instruction, instead of being initialized element-wise in a loop over the length of the array.This removes the coupling between the length of nondeterministic primitive arrays and the maximum unwind value.
Advantages when dealing with arrays of primitive type:
--max-nondet-array-length
can now be set to a value larger than--unwind
--unwind
lowFor multi-dimensional arrays, only the innermost dimension benefits from loop-less initialization. Higher dimensions are still initialized via a loop, and so are bound by
--unwind
.