Skip to content

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

Merged
merged 8 commits into from
Jan 28, 2019
Merged

Conversation

xbauch
Copy link
Contributor

@xbauch xbauch commented Nov 28, 2018

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.

Copy link
Contributor

@sonodtt sonodtt left a 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 -

Alloc_Symbol.Name := Intern (Alloc_Name);
Alloc_Symbol.PrettyName := Alloc_Symbol.Name;
Alloc_Symbol.BaseName := Alloc_Symbol.Name;
Alloc_Symbol.Mode := Intern ("C");
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@sonodtt sonodtt Dec 7, 2018

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 )

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Set_Cond (Body_Loop, Loop_Test);
Set_Init (I => Body_Loop,
Value => Make_Nil (Sloc (RHS_Element_Type)));
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@@ -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,
Copy link
Contributor

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...

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -0,0 +1,2 @@
VERIFICATION SUCCESSFUL
q
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is q here?

Copy link
Contributor Author

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.

Copy link
Contributor

@sonodtt sonodtt left a 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.

@sonodtt
Copy link
Contributor

sonodtt commented Jan 8, 2019

PR will require additional work to investigate and fix issue w.r. to error
"raised CONSTRAINT_ERROR : Symbol_Table_Info.Symbol_Maps.Insert: attempt to insert key already in map"
Minimal reproduction: define an array of int and also an array of floats.
Investigation WIP by @sonodtt - as part of the general 'fix array stuff' https://diffblue.atlassian.net/browse/ADA-223

@xbauch
Copy link
Contributor Author

xbauch commented Jan 17, 2019

Now builds on #91 --> only review the last two commits.

@xbauch xbauch force-pushed the testsuite/arrays branch 3 times, most recently from 58b3137 to 3bc2d5a Compare January 18, 2019 11:11
Copy link
Contributor

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);

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -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);

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?

Copy link
Contributor Author

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);

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...

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)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Source_Location => Source_Loc)),
Body_Block, 0);
-- --------------------------------------------------
-- TYPECAST VERSION

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code?

Copy link
Contributor Author

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.

@@ -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"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -1114,6 +1276,7 @@ package body Tree_Walk is
U : constant Node_Id := Unit (N);
Unit_Symbol : Symbol;
begin
Add_Malloc_Symbol;

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved.

Range_Check => False,
Value =>
Convert_Uint_To_Hex (Value => Esize (Element_Type) / 8,
Bit_Width => 32));

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?

Copy link
Contributor Author

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);

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?

Copy link
Contributor Author

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

@xbauch xbauch force-pushed the testsuite/arrays branch 2 times, most recently from 3136897 to e4c0de6 Compare January 18, 2019 15:33
@xbauch
Copy link
Contributor Author

xbauch commented Jan 18, 2019

@hannes-steffenhagen-diffblue I split it a bit more meaningfully (the last 7 commits belong here).

@xbauch
Copy link
Contributor Author

xbauch commented Jan 24, 2019

@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;
Copy link
Contributor

@sonodtt sonodtt Jan 25, 2019

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@sonodtt
Copy link
Contributor

sonodtt commented Jan 25, 2019

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.
Sure, it fails, in multiple locations, atm. But we can keep it around as a failing test?
You'll need a test that passes - which you have now have so I'd suggest naming the new test e.g. "write_to_array_element.adb"

Copy link
Contributor

@sonodtt sonodtt left a 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.

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a 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.

Make_Code_Return (Return_Value => Array_Copy,
Source_Location => Source_Loc);

-- NEW VARS FOR MALLOC ALLOCATION
Copy link
Contributor

@sonodtt sonodtt Jan 25, 2019

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')?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

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) {

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)

Copy link
Contributor Author

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);

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;?

Copy link
Contributor Author

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.

Sonny Martin and others added 7 commits January 25, 2019 16:42
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.
@xbauch xbauch force-pushed the testsuite/arrays branch 2 times, most recently from 3dd023f to 965aa1a Compare January 25, 2019 17:05
@xbauch
Copy link
Contributor Author

xbauch commented Jan 25, 2019

@chrisr-diffblue I've reverted the removal of the original test, adding a new, passing one.

@chrisr-diffblue chrisr-diffblue merged commit c61cba5 into diffblue:master Jan 28, 2019
@xbauch xbauch deleted the testsuite/arrays branch March 14, 2019 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants