https://gcc.gnu.org/g:709bf32c15dc104827d792897dc85408fabb2557

commit r16-1843-g709bf32c15dc104827d792897dc85408fabb2557
Author: Martin Clochard <cloch...@adacore.com>
Date:   Tue Apr 29 11:36:19 2025 +0200

    ada: Minor fix in handling of inherited Pre/Post'Class aspect
    
    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.

Diff:
---
 gcc/ada/exp_util.adb | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 79bf6da86ca9..811942776f5c 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -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

Reply via email to