public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix on computation of packed array size in case of error
@ 2021-07-08 13:50 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-07-08 13:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: Yannick Moy

[-- Attachment #1: Type: text/plain, Size: 317 bytes --]

In case of compilation error, the low and high bounds of the array
type might have been replaced by an error node. Deal with this case
by checking that the bounds are known at compile time.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

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

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1748 bytes --]

diff --git a/gcc/ada/layout.adb b/gcc/ada/layout.adb
--- a/gcc/ada/layout.adb
+++ b/gcc/ada/layout.adb
@@ -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;



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-08 13:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 13:50 [Ada] Fix on computation of packed array size in case of error Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).