Skip to content

Fix UKNI range issue, and add symbols earlier to the symbol table #238

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 2 commits into from
May 28, 2019

Conversation

NlightNFotis
Copy link
Contributor

Fix the range exception problem for UKNI, and also fix another bug where symbols where not being added to the symbol table at the appropriate stage.

This contains two tests that are not fully functional right now due to the problem described in #226

return Val;
end;
else
return Mem;
Copy link
Contributor

Choose a reason for hiding this comment

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

So the function is identity for non-C_Enum_Type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Do you think it's better to be documented? I thought it was obvious.

Copy link
Contributor

Choose a reason for hiding this comment

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

No. I was just trying to find out if it was intentional.

Choose a reason for hiding this comment

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

Maybe worth spelling out if it's not obvious.

(Intern
(Get_Identifier
(Mem)))
.Value;
Copy link
Contributor

Choose a reason for hiding this comment

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

So this function returns the initial value for the symbol? What if it's modified?

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 will need to get back to you on that.

Choose a reason for hiding this comment

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

@xbauch The symbol is a variable, but they stand in for enum members. Since enum members aren't assignable this should be fine, but I'd prefer if exactly what's going on here would be spelled out in a comment or something.

@NlightNFotis
Copy link
Contributor Author

@xbauch I updated the golden results, but something in them doesn't look right. Can you also take a look if there's something out of place?

@NlightNFotis NlightNFotis force-pushed the Range_Exception branch 2 times, most recently from 305c4de to 6cda576 Compare May 20, 2019 11:32
@@ -792,23 +805,44 @@ package body Tree_Walk is

procedure Handle_Parameter (Formal : Entity_Id; Actual : Node_Id);

function Handle_Enum_Symbol_Members (Mem : Irep) return Irep;

Choose a reason for hiding this comment

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

What's Mem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This refers to the Member.

(Intern
(Get_Identifier
(Mem)))
.Value;

Choose a reason for hiding this comment

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

@xbauch The symbol is a variable, but they stand in for enum members. Since enum members aren't assignable this should be fine, but I'd prefer if exactly what's going on here would be spelled out in a comment or something.

return Val;
end;
else
return Mem;

Choose a reason for hiding this comment

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

Maybe worth spelling out if it's not obvious.

@@ -2882,6 +2916,24 @@ package body Tree_Walk is

-- Begin processing for Do_Object_Declaration_Full_Declaration

procedure Register_Identifier_In_Symbol_Table (N : Irep; Val : Irep)

Choose a reason for hiding this comment

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

This seems very similar to other functions we already have. Can you check if something like this doesn't already exist in goto_utils or the like?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's nothing there now, but I remember a PR by Petr that was adding like a couple more similar functions. They should be refactored in the future into one, but not as part of this PR.

Choose a reason for hiding this comment

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

This should probably go into the symbol table. I'm not sure about the arguments either; Rather than having an Irep and requiring ito to be a Symbol_Expr, why not pass in the name and type (which are ultimately what you need) as parameters?

Should also be called something like Declare_Global_Variable?

Also this should probably go into goto_utils

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, because a number of similar functions were introduced recently for very similar reasons, just in different paths, I suggest that this be done as a more organised attempt to refactor these functions and this one, and make sure that the refactored version gets appropriately invoked in the correct places. But I don't think it's within the scope of this PR for this to happen.

@@ -0,0 +1,2 @@
ALL XFAIL Doesn't crash anymore but cbmc does not perform range assertion checks

Choose a reason for hiding this comment

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

Can you add a test that doesn't fail? I believe this should still be doing a range check for things like explicit casts. Also I think @xbauch changed the test script so multiple .adb files in the same directory are linked together instead of running separately?

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 don't think there's any relevant test for this. The range of this PR was for a very particular piece of code (using enum symbols as range constraints) to not crash. This has been fixed, but gnat2goto suffers from a different problem now (it doesn't handle constraints of subtypes correctly). I can't easily think of something that can exercise the fix without falling on its face because of the subtype issue.

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.

@xbauch xbauch mentioned this pull request May 21, 2019
@NlightNFotis NlightNFotis force-pushed the Range_Exception branch 2 times, most recently from d80b716 to 2a6c6fc Compare May 23, 2019 14:48
when others =>
Report_Unhandled_Node_Empty (Upper_Bound,
"Do_Base_Range_Constraint",
"unsupported upper range kind");
end case;

Set_Width (Result_Type, Get_Width (Resolved_Underlying));
if Kind (Resolved_Underlying) = I_C_Enum_Type then

Choose a reason for hiding this comment

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

This seems sketchy. enumeration_typet does not have a width field, seems like you're basically invoking UB 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.

The enumeration_typet doesn't have a width field, but it has a subtype that has a width field.

Identifier_Symbol.SymType := Get_Type (N);
Identifier_Symbol.Mode := Intern ("C");
Identifier_Symbol.Value := Val;
Global_Symbol_Table.Insert (Identifier_Name, Identifier_Symbol);

Choose a reason for hiding this comment

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

Should have IsLValue => True and IsStaticLifetime => True

@@ -2882,6 +2916,24 @@ package body Tree_Walk is

-- Begin processing for Do_Object_Declaration_Full_Declaration

procedure Register_Identifier_In_Symbol_Table (N : Irep; Val : Irep)

Choose a reason for hiding this comment

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

This should probably go into the symbol table. I'm not sure about the arguments either; Rather than having an Irep and requiring ito to be a Symbol_Expr, why not pass in the name and type (which are ultimately what you need) as parameters?

Should also be called something like Declare_Global_Variable?

Also this should probably go into goto_utils

@@ -2907,6 +2961,11 @@ package body Tree_Walk is
Rhs => Init_Expr,
Source_Location => Sloc (N)));
end if;

if not Is_In_Symtab then
Register_Identifier_In_Symbol_Table (Id, Init_Expr);

Choose a reason for hiding this comment

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

I'm not sure I quite understand what what this here does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What this does is that there was a problem where symbols where not added to the symbol table with the values they should have at one path that handled object declarations in the past, and these caused symbol table lookups to fail. This was fixing this.

@NlightNFotis NlightNFotis merged commit 848a85b into diffblue:master May 28, 2019
@NlightNFotis NlightNFotis deleted the Range_Exception branch May 28, 2019 09:51
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.

3 participants