https://gcc.gnu.org/g:aa086b7bf86945c1448fee665b8289c39dbcb743

commit r15-6726-gaa086b7bf86945c1448fee665b8289c39dbcb743
Author: Javier Miranda <mira...@adacore.com>
Date:   Wed Dec 25 06:42:10 2024 +0000

    ada: Cleanup preanalysis of static expressions (part 3)
    
    Avoid reporting spurious errors.
    
    gcc/ada/ChangeLog:
    
            * freeze.adb (Freeze_Expr_Types): Reverse patch; that is, restore
            calls to Preanalyze_Spec_Expression instead of 
Preanalyze_And_Resolve
            for the sake of consistency with Analyze_Expression_Function. Patch
            suggested by Eric Botcazou.
            * exp_put_image.adb (Image_Should_Call_Put_Image): Ensure that
            function Defining_Identifier is called with a proper node to
            avoid internal assertion failure.

Diff:
---
 gcc/ada/exp_put_image.adb | 2 ++
 gcc/ada/freeze.adb        | 8 +++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/exp_put_image.adb b/gcc/ada/exp_put_image.adb
index 38bde44ff5af..ae5fa40fa380 100644
--- a/gcc/ada/exp_put_image.adb
+++ b/gcc/ada/exp_put_image.adb
@@ -1190,6 +1190,8 @@ package body Exp_Put_Image is
          --  aspects, not just for Put_Image?
 
          if Is_Itype (U_Type)
+           and then Nkind (Associated_Node_For_Itype (U_Type)) in
+                      N_Full_Type_Declaration | N_Subtype_Declaration
            and then Has_Aspect (Defining_Identifier
                                   (Associated_Node_For_Itype (U_Type)),
                                 Aspect_Put_Image)
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 10f0de78d9d7..54b620214e80 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -9389,14 +9389,16 @@ package body Freeze is
       --  pre/postconditions during expansion of the subprogram body, the
       --  subprogram is already installed.
 
+      --  Call Preanalyze_Spec_Expression instead of Preanalyze_And_Resolve
+      --  for the sake of consistency with Analyze_Expression_Function.
+
       if Def_Id /= Current_Scope then
          Push_Scope (Def_Id);
          Install_Formals (Def_Id);
-
-         Preanalyze_And_Resolve (Dup_Expr, Typ);
+         Preanalyze_Spec_Expression (Dup_Expr, Typ);
          End_Scope;
       else
-         Preanalyze_And_Resolve (Dup_Expr, Typ);
+         Preanalyze_Spec_Expression (Dup_Expr, Typ);
       end if;
 
       --  Restore certain attributes of Def_Id since the preanalysis may

Reply via email to