]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix analysis of Extensions_Visible
authorYannick Moy <moy@adacore.com>
Mon, 17 Jun 2024 09:57:55 +0000 (11:57 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 2 Jul 2024 13:20:34 +0000 (15:20 +0200)
Pragma/aspect Extensions_Visible should be analyzed before any
pre/post contracts on a subprogram, as the legality of conversions
of formal parameters to classwide type depends on the value of
Extensions_Visible. Now fixed.

gcc/ada/

* contracts.adb (Analyze_Pragmas_In_Declarations): Analyze
pragmas in two iterations over the list of declarations in
order to analyze some pragmas before others.
* einfo-utils.ads (Get_Pragma): Fix comment.
* sem_prag.ads (Pragma_Significant_To_Subprograms): Fix.
(Pragma_Significant_To_Subprograms_Analyzed_First): Add new
global array to identify these pragmas which should be analyzed
first, which concerns only Extensions_Visible for now.

gcc/ada/contracts.adb
gcc/ada/einfo-utils.ads
gcc/ada/sem_prag.ads

index 9fc9e05db687292d6b8a7fadf5c072e44118fea6..a93bf622aa139a7f487217bb5b8a0781782034ce 100644 (file)
@@ -546,33 +546,41 @@ package body Contracts is
 
    begin
       --  Move through the body's declarations analyzing all pragmas which
-      --  appear at the top of the declarations.
+      --  appear at the top of the declarations. Go over the list twice, so
+      --  that pragmas which should be analyzed first are analyzed in the
+      --  first pass.
 
-      Curr_Decl := First (Declarations (Unit_Declaration_Node (Body_Id)));
-      while Present (Curr_Decl) loop
+      for Pragmas_Analyzed_First in reverse False .. True loop
 
-         if Nkind (Curr_Decl) = N_Pragma then
+         Curr_Decl := First (Declarations (Unit_Declaration_Node (Body_Id)));
+         while Present (Curr_Decl) loop
 
-            if Pragma_Significant_To_Subprograms
-                 (Get_Pragma_Id (Curr_Decl))
-            then
-               Analyze (Curr_Decl);
-            end if;
+            if Nkind (Curr_Decl) = N_Pragma then
 
-         --  Skip the renamings of discriminants and protection fields
+               if Pragma_Significant_To_Subprograms
+                    (Get_Pragma_Id (Curr_Decl))
+                 and then Pragmas_Analyzed_First =
+                   Pragma_Significant_To_Subprograms_Analyzed_First
+                     (Get_Pragma_Id (Curr_Decl))
+               then
+                  Analyze (Curr_Decl);
+               end if;
 
-         elsif Is_Prologue_Renaming (Curr_Decl) then
-            null;
+            --  Skip the renamings of discriminants and protection fields
 
-         --  We have reached something which is not a pragma so we can be sure
-         --  there are no more contracts or pragmas which need to be taken into
-         --  account.
+            elsif Is_Prologue_Renaming (Curr_Decl) then
+               null;
 
-         else
-            exit;
-         end if;
+            --  We have reached something which is not a pragma so we can be
+            --  sure there are no more contracts or pragmas which need to be
+            --  taken into account.
+
+            else
+               exit;
+            end if;
 
-         Next (Curr_Decl);
+            Next (Curr_Decl);
+         end loop;
       end loop;
    end Analyze_Pragmas_In_Declarations;
 
index 01953c35bc34adf203fee24ebeaab9fc45a27ad5..8207576fb89f13528ad553535b3accf3b4e21db1 100644 (file)
@@ -448,6 +448,7 @@ package Einfo.Utils is
    --    Effective_Reads
    --    Effective_Writes
    --    Exceptional_Cases
+   --    Extensions_Visible
    --    Global
    --    Initial_Condition
    --    Initializes
index 59220ea890c2bd40ee00bf212a5ae58e741d7eec..557e045487018ac71e4089ddfc355230a4ff2e21 100644 (file)
@@ -216,6 +216,7 @@ package Sem_Prag is
       Pragma_Contract_Cases      => True,
       Pragma_Depends             => True,
       Pragma_Exceptional_Cases   => True,
+      Pragma_Extensions_Visible  => True,
       Pragma_Ghost               => True,
       Pragma_Global              => True,
       Pragma_Inline              => True,
@@ -238,6 +239,15 @@ package Sem_Prag is
       Pragma_Volatile_Function   => True,
       others                     => False);
 
+   --  The following table lists all pragmas which are relevant to the analysis
+   --  of subprogram bodies and should be analyzed first, because the analysis
+   --  of other pragmas relevant to subprogram bodies depend on them.
+
+   Pragma_Significant_To_Subprograms_Analyzed_First :
+     constant array (Pragma_Id) of Boolean :=
+     (Pragma_Extensions_Visible => True,
+      others                    => False);
+
    -----------------
    -- Subprograms --
    -----------------