]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix on computation of packed array size in case of error
authorYannick Moy <moy@adacore.com>
Wed, 26 May 2021 08:49:14 +0000 (10:49 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 8 Jul 2021 13:34:18 +0000 (13:34 +0000)
gcc/ada/

* layout.adb (Layout_Type): Add guard before calling Expr_Value.

gcc/ada/layout.adb

index cbc296a6e45f2c825de735a98a855d9f88471b96..ee8e281785e9545335ab6d44f564b1689041cc28 100644 (file)
@@ -513,18 +513,28 @@ package body Layout is
 
             begin
                Get_Index_Bounds (First_Index (E), Lo, Hi);
-               Siz := (Expr_Value (Hi) - Expr_Value (Lo) + 1)
-                 * Component_Size (E);
 
-               --  Do not overwrite a different value of 'Size specified
-               --  explicitly by the user. In that case, also do not set Esize.
+               --  Even if the bounds are known at compile time, they could
+               --  have been replaced by an error node. Check each bound
+               --  explicitly.
 
-               if Unknown_RM_Size (E) or else RM_Size (E) = Siz then
-                  Set_RM_Size (E, Siz);
+               if Compile_Time_Known_Value (Lo)
+                 and then Compile_Time_Known_Value (Hi)
+               then
+                  Siz := (Expr_Value (Hi) - Expr_Value (Lo) + 1)
+                    * Component_Size (E);
+
+                  --  Do not overwrite a different value of 'Size specified
+                  --  explicitly by the user. In that case, also do not set
+                  --  Esize.
 
-                  if Unknown_Esize (E) then
-                     Siz := ((Siz + (Abits - 1)) / Abits) * Abits;
-                     Set_Esize (E, Siz);
+                  if Unknown_RM_Size (E) or else RM_Size (E) = Siz then
+                     Set_RM_Size (E, Siz);
+
+                     if Unknown_Esize (E) then
+                        Siz := ((Siz + (Abits - 1)) / Abits) * Abits;
+                        Set_Esize (E, Siz);
+                     end if;
                   end if;
                end if;
             end;