Skip to content

Commit b3c95ba

Browse files
committed
Fix UKNI range issue, and add symbols earlier to the symbol table
1 parent 5f5d388 commit b3c95ba

File tree

5 files changed

+101
-5
lines changed

5 files changed

+101
-5
lines changed

gnat2goto/driver/tree_walk.adb

+62-5
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,9 @@ package body Tree_Walk is
743743

744744
Result_Type : constant Irep := New_Irep (I_Bounded_Signedbv_Type);
745745
begin
746-
if not (Kind (Resolved_Underlying) in Class_Bitvector_Type) then
746+
if not (Kind (Resolved_Underlying) in Class_Bitvector_Type or
747+
Kind (Resolved_Underlying) = I_C_Enum_Type)
748+
then
747749
return Report_Unhandled_Node_Type (Range_Expr,
748750
"Do_Base_Range_Constraint",
749751
"range expression not bitvector type");
@@ -754,6 +756,9 @@ package body Tree_Walk is
754756
Store_Nat_Bound (Bound_Type_Nat (Intval (Lower_Bound)));
755757
when N_Attribute_Reference => Lower_Bound_Value :=
756758
Store_Symbol_Bound (Get_Array_Attr_Bound_Symbol (Lower_Bound));
759+
when N_Identifier =>
760+
Lower_Bound_Value :=
761+
Store_Symbol_Bound (Bound_Type_Symbol (Lower_Bound));
757762
when others =>
758763
Report_Unhandled_Node_Empty (Lower_Bound,
759764
"Do_Base_Range_Constraint",
@@ -765,13 +770,21 @@ package body Tree_Walk is
765770
Store_Nat_Bound (Bound_Type_Nat (Intval (Upper_Bound)));
766771
when N_Attribute_Reference => Upper_Bound_Value :=
767772
Store_Symbol_Bound (Get_Array_Attr_Bound_Symbol (Upper_Bound));
773+
when N_Identifier =>
774+
Upper_Bound_Value :=
775+
Store_Symbol_Bound (Bound_Type_Symbol (Upper_Bound));
768776
when others =>
769777
Report_Unhandled_Node_Empty (Upper_Bound,
770778
"Do_Base_Range_Constraint",
771779
"unsupported upper range kind");
772780
end case;
773781

774-
Set_Width (Result_Type, Get_Width (Resolved_Underlying));
782+
if Kind (Resolved_Underlying) = I_C_Enum_Type then
783+
Set_Width (Result_Type,
784+
Get_Width (Get_Subtype (Resolved_Underlying)));
785+
else
786+
Set_Width (Result_Type, Get_Width (Resolved_Underlying));
787+
end if;
775788
Set_Lower_Bound (Result_Type, Lower_Bound_Value);
776789
Set_Upper_Bound (Result_Type, Upper_Bound_Value);
777790
return Result_Type;
@@ -792,23 +805,44 @@ package body Tree_Walk is
792805

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

808+
function Handle_Enum_Symbol_Members (Mem : Irep) return Irep;
809+
function Handle_Enum_Symbol_Members (Mem : Irep) return Irep is
810+
Followed_Type_Symbol : constant Irep :=
811+
Follow_Symbol_Type (Get_Type (Mem), Global_Symbol_Table);
812+
begin
813+
if Kind (Followed_Type_Symbol) = I_C_Enum_Type then
814+
declare
815+
Val : constant Irep := Global_Symbol_Table
816+
(Intern
817+
(Get_Identifier
818+
(Mem)))
819+
.Value;
820+
begin
821+
return Val;
822+
end;
823+
else
824+
return Mem;
825+
end if;
826+
end Handle_Enum_Symbol_Members;
827+
795828
----------------------
796829
-- Handle_Parameter --
797830
----------------------
798831

799832
procedure Handle_Parameter (Formal : Entity_Id; Actual : Node_Id) is
800833
Is_Out : constant Boolean := Out_Present (Parent (Formal));
801834
Actual_Irep : Irep;
802-
835+
Expression : constant Irep := Do_Expression (Actual);
803836
begin
804837
if Is_Out and then
805-
not (Kind (Get_Type (Do_Expression (Actual))) in Class_Type)
838+
not (Kind (Get_Type (Expression)) in Class_Type)
806839
then
807840
Report_Unhandled_Node_Empty (Actual, "Handle_Parameter",
808841
"Kind of actual not in class type");
809842
return;
810843
end if;
811-
Actual_Irep := Wrap_Argument (Do_Expression (Actual), Is_Out);
844+
Actual_Irep := Wrap_Argument (
845+
Handle_Enum_Symbol_Members (Expression), Is_Out);
812846
Append_Argument (Args, Actual_Irep);
813847
end Handle_Parameter;
814848

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

28832917
-- Begin processing for Do_Object_Declaration_Full_Declaration
28842918

2919+
procedure Register_Identifier_In_Symbol_Table (N : Irep; Val : Irep)
2920+
with Pre => Kind (N) = I_Symbol_Expr;
2921+
procedure Register_Identifier_In_Symbol_Table (N : Irep; Val : Irep) is
2922+
Identifier_Name : constant Symbol_Id :=
2923+
Intern (Get_Identifier (N));
2924+
Identifier_Symbol : Symbol;
2925+
begin
2926+
Identifier_Symbol.Name := Identifier_Name;
2927+
Identifier_Symbol.BaseName := Identifier_Name;
2928+
Identifier_Symbol.PrettyName := Identifier_Name;
2929+
Identifier_Symbol.SymType := Get_Type (N);
2930+
Identifier_Symbol.Mode := Intern ("C");
2931+
Identifier_Symbol.Value := Val;
2932+
Global_Symbol_Table.Insert (Identifier_Name, Identifier_Symbol);
2933+
end Register_Identifier_In_Symbol_Table;
2934+
2935+
Is_In_Symtab : constant Boolean :=
2936+
Global_Symbol_Table.Contains (Intern (Get_Identifier (Id)));
28852937
begin
28862938
Set_Source_Location (Decl, (Sloc (N)));
28872939
Set_Symbol (Decl, Id);
@@ -2907,6 +2959,11 @@ package body Tree_Walk is
29072959
Rhs => Init_Expr,
29082960
Source_Location => Sloc (N)));
29092961
end if;
2962+
2963+
if not Is_In_Symtab then
2964+
Register_Identifier_In_Symbol_Table (Id, Init_Expr);
2965+
end if;
2966+
29102967
end Do_Object_Declaration_Full;
29112968

