Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 848a85b

Browse files
authoredMay 28, 2019
Merge pull request #238 from NlightNFotis/Range_Exception
Fix UKNI range issue, and add symbols earlier to the symbol table
2 parents 3b69fe6 + 0400863 commit 848a85b

File tree

20 files changed

+179
-66
lines changed

20 files changed

+179
-66
lines changed
 

‎experiments/golden-results/SPARK-tetris-summary.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ Calling function: Process_Declaration
33
Error message: Package declaration
44
Nkind: N_Package_Declaration
55
--
6-
Occurs: 10 times
7-
Calling function: Do_Base_Range_Constraint
8-
Error message: range expression not bitvector type
9-
Nkind: N_Range
10-
--
116
Occurs: 9 times
127
Calling function: Process_Pragma_Declaration
138
Error message: Unsupported pragma: Volatile

‎experiments/golden-results/StratoX-summary.txt

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Calling function: Process_Declaration
88
Error message: Unknown declaration kind
99
Nkind: N_Freeze_Generic_Entity
1010
--
11-
Occurs: 157 times
11+
Occurs: 155 times
1212
Calling function: Do_Function_Call
1313
Error message: func name not in symbol table
1414
Nkind: N_Function_Call
@@ -74,15 +74,15 @@ Error message: Unknown declaration kind
7474
Nkind: N_Null_Statement
7575
--
7676
Occurs: 13 times
77-
Calling function: Do_Constant
78-
Error message: Constant Type not in symbol table
79-
Nkind: N_Integer_Literal
80-
--
81-
Occurs: 13 times
8277
Calling function: Process_Declaration
8378
Error message: Generic instantiation declaration
8479
Nkind: N_Function_Instantiation
8580
--
81+
Occurs: 12 times
82+
Calling function: Do_Constant
83+
Error message: Constant Type not in symbol table
84+
Nkind: N_Integer_Literal
85+
--
8686
Occurs: 11 times
8787
Calling function: Do_Expression
8888
Error message: In
@@ -104,21 +104,11 @@ Error message: Unsupported pragma: Global
104104
Nkind: N_Pragma
105105
--
106106
Occurs: 9 times
107-
Calling function: Do_Procedure_Call_Statement
108-
Error message: sym id not in symbol table
109-
Nkind: N_Procedure_Call_Statement
110-
--
111-
Occurs: 9 times
112107
Calling function: Process_Pragma_Declaration
113108
Error message: Unsupported pragma: Elaborate Body
114109
Nkind: N_Pragma
115110
--
116111
Occurs: 8 times
117-
Calling function: Do_Base_Range_Constraint
118-
Error message: range expression not bitvector type
119-
Nkind: N_Range
120-
--
121-
Occurs: 8 times
122112
Calling function: Process_Declaration
123113
Error message: Generic instantiation declaration
124114
Nkind: N_Package_Instantiation
@@ -204,6 +194,11 @@ Error message: Generic declaration
204194
Nkind: N_Generic_Package_Declaration
205195
--
206196
Occurs: 3 times
197+
Calling function: Do_Procedure_Call_Statement
198+
Error message: sym id not in symbol table
199+
Nkind: N_Procedure_Call_Statement
200+
--
201+
Occurs: 3 times
207202
Calling function: Process_Statement
208203
Error message: Unknown expression kind
209204
Nkind: N_Object_Declaration

‎experiments/golden-results/Tokeneer-summary.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,6 @@ Error message: Abstract type declaration unsupported
8484
Nkind: N_Private_Type_Declaration
8585
--
8686
Occurs: 8 times
87-
Calling function: Do_Base_Range_Constraint
88-
Error message: range expression not bitvector type
89-
Nkind: N_Range
90-
--
91-
Occurs: 8 times
92-
Calling function: Do_Base_Range_Constraint
93-
Error message: unsupported upper range kind
94-
Nkind: N_Identifier
95-
--
96-
Occurs: 8 times
9787
Calling function: Process_Pragma_Declaration
9888
Error message: Unknown pragma
9989
Nkind: N_Pragma

‎experiments/golden-results/UKNI-Information-Barrier-summary.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ Calling function: Do_Itype_Definition
1818
Error message: Unknown Ekind
1919
Nkind: N_Defining_Identifier
2020
--
21-
Occurs: 2 times
22-
Calling function: Do_Base_Range_Constraint
23-
Error message: range expression not bitvector type
24-
Nkind: N_Range
25-
--
2621
Occurs: 1 times
2722
Calling function: Process_Declaration
2823
Error message: Use package clause declaration

