]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Compiler crash on container aggregate association with nonstatic key choice
authorGary Dismukes <dismukes@adacore.com>
Thu, 21 Aug 2025 18:48:12 +0000 (18:48 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 11 Sep 2025 09:10:48 +0000 (11:10 +0200)
The compiler blows up on a container aggregate with a container element
association that has a key_choice given by a nonstatic key expression.
This happens in the size computation for the aggregate due to calling
Update_Choices with the nonstatic expression.  The fix is simply to
condition the call to Update_Choices on whether the choice expression
is static.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Container_Aggr_Code.Build_Size_Expr): In the case
of an association with a single choice, only call Update_Choices when
the choice expression is nonstatic.

gcc/ada/exp_aggr.adb

index 34d4f84f95e6d22e28bb41937f289438462a78d0..6b4f4a19d1f9cb665a008c700f748a023e883f04 100644 (file)
@@ -6984,7 +6984,9 @@ package body Exp_Aggr is
                --  Choice is a single discrete value
 
                elsif Is_Discrete_Type (Etype (Choice)) then
-                  Update_Choices (Choice, Choice);
+                  if Is_Static_Expression (Choice) then
+                     Update_Choices (Choice, Choice);
+                  end if;
 
                   Temp_Siz_Exp := Make_Integer_Literal (Loc, 1);
                   Set_Is_Static_Expression (Temp_Siz_Exp);