aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Baird <baird@adacore.com>2020-05-13 10:38:35 -0700
committerPierre-Marie de Rodat <derodat@adacore.com>2020-07-07 05:26:58 -0400
commit1c4b5a795ad772b0d80d18757593808044b14e90 (patch)
treec52d861646b30eadea9c30d169d76127e9de4d37
parent865ec5b024b21e3fe3fa764068f44ca315a7af63 (diff)
downloadgcc-1c4b5a795ad772b0d80d18757593808044b14e90.zip
gcc-1c4b5a795ad772b0d80d18757593808044b14e90.tar.gz
gcc-1c4b5a795ad772b0d80d18757593808044b14e90.tar.bz2
[Ada] Simplify statically known Max_Size_In_Storage_Elements attribute in more cases
gcc/ada/ * sem_attr.adb (Eval_Attribute): Generalize static evaluation of Size attribute references to also handle Max_Size_In_Storage_Elements references.
-rw-r--r--gcc/ada/sem_attr.adb16
1 files changed, 13 insertions, 3 deletions
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 7a2f595..0d1f9c5 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -8127,14 +8127,24 @@ package body Sem_Attr is
-- for a size from an attribute definition clause). At this stage, this
-- can happen only for types (e.g. record types) for which the size is
-- always non-static. We exclude generic types from consideration (since
- -- they have bogus sizes set within templates).
+ -- they have bogus sizes set within templates). We can also fold
+ -- Max_Size_In_Storage_Elements in the same cases.
- elsif Id = Attribute_Size
+ elsif (Id = Attribute_Size or
+ Id = Attribute_Max_Size_In_Storage_Elements)
and then Is_Type (P_Entity)
and then (not Is_Generic_Type (P_Entity))
and then Known_Static_RM_Size (P_Entity)
then
- Compile_Time_Known_Attribute (N, RM_Size (P_Entity));
+ declare
+ Attr_Value : Uint := RM_Size (P_Entity);
+ begin
+ if Id = Attribute_Max_Size_In_Storage_Elements then
+ Attr_Value := (Attr_Value + System_Storage_Unit - 1)
+ / System_Storage_Unit;
+ end if;
+ Compile_Time_Known_Attribute (N, Attr_Value);
+ end;
return;
-- We can fold 'Alignment applied to a type if the alignment is known