]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Preserve AST structure when copying tree with discrete types
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 17 Oct 2025 08:47:41 +0000 (10:47 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 3 Nov 2025 14:15:18 +0000 (15:15 +0100)
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.

gcc/ada/sem_util.adb

index 5fd2445aa4c3f511c07d751790227c08f5705a74..cacf29c917fb1903a66d3e9bc0b292b240d53f59 100644 (file)
@@ -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