From: Martin Clochard <cloch...@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 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 79bf6da86ca..811942776f5 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
-- 
2.43.0

Reply via email to