aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/layout.adb
diff options
context:
space:
mode:
authorYannick Moy <moy@adacore.com>2021-05-26 10:49:14 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2021-07-08 13:34:18 +0000
commit242c0f4772c6697ba0b27853f153a13970bbded9 (patch)
treec9f457c646e8d3905f33916a7d77f5451d4b2c63 /gcc/ada/layout.adb
parent36fcfed88c7cbb3d55a59cdd077e8b26107148b9 (diff)
downloadgcc-242c0f4772c6697ba0b27853f153a13970bbded9.zip
gcc-242c0f4772c6697ba0b27853f153a13970bbded9.tar.gz
gcc-242c0f4772c6697ba0b27853f153a13970bbded9.tar.bz2
[Ada] Fix on computation of packed array size in case of error
gcc/ada/ * layout.adb (Layout_Type): Add guard before calling Expr_Value.
Diffstat (limited to 'gcc/ada/layout.adb')
-rw-r--r--gcc/ada/layout.adb28
1 files changed, 19 insertions, 9 deletions
diff --git a/gcc/ada/layout.adb b/gcc/ada/layout.adb
index cbc296a..ee8e281 100644
--- 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;