From: Piotr Trojanek Date: Fri, 17 Oct 2025 08:47:41 +0000 (+0200) Subject: ada: Preserve AST structure when copying tree with discrete types X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4d98d5e454ba93941445e0ab960167b6579db14a;p=thirdparty%2Fgcc.git 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 --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 5fd2445aa4c..cacf29c917f 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