‎experiments/golden-results/muen-summary.txt

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ Error message: Unsupported pragma: Abstract state
5454
Nkind: N_Pragma
5555
--
5656
Occurs: 11 times
57-
Calling function: Do_Constant
58-
Error message: Constant Type not in symbol table
59-
Nkind: N_Integer_Literal
60-
--
61-
Occurs: 11 times
6257
Calling function: Process_Pragma_Declaration
6358
Error message: Unsupported pragma: Initializes
6459
Nkind: N_Pragma
6560
--
6661
Occurs: 10 times
62+
Calling function: Do_Constant
63+
Error message: Constant Type not in symbol table
64+
Nkind: N_Integer_Literal
65+
--
66+
Occurs: 10 times
6767
Calling function: Do_Type_Definition
6868
Error message: Unknown expression kind
6969
Nkind: N_Access_Function_Definition
@@ -73,11 +73,6 @@ Calling function: Process_Declaration
7373
Error message: Package declaration
7474
Nkind: N_Package_Declaration
7575
--
76-
Occurs: 9 times
77-
Calling function: Do_Function_Call
78-
Error message: func name not in symbol table
79-
Nkind: N_Function_Call
80-
--
8176
Occurs: 8 times
8277
Calling function: Do_Itype_Integer_Subtype
8378
Error message: Non-literal bound unsupported
@@ -99,16 +94,16 @@ Error message: Unsupported pragma: Global
9994
Nkind: N_Pragma
10095
--
10196
Occurs: 7 times
97+
Calling function: Do_Function_Call
98+
Error message: func name not in symbol table
99+
Nkind: N_Function_Call
100+
--
101+
Occurs: 7 times
102102
Calling function: Process_Declaration
103103
Error message: Generic instantiation declaration
104104
Nkind: N_Function_Instantiation
105105
--
106106
Occurs: 6 times
107-
Calling function: Do_Base_Range_Constraint
108-
Error message: range expression not bitvector type
109-
Nkind: N_Range
110-
--
111-
Occurs: 6 times
112107
Calling function: Process_Pragma_Declaration
113108
Error message: Unsupported pragma: Precondition
114109
Nkind: N_Pragma
@@ -149,11 +144,6 @@ Error message: Etype not a type
149144
Nkind: N_Identifier
150145
--
151146
Occurs: 2 times
152-
Calling function: Do_Procedure_Call_Statement
153-
Error message: sym id not in symbol table
154-
Nkind: N_Procedure_Call_Statement
155-
--
156-
Occurs: 2 times
157147
Calling function: Do_Type_Definition
158148
Error message: Unknown expression kind
159149
Nkind: N_Access_Procedure_Definition

‎experiments/golden-results/vct-summary.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ Calling function: Process_Declaration
33
Error message: Exception declaration
44
Nkind: N_Exception_Declaration
55
--
6-
Occurs: 32 times
7-
Calling function: Do_Base_Range_Constraint
8-
Error message: unsupported upper range kind
9-
Nkind: N_Identifier
10-
--
116
Occurs: 18 times
127
Calling function: Do_Operator_General
138
Error message: Concat unsupported
@@ -132,3 +127,13 @@ Occurs: 1 times
132127
+===========================GNAT BUG DETECTED==============================+
133128
| GNU Ada (ada2goto) Assert_Failure failed precondition from range_check.ads:29|
134129
| Error detected at system.ads:156:5 |
130+
--
131+
Occurs: 1 times
132+
+===========================GNAT BUG DETECTED==============================+
133+
| GNU Ada (ada2goto) Assert_Failure failed precondition from range_check.ads:29|
134+
| Error detected at system.ads:156:5 |
135+
--
136+
Occurs: 1 times
137+
+===========================GNAT BUG DETECTED==============================+
138+
| GNU Ada (ada2goto) Assert_Failure failed precondition from range_check.ads:29|
139+
| Error detected at system.ads:156:5 |

‎gnat2goto/driver/goto_utils.adb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,21 @@ package body GOTO_Utils is
473473
(Get_Type (Function_Expr)),
474474
Source_Location => Source_Location);
475475
end Make_Simple_Side_Effect_Expr_Function_Call;
476+
477+
procedure Register_Identifier_In_Symbol_Table
478+
(N : Irep; Val : Irep; Symtab : in out Symbol_Table) is
479+
Identifier_Name : constant Symbol_Id :=
480+
Intern (Get_Identifier (N));
481+
Identifier_Symbol : Symbol;
482+
begin
483+
Identifier_Symbol.Name := Identifier_Name;
484+
Identifier_Symbol.BaseName := Identifier_Name;
485+
Identifier_Symbol.PrettyName := Identifier_Name;
486+
Identifier_Symbol.SymType := Get_Type (N);
487+
Identifier_Symbol.IsLValue := True;
488+
Identifier_Symbol.IsStaticLifetime := True;
489+
Identifier_Symbol.Mode := Intern ("C");
490+
Identifier_Symbol.Value := Val;
491+
Symtab.Insert (Identifier_Name, Identifier_Symbol);
492+
end Register_Identifier_In_Symbol_Table;
476493
end GOTO_Utils;

