-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
return Val; | ||
end; | ||
else | ||
return Mem; |
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.
So the function is identity for non-C_Enum_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.
Yes. Do you think it's better to be documented? I thought it was obvious.
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. I was just trying to find out if it was intentional.
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.
Maybe worth spelling out if it's not obvious.
(Intern | ||
(Get_Identifier | ||
(Mem))) | ||
.Value; |
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.
So this function returns the initial value for the symbol? What if it's modified?
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 will need to get back to you on that.
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.
@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.
@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? |
305c4de
to
6cda576
Compare
@@ -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; |
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's Mem
?
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 refers to the Member
.
(Intern | ||
(Get_Identifier | ||
(Mem))) | ||
.Value; |
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.
@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; |
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.
Maybe worth spelling out if it's not obvious.
gnat2goto/driver/tree_walk.adb
Outdated
@@ -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) |
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 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?
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.
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.
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 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
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.
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 |
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.
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?
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 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.
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.
Looks good.
d80b716
to
2a6c6fc
Compare
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 |
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 seems sketchy. enumeration_typet
does not have a width field, seems like you're basically invoking UB 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.
The enumeration_typet
doesn't have a width
field, but it has a subtype that has a width
field.
gnat2goto/driver/tree_walk.adb
Outdated
Identifier_Symbol.SymType := Get_Type (N); | ||
Identifier_Symbol.Mode := Intern ("C"); | ||
Identifier_Symbol.Value := Val; | ||
Global_Symbol_Table.Insert (Identifier_Name, Identifier_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.
Should have IsLValue => True
and IsStaticLifetime => True
gnat2goto/driver/tree_walk.adb
Outdated
@@ -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) |
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 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
gnat2goto/driver/tree_walk.adb
Outdated
@@ -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); |
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'm not sure I quite understand what what this here does?
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 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.
a678bb8
to
a52479f
Compare
a52479f
to
0400863
Compare
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