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.
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;
 


Reply via email to