https://gcc.gnu.org/g:4d98d5e454ba93941445e0ab960167b6579db14a

commit r16-4996-g4d98d5e454ba93941445e0ab960167b6579db14a
Author: Piotr Trojanek <[email protected]>
Date:   Fri Oct 17 10:47:41 2025 +0200

    ada: Preserve AST structure when copying tree with discrete types
    
    When copying AST we created an orphaned copy of a scalar range. This was
    confusing the compile-time evaluator, because we couldn't determine 
location of
    a scalar range within an IF statement by looking at its parenthood chain.
    
    gcc/ada/ChangeLog:
    
            * sem_util.adb (Update_Semantic_Fields): Preserve tree structure 
when
            copying scalar range of a discrete type.

Diff:
---
 gcc/ada/sem_util.adb | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 5fd2445aa4c3..cacf29c917fb 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -24875,10 +24875,20 @@ package body Sem_Util is
          --  Scalar_Range
 
          if Is_Discrete_Type (Id) then
+
+            --  The scalar range of the source entity had a parent, so the
+            --  scalar range of the newly created entity should also have a
+            --  parent, so that the AST structure is the same.
+
+            pragma Assert (Present (Parent (Scalar_Range (Id))));
+
             Set_Scalar_Range (Id, Node_Id (
               Copy_Field_With_Replacement
                 (Field    => Union_Id (Scalar_Range (Id)),
                  Semantic => True)));
+
+            pragma Assert (No (Parent (Scalar_Range (Id))));
+            Set_Parent (Scalar_Range (Id), Id);
          end if;
 
          --  Scope

Reply via email to