]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Minor fix in handling of inherited Pre/Post'Class aspect
authorMartin Clochard <clochard@adacore.com>
Tue, 29 Apr 2025 09:36:19 +0000 (11:36 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 1 Jul 2025 08:29:38 +0000 (10:29 +0200)
Mapping of calls to primitive functions in Pre/Post'Class aspects
inherited by derived types was only testing against controlling formals
of the parent subprogram. This lead to missing some calls, because formals
could be rewritten to that of the derived subprogram before the test
happens.

gcc/ada/ChangeLog:

* exp_util.adb (Is_Controlling_Formal_Ref): test scope against
derived subprogram as well.

gcc/ada/exp_util.adb

index 79bf6da86ca9f991d5b701bbae881f1631505975..811942776f5c4c14ce47ddb59a484dee387e4d27 100644 (file)
@@ -1584,7 +1584,9 @@ package body Exp_Util is
                         function Is_Controlling_Formal_Ref
                           (N : Node_Id) return Boolean;
                         --  Returns True if and only if N denotes a reference
-                        --  to a controlling formal declared for Par_Subp.
+                        --  to a controlling formal declared for Par_Subp, or
+                        --  Subp as formals may have been rewritten before the
+                        --  test happens.
 
                         -------------------------------
                         -- Is_Controlling_Formal_Ref --
@@ -1597,7 +1599,7 @@ package body Exp_Util is
                            return Nkind (N) in N_Identifier | N_Expanded_Name
                              and then Is_Formal (Entity (N))
                              and then Is_Controlling_Formal (Entity (N))
-                             and then Scope (Entity (N)) = Par_Subp;
+                             and then Scope (Entity (N)) in Par_Subp | Subp;
                         end Is_Controlling_Formal_Ref;
 
                      --  Start of processing for Expr_Has_Ctrl_Formal_Ref