From: Piotr Trojanek <[email protected]>
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.
Tested on x86_64-pc-linux-gnu, committed on master.
---
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 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
--
2.51.0