This patch fixes a compiler abort on an object declaration whose
expression is an aggregate for an unchecked union type. A declaration
for an object of such a type is otherwise treated as a renaming of the
expression (typically an object of the type), but this does work for an
aggregate, which must be resolved and handled as an initial value of
a regular declaration.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_ch3.adb (Analyze_Object_Declaration): If the type is an
Unchecked_Union, and the expression is an aggregate. complete
the analysis and resolution of the aggregate, and treat like a
regular object declaration, instead of as a renaming
declarattion.
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -4564,16 +4564,26 @@ package body Sem_Ch3 is
Set_Ekind (Id, E_Variable);
end if;
- Rewrite (N,
- Make_Object_Renaming_Declaration (Loc,
- Defining_Identifier => Id,
- Subtype_Mark => New_Occurrence_Of (T, Loc),
- Name => E));
-
- Set_Renamed_Object (Id, E);
- Freeze_Before (N, T);
- Set_Is_Frozen (Id);
- goto Leave;
+ -- If the expression is an aggregate it contains the required
+ -- discriminant values but it has not been resolved yet, so do
+ -- it now, and treat it as the initial expression of an object
+ -- declaration, rather than a renaming.
+
+ if Nkind (E) = N_Aggregate then
+ Analyze_And_Resolve (E, T);
+
+ else
+ Rewrite (N,
+ Make_Object_Renaming_Declaration (Loc,
+ Defining_Identifier => Id,
+ Subtype_Mark => New_Occurrence_Of (T, Loc),
+ Name => E));
+
+ Set_Renamed_Object (Id, E);
+ Freeze_Before (N, T);
+ Set_Is_Frozen (Id);
+ goto Leave;
+ end if;
else
-- Ensure that the generated subtype has a unique external name