]> gcc.gnu.org Git - gcc.git/commitdiff
ada: Fix visibility error with DIC or Type_Invariant aspect on generic type
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 11 Apr 2023 10:15:22 +0000 (12:15 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 30 May 2023 07:12:15 +0000 (09:12 +0200)
The compiler fails to capture global references during the analysis of the
aspect on the generic type because it analyzes a copy of the expression.

gcc/ada/

* exp_util.adb (Build_DIC_Procedure_Body.Add_Own_DIC): When inside
a generic unit, preanalyze the expression directly.
(Build_Invariant_Procedure_Body.Add_Own_Invariants): Likewise.

gcc/ada/exp_util.adb

index 2582524b1dd83779d0a878fb3abf2524620a1263..4c4844594d2f74e93e8a93d2a92f72e2fb3ae957 100644 (file)
@@ -1853,7 +1853,15 @@ package body Exp_Util is
 
       begin
          pragma Assert (Present (DIC_Expr));
-         Expr := New_Copy_Tree (DIC_Expr);
+
+         --  We need to preanalyze the expression itself inside a generic to
+         --  be able to capture global references present in it.
+
+         if Inside_A_Generic then
+            Expr := DIC_Expr;
+         else
+            Expr := New_Copy_Tree (DIC_Expr);
+         end if;
 
          --  Perform the following substitution:
 
@@ -3111,7 +3119,14 @@ package body Exp_Util is
                   return;
                end if;
 
-               Expr := New_Copy_Tree (Prag_Expr);
+               --  We need to preanalyze the expression itself inside a generic
+               --  to be able to capture global references present in it.
+
+               if Inside_A_Generic then
+                  Expr := Prag_Expr;
+               else
+                  Expr := New_Copy_Tree (Prag_Expr);
+               end if;
 
                --  Substitute all references to type T with references to the
                --  _object formal parameter.
This page took 0.065218 seconds and 5 git commands to generate.