[Ada] Freeze aspect expression relocated to pragma Precondition

Message ID 20200707092736.GA41591@adacore.com
State New
Headers show
Series
  • [Ada] Freeze aspect expression relocated to pragma Precondition
Related show

Commit Message

Pierre-Marie de Rodat July 7, 2020, 9:27 a.m.
In Analyze_Aspect_Specification we relocate expression of a Pre aspect
to pragma Precondition. From this point we now only process the
relocated expression; in particular, we freeze it and then copy to a
pragma Check (which will ultimately execute this expression when
subprogram is called).

This fixes a bug where freezing of the original expression (in
particular its analysis) was breaking the Parent links in the relocated
expression.  Then validity checks for this precondition expression were
inserted next to the original aspect, i.e. outside of the subprogram
body.

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

gcc/ada/

	* contracts.adb (Analyze_Entry_Or_Subprogram_Contract,
	Process_Preconditions_For): Freeze expression that has been
	relocated to pragma Precondition, not the expression which is
	still in the aspect.

Patch

diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -653,7 +653,9 @@  package body Contracts is
                      Freeze_Expr_Types
                        (Def_Id => Subp_Id,
                         Typ    => Standard_Boolean,
-                        Expr   => Expression (Corresponding_Aspect (Prag)),
+                        Expr   =>
+                          Expression
+                            (First (Pragma_Argument_Associations (Prag))),
                         N      => Bod);
                   end if;
 
@@ -2603,7 +2605,9 @@  package body Contracts is
                         Freeze_Expr_Types
                           (Def_Id => Subp_Id,
                            Typ    => Standard_Boolean,
-                           Expr   => Expression (Corresponding_Aspect (Prag)),
+                           Expr   =>
+                             Expression
+                               (First (Pragma_Argument_Associations (Prag))),
                            N      => Body_Decl);
                      end if;