Skip to content

Address clause #260

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
Jul 31, 2019
Merged

Address clause #260

merged 8 commits into from
Jul 31, 2019

Conversation

tjj2017
Copy link
Collaborator

@tjj2017 tjj2017 commented Jun 25, 2019

gnat2goto is crashing when an address representation clause is encountered. The reason is that gnat2goto was assuming that the expression defining the attribute for all representation clauses is an integer literal. This is certainly not the case for an address clause because a subprogram has to be called to convert the given integer value to a private Address type.

This mod separates out address clauses before the expression is evaluated and reports a missing feature. No doubt we will have to deal with address clauses in the future when we decide how to represent and perform some sort of analysis on them.

Assuming that the expression defining the value of a Size or Component_Size attribute is an integer_literal is also too restrictive, it can be a static_expression. I have replaced IntVal which only accepts an integer_literal with Expr_Value which accepts a static_expression and returns its folded value.

I have added a successful test which defined modular types with a Size representation clause with static_expressions.

I have also added a failing test which legally applies a size representation clause to an object but fails. In addition, size representation clauses applied to derived integer types, again legal in Ada, fails in gnat2goto.

The reason for these failures is the unsatisfied assertion:
-- Just check that the front-end already applied this size
-- clause, i .e. that the size of type-irep we already had
-- equals the entity type this clause is applied to (and the
-- size specified in this clause).
pragma Assert
(Entity_Esize =
UI_From_Int (Int (Get_Width (Target_Type_Irep)))
and Entity_Esize = Expression_Value);
I have not tried to fix this as I am unsure of the GOTO representation that is being used.

Target_Type_Irep : constant Irep :=
Follow_Symbol_Type
(Get_Type (Target_Name), Global_Symbol_Table);
Expression_Value : constant Uint := Expr_Value (Expression (N));
Copy link
Contributor

Choose a reason for hiding this comment

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

Effectively, this line is what is changed in this commit. And it seems ok.

Copy link
Contributor

@xbauch xbauch left a comment

Choose a reason for hiding this comment

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

Looks good.

@tjj2017
Copy link
Collaborator Author

tjj2017 commented Jun 27, 2019

In regression tests a different node number is given in test address_clause between Mac and Linux. I have changed the expected test.out file to that for Linux. Probably should avoid having node numbers in test.out.

Updated golden-results

@martin-cs
Copy link
Collaborator

( Please make sure this is synchronised with #233 )

@xbauch
Copy link
Contributor

xbauch commented Jun 28, 2019

( Please make sure this is synchronised with #233 )

As far as I understand, this PR generalises handling the other two representation clauses (size and component_size). However we choose to implement address (via #233 or otherwise) will be possible to plug in next to this PR. So yes, we're in sync.

tjj2017 added 8 commits June 28, 2019 15:53
Use more General Exp_Value rather than IntVal
to determine value of "Size" and "Component_Size"
IntVal expects an integer literal whereas Exp_Value
will accept a static expression and return its
folded value.
derivations of existing types or to object declarations.

Assertion:
                  pragma Assert
                    (Entity_Esize =
                       UI_From_Int (Int (Get_Width (Target_Type_Irep)))
                     and Entity_Esize = Expression_Value);
fails in procedure Handle_Representation_Claise
Probably unwise to have node numbers on regression test outputs.
A little bit more text parsed causing new errors.
@tjj2017
Copy link
Collaborator Author

tjj2017 commented Jun 28, 2019

Rebased to current diffblue/master and updated golden-results

@chrisr-diffblue chrisr-diffblue merged commit 43fe9b2 into diffblue:master Jul 31, 2019
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.

4 participants