‎gnat2goto/driver/goto_utils.ads

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,8 @@ package GOTO_Utils is
138138
Function_Expr : Irep;
139139
Source_Location : Source_Ptr) return Irep;
140140

141+
procedure Register_Identifier_In_Symbol_Table
142+
(N : Irep; Val : Irep; Symtab : in out Symbol_Table)
143+
with Pre => Kind (N) = I_Symbol_Expr;
144+
141145
end GOTO_Utils;

‎gnat2goto/driver/tree_walk.adb

Lines changed: 49 additions & 5 deletions
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,46 @@ 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
822+
(if Kind (Val) = I_Op_Typecast
823+
then Get_Op0 (Val) else Val);
824+
end;
825+
else
826+
return Mem;
827+
end if;
828+
end Handle_Enum_Symbol_Members;
829+
795830
----------------------
796831
-- Handle_Parameter --
797832
----------------------
798833

799834
procedure Handle_Parameter (Formal : Entity_Id; Actual : Node_Id) is
800835
Is_Out : constant Boolean := Out_Present (Parent (Formal));
801836
Actual_Irep : Irep;
802-
837+
Expression : constant Irep := Do_Expression (Actual);
803838
begin
804839
if Is_Out and then
805-
not (Kind (Get_Type (Do_Expression (Actual))) in Class_Type)
840+
not (Kind (Get_Type (Expression)) in Class_Type)
806841
then
807842
Report_Unhandled_Node_Empty (Actual, "Handle_Parameter",
808843
"Kind of actual not in class type");
809844
return;
810845
end if;
811-
Actual_Irep := Wrap_Argument (Do_Expression (Actual), Is_Out);
846+
Actual_Irep := Wrap_Argument (
847+
Handle_Enum_Symbol_Members (Expression), Is_Out);
812848
Append_Argument (Args, Actual_Irep);
813849
end Handle_Parameter;
814850

@@ -2882,6 +2918,8 @@ package body Tree_Walk is
28822918

28832919
-- Begin processing for Do_Object_Declaration_Full_Declaration
28842920

2921+
Is_In_Symtab : constant Boolean :=
2922+
Global_Symbol_Table.Contains (Intern (Get_Identifier (Id)));
28852923
begin
28862924
Set_Source_Location (Decl, (Sloc (N)));
28872925
Set_Symbol (Decl, Id);
@@ -2907,6 +2945,12 @@ package body Tree_Walk is
29072945
Rhs => Init_Expr,
29082946
Source_Location => Sloc (N)));
29092947
end if;
2948+
2949+
if not Is_In_Symtab then
2950+
Register_Identifier_In_Symbol_Table
2951+
(Id, Init_Expr, Global_Symbol_Table);
2952+
end if;
2953+
29102954
end Do_Object_Declaration_Full;
29112955

29122956
-------------------------
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
procedure Range_Constraint 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+
-- this particular test is testing a syntactic fix for ranges constraint by enum symbols.
11+
subtype Result_Indicator_Type is Indicator_Type range CALIBRATION_PASS .. MEASUREMENT_NOT_PROVEN;
12+
begin
13+
null;
14+
end Range_Constraint;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERIFICATION SUCCESSFUL
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from test_support import *
2+
3+
prove()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
procedure Range_Constraint 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+
-- this test is here because subtype assignment is broken and needs to be activated againt when fixed
13+
Value : constant Result_Indicator_Type := CALIBRATION_FAIL;
14+
begin
15+
pragma assert (Value = CALIBRATION_FAIL);
16+
end Range_Constraint;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALL XFAIL symex is crashing at the assignment because of wrong code generation.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERIFICATION SUCCESSFUL
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from test_support import *
2+
3+
prove()
Lines changed: 20 additions & 0 deletions
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;
Lines changed: 14 additions & 0 deletions
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;
Lines changed: 2 additions & 0 deletions
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+
Lines changed: 3 additions & 0 deletions
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)
Please sign in to comment.