29122969
-------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
procedure Range_Second is
2+
type Indicator_Type is (
3+
CALIBRATION_MODE,
4+
MEASUREMENT_MODE,
5+
CALIBRATION_PASS,
6+
CALIBRATION_FAIL,
7+
MEASUREMENT_NOT_PROVEN,
8+
MEASUREMENT_PRESENT);
9+
10+
subtype Result_Indicator_Type is Indicator_Type range CALIBRATION_PASS .. MEASUREMENT_NOT_PROVEN;
11+
12+
procedure Testable (Result : Result_Indicator_Type) is
13+
begin
14+
null;
15+
end Testable;
16+
17+
begin
18+
Testable (CALIBRATION_PASS);
19+
Testable (MEASUREMENT_PRESENT);
20+
end Range_Second;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
procedure Range_Second is
2+
type An_Int is range 1..1000;
3+
subtype Another_Int is An_Int range 5..100;
4+
5+
procedure Testable (Result : An_Int) is
6+
test_val : Another_Int := Result;
7+
begin
8+
null;
9+
end Testable;
10+
11+
begin
12+
Testable (50);
13+
Testable (200);
14+
end Range_Second;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALL XFAIL Doesn't crash anymore but cbmc does not perform range assertion checks
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from test_support import *
2+
3+
prove()

0 commit comments

Comments
 (0)