diff mbox

[Ada] Crash on configuration pragma Check_Policy.

Message ID 20160420101050.GA55529@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 20, 2016, 10:10 a.m. UTC
There are two different syntaxes for this pragma, and the analysis of the
pragma in the new syntax results in the construction of one or more pragmas
in the older form. If the original pragma appears in a configuration file
the generated ones must be inserted in the same file because Insert_Actions
is not usable in the absence of a scope.

Given the following gnat.adc file:

     pragma Check_Policy (Debug => Disable);

The following must compile quietly:

---
proceddure Dummy is
begin
   null;
end;

Tested on x86_64-pc-linux-gnu, committed on trunk

2016-04-20  Ed Schonberg  <schonberg@adacore.com>

	* sem_prag.adb (Analyze_Pragma, case Check_Policy):  If this
	is a configuration pragma and it uses the ARG syntax, insert
	the rewritten pragma after the current one rather than using
	Insert_Actions.
diff mbox

Patch

Index: sem_prag.adb
===================================================================
--- sem_prag.adb	(revision 235240)
+++ sem_prag.adb	(working copy)
@@ -12504,9 +12504,10 @@ 
 
             else
                declare
-                  Arg  : Node_Id;
-                  Argx : Node_Id;
-                  LocP : Source_Ptr;
+                  Arg   : Node_Id;
+                  Argx  : Node_Id;
+                  LocP  : Source_Ptr;
+                  New_P : Node_Id;
 
                begin
                   Arg := Arg1;
@@ -12526,7 +12527,7 @@ 
                      --  Construct equivalent old form syntax Check_Policy
                      --  pragma and insert it to get remaining checks.
 
-                     Insert_Action (N,
+                     New_P :=
                        Make_Pragma (LocP,
                          Chars                        => Name_Check_Policy,
                          Pragma_Argument_Associations => New_List (
@@ -12534,9 +12535,20 @@ 
                              Expression =>
                                Make_Identifier (LocP, Chars (Arg))),
                            Make_Pragma_Argument_Association (Sloc (Argx),
-                             Expression => Argx))));
+                             Expression => Argx)));
 
                      Arg := Next (Arg);
+
+                     --  For a configuration pragma, insert old form in
+                     --  the corresponding file.
+
+                     if Is_Configuration_Pragma then
+                        Insert_After (N, New_P);
+                        Analyze (New_P);
+
+                     else
+                        Insert_Action (N, New_P);
+                     end if;
                   end loop;
 
                   --  Rewrite original Check_Policy pragma to null, since we