-
Notifications
You must be signed in to change notification settings - Fork 12
Testsuite/arrays #83
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
Testsuite/arrays #83
Conversation
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.
Approved with remarks. - update: blocked -
gnat2goto/driver/tree_walk.adb
Outdated
Alloc_Symbol.Name := Intern (Alloc_Name); | ||
Alloc_Symbol.PrettyName := Alloc_Symbol.Name; | ||
Alloc_Symbol.BaseName := Alloc_Symbol.Name; | ||
Alloc_Symbol.Mode := Intern ("C"); |
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 don't see any use of Alloc_Symbol.Value (so no body?) - or further use of Alloc_Symbol.
Just flagging this.
Not enough gnat2goto experience to say if this is likely a problem going forward.
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.
Here CBMC was complaining that __new__array
is not in the symbol table, but it only needed declaration: the definition is in the builtin functions. So I thought the body would be ignored anyway.
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.
FYI. Mostly for future stuff. No big deal - but I get this on the cbmc side:
"**** WARNING: no body for function __new_array"
I think an empty body will do? (this will pass the goto-program validation) - what happens is that if a function is declared but not called (no fn pointer taken etc), then it would not go into the goto-program function_map (nb I havent' verified symbol-table but I think this points to same behaviour). When it is used in any fashion (not just called, e.g. function address is taken to initialise a fn pointer) - then an empty body gets created even when there is only a declaration visible in the sourcecode.
Just a FYI for context - of behaviour that I came across in goto-program validation. So empty body should suffice (fingers crossed).
I'd say this can be fixed later - it is just a warning. ( /opinion )
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.
Empty body might do, but I'm not sure how to create one in gnat2goto. Make_Nil
results in the same warning and New_Irep (I_Code_Block)
breaks CBMC.
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.
Ok. Thanks for extra effort + info - will look into it as part of the array epic.
gnat2goto/driver/tree_walk.adb
Outdated
Set_Cond (Body_Loop, Loop_Test); | ||
Set_Init (I => Body_Loop, | ||
Value => Make_Nil (Sloc (RHS_Element_Type))); |
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.
Have not seen use of aligned name parameters elsewhere - and surprised this passes the compiler?
If it passes, fine, but there's no precedent for this code style.
Nitpick.
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 sure, but GPS provides this layout as a part of it's auto-completion. I mostly like it, but it can get very verbose sometimes.
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've seen this code style in other parts of GNAT.
gnat2goto/driver/tree_walk.adb
Outdated
@@ -3870,6 +3882,8 @@ package body Tree_Walk is | |||
Append_Argument (Call_Args, Param_Symbol (Ptr_Arg)); | |||
Append_Argument (Call_Args, Param_Symbol (Len_Arg)); | |||
Set_Arguments (Call_Inst, Call_Args); | |||
Set_Lhs (I => Call_Inst, |
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.
Lhs_fun_call is set to the LHS of the returned duplicator function. Not sure why it needs that on top of the function return value (?) It's all a bit voodoo...
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 though about it a bit, and it sort of makes sense, i.e. to require function calls to have left-hand sides. Even if a function has a return value, if we didn't store it in the lhs, it would get lost.
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.
Hmm. You're saying as a temporary. I think this could therefore be implicit in the make_code_function_call bla bla function.
The return value would be assigned at the call location - or the function can be called for its side effects (temporary not needed).
But nevermind. If that's how it is - that's how it is.
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 find it unfortunate that the relevant Irep does not require the lhs given that CBMC will fail. I'm not sure if make-function-call is the only place a function can be created, but yes: you are right.
7a485c3
to
4abda44
Compare
034d29b
to
642030c
Compare
@@ -0,0 +1,2 @@ | |||
VERIFICATION SUCCESSFUL | |||
q |
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.
What is q
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.
It's probably an emacs thing.
642030c
to
43d51fc
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.
PR will require additional work to fix the non-terminating loop unrolling in goto-symex. This is WIP by @sonodtt.
PR will require additional work to investigate and fix issue w.r. to error |
43d51fc
to
154dac8
Compare
Now builds on #91 --> only review the last two commits. |
58b3137
to
3bc2d5a
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 needs a lot of cleanup before being merged, i.e. removing "note" type comments, removing unrelated changes, removing commented out code and getting changes into a logical order.
@@ -7,6 +7,6 @@ procedure Func_Args is | |||
end; | |||
begin | |||
C := Assign2 (A + B, B); | |||
pragma Assert (C = 7); | |||
pragma Assert (C = 5); |
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 appears to be unrelated to arrays?
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.
Removed.
gnat2goto/driver/tree_walk.adb
Outdated
@@ -803,6 +805,7 @@ package body Tree_Walk is | |||
end if; | |||
LHS_Idx_Type := Get_Array_Index_Type (Name (N)); | |||
RHS_Idx_Type := Get_Array_Index_Type (Expression (N)); | |||
-- LHS_Length := Make_Integer_Constant (2, LHS_Idx_Type); |
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 is commented out code being added 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.
Sorry, removed.
Builtin : Symbol; | ||
Type_Irep : constant Irep := New_Irep (I_Unsignedbv_Type); | ||
begin | ||
Set_Width (Type_Irep, 64); |
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.
Probably shouldn't be a magic number, but for now we're probably alright in most circumstances. I can think of a few ways to make this more robust, but none of them are particularly nice. I'd just keep a reminder comment in here for now pointing out that this is an assumption, and moreover one that doesn't necessarily hold for target platforms...
gnat2goto/driver/tree_walk.adb
Outdated
Alloc_Symbol.Mode := Intern ("C"); | ||
Global_Symbol_Table.Insert (Intern (Alloc_Name), Alloc_Symbol); | ||
end if; | ||
-- if not (Global_Symbol_Table.Contains (Intern (Alloc_Name))) |
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.
Commented out code?
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.
Removed.
gnat2goto/driver/tree_walk.adb
Outdated
Source_Location => Source_Loc)), | ||
Body_Block, 0); | ||
-- -------------------------------------------------- | ||
-- TYPECAST VERSION |
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.
Commented out code?
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.
Well there were two versions and we wanted to get opinions as to which would be better. I removed the less generic version.
gnat2goto/driver/driver.adb
Outdated
@@ -248,6 +248,7 @@ package body Driver is | |||
|
|||
Global_Symbol_Table.Insert (Start_Name, Start_Symbol); | |||
Follow_Type_Declarations (Global_Symbol_Table, Followed_Symbol_Table); | |||
-- Followed_Symbol_Table.Exclude (Intern ("malloc")); |
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.
Commented out code?
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.
Removed.
gnat2goto/driver/tree_walk.adb
Outdated
@@ -1114,6 +1276,7 @@ package body Tree_Walk is | |||
U : constant Node_Id := Unit (N); | |||
Unit_Symbol : Symbol; | |||
begin | |||
Add_Malloc_Symbol; |
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.
No, this should probably go into driver.adb
or something. I don't think it makes sense to do this once per compilation unit.
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.
Moved.
gnat2goto/driver/tree_walk.adb
Outdated
Range_Check => False, | ||
Value => | ||
Convert_Uint_To_Hex (Value => Esize (Element_Type) / 8, | ||
Bit_Width => 32)); |
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 32 if we hardcoded size_t to 64 bits?
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.
Changed.
Actual3 (13 .. 16) := Actual3 (11 .. 12) & Actual3 (15 .. 16); | ||
Array_Attribs := Actual3'First + Actual3'Last + Actual3'Length; | ||
Actual7(1) := 2; | ||
-- pragma Assert(Actual7(1) =2); |
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.
What does this fail with?
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.
Somewhere in symex flattening. #108
3136897
to
e4c0de6
Compare
@hannes-steffenhagen-diffblue I split it a bit more meaningfully (the last 7 commits belong here). |
dd7abf0
to
1cae3dc
Compare
1cae3dc
to
4dc8bd5
Compare
4dc8bd5
to
8f9d75b
Compare
@sonodtt and @hannes-steffenhagen-diffblue this is now ready for another set of review. I've only added the malloc size fix and a failing test. |
@@ -0,0 +1,7 @@ | |||
procedure Arrays_Access is | |||
type Arr7 is array (1 .. 3) of Integer; |
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.
Nitpick. Rename to Arr3 and Actual3? (or just Arr and Actual)
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.
Done.
I'm not sure we should be removing the body of the old array tests, which documents what was intended to pass as a minimal based on expected state of gnat2goto. |
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.
Approved - subject to consensus on tests.
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 agree with @sonodtt - we shouldn't be removing tests which currently fail. A better approach would be to split the tests into several parts, then XFAIL the ones that currently fail.
gnat2goto/driver/tree_walk.adb
Outdated
Make_Code_Return (Return_Value => Array_Copy, | ||
Source_Location => Source_Loc); | ||
|
||
-- NEW VARS FOR MALLOC ALLOCATION |
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.
If we preserve this line (I'm in favour), then lowercase (and remove 'new')?
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.
Done.
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 dealing with the main problem we've been having
|
||
-- Build a functions: | ||
-- n.b.: the typecast is optional | ||
-- void copy_array(lhs_type* out, rhs_type* in, int len) { |
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've been wondering - isn't this basically just memcpy
? We do model that, for instance a C-program like this:
#include <string.h>
#include <assert.h>
#include <stdlib.h>
int main(void) {
const int array_size = 10;
int *arr = malloc(sizeof(int) * array_size);
int *arr_copy = malloc(sizeof(int) * array_size);
for(int i = 0; i < array_size; ++i) {
arr[i] = i;
}
memcpy(arr_copy, arr, sizeof(int)*array_size);
for(int i = 0; i < array_size; ++i) {
assert(arr_copy[i] == i);
}
}
can be verified just fine. I understand you were having troubles with this function, so maybe that can be mitigated this way? (i.e. you should be able to just call it the same way you deal with malloc
)
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.
will try, ta.
@@ -0,0 +1,7 @@ | |||
procedure Arrays_Access is | |||
type Arr7 is array (1 .. 3) of Integer; | |||
Actual7 : Arr7 := (1,2,3); |
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 this the bit that's triggering your problems with array_copy
on the assign/read task? What if you leave it off, i.e. leave Actual7
uninitialized like this: Actual7 : Arr7;
?
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.
It helped a bit, ta.
Use wrappers for creating parameters and function symbols.
Use wrappers for calling malloc, param creation, etc.
Test tries to write and read from and array index.
3dd023f
to
965aa1a
Compare
@chrisr-diffblue I've reverted the removal of the original test, adding a new, passing one. |
965aa1a
to
007a82c
Compare
Building on #79 (thus only the last commit is new) this fixes the
arrays
test to the point that CBMC parses it. The symex takes a lot of time though.