Skip to content

Commit 2682fbc

Browse files
Merge pull request #246 from chrisr-diffblue/feature/pragma-declaration-volatile
Feature/pragma declaration volatile
2 parents bd18b02 + 78580cc commit 2682fbc

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
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: 9 times
7-
Calling function: Process_Pragma_Declaration
8-
Error message: Unsupported pragma: Volatile
9-
Nkind: N_Pragma
10-
--
116
Occurs: 1 times
127
Calling function: Process_Declaration
138
Error message: Representation clause unsupported: component_size

experiments/golden-results/UKNI-Information-Barrier-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: Representation clause unsupported: address
44
Nkind: N_Attribute_Definition_Clause
55
--
6-
Occurs: 37 times
7-
Calling function: Process_Pragma_Declaration
8-
Error message: Unsupported pragma: Volatile
9-
Nkind: N_Pragma
10-
--
116
Occurs: 8 times
127
Calling function: Process_Declaration
138
Error message: Representation clause unsupported: component_size

gnat2goto/driver/tree_walk.adb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4761,6 +4761,28 @@ package body Tree_Walk is
47614761
end Process_Declaration;
47624762

47634763
procedure Process_Pragma_Declaration (N : Node_Id) is
4764+
procedure Handle_Pragma_Volatile (N : Node_Id);
4765+
4766+
procedure Handle_Pragma_Volatile (N : Node_Id) is
4767+
Argument_Associations : constant List_Id :=
4768+
Pragma_Argument_Associations (N);
4769+
First_Argument_Expression : constant Node_Id :=
4770+
Expression (First (Argument_Associations));
4771+
Expression_Id : constant Symbol_Id :=
4772+
Intern (Unique_Name (Entity (First_Argument_Expression)));
4773+
4774+
procedure Set_Volatile (Key : Symbol_Id; Element : in out Symbol);
4775+
procedure Set_Volatile (Key : Symbol_Id; Element : in out Symbol) is
4776+
begin
4777+
pragma Assert (Unintern (Key) = Unintern (Expression_Id));
4778+
Element.IsVolatile := True;
4779+
end Set_Volatile;
4780+
begin
4781+
pragma Assert (Global_Symbol_Table.Contains (Expression_Id));
4782+
Global_Symbol_Table.Update_Element (
4783+
Position => Global_Symbol_Table.Find (Expression_Id),
4784+
Process => Set_Volatile'Access);
4785+
end Handle_Pragma_Volatile;
47644786
begin
47654787
case Pragma_Name (N) is
47664788
when Name_Assert |
@@ -4819,8 +4841,7 @@ package body Tree_Walk is
48194841
-- they may be modified by the environment. Effectively, they need
48204842
-- to be modelled as non-deterministic input in every state. It
48214843
-- changes the semantics wrt to thread interleavings.
4822-
Report_Unhandled_Node_Empty (N, "Process_Pragma_Declaration",
4823-
"Unsupported pragma: Volatile");
4844+
Handle_Pragma_Volatile (N);
48244845
when Name_Attach_Handler =>
48254846
-- The expression in the Attach_Handler pragma as evaluated at
48264847
-- object creation time specifies an interrupt. As part of the
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[1] file volatile_type.adb line 14 assertion: SUCCESS
2+
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 Volatile_Type is
2+
Data: Integer;
3+
pragma Volatile(Data);
4+
Flag: Boolean;
5+
pragma Volatile(Flag);
6+
begin
7+
Data := 42;
8+
Flag := True;
9+
10+
if not Flag then
11+
Data := 0;
12+
end if;
13+
14+
pragma Assert (Data=42);
15+
16+
end Volatile_Type;

0 commit comments

Comments
 (0)