From 955379e4ed77883365cd041840bb17245810c095 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 12 Dec 2019 10:02:55 +0000 Subject: [PATCH] [Ada] Fix wrong value of 'Size for slices of bit-packed arrays (2) 2019-12-12 Eric Botcazou gcc/ada/ * exp_attr.adb (Expand_Size_Attribute): Look directly at the prefix to detect the bit-packed slices. Apply the checks last in case the attribute needs to be processed by the back-end. * exp_ch4.adb (Expand_N_Slice): Do not create a temporary for a prefix of the Size attribute. From-SVN: r279293 --- gcc/ada/ChangeLog | 8 ++++++++ gcc/ada/exp_attr.adb | 9 ++++----- gcc/ada/exp_ch4.adb | 6 ++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index c2e4c36ab89..cf79c7d2a62 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2019-12-12 Eric Botcazou + + * exp_attr.adb (Expand_Size_Attribute): Look directly at the + prefix to detect the bit-packed slices. Apply the checks last + in case the attribute needs to be processed by the back-end. + * exp_ch4.adb (Expand_N_Slice): Do not create a temporary for + a prefix of the Size attribute. + 2019-12-12 Steve Baird * sem_ch12.adb diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index 1459cfcd04f..c7b6451430e 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -7455,8 +7455,6 @@ package body Exp_Attr is -- All other cases are handled by the back end else - Apply_Universal_Integer_Attribute_Checks (N); - -- If Size is applied to a formal parameter that is of a packed -- array subtype, then apply Size to the actual subtype. @@ -7489,9 +7487,7 @@ package body Exp_Attr is -- System.Unsigned_Types.Packed_Byte for code generation purposes so -- the size is always rounded up in the back end. - elsif Nkind (Original_Node (Pref)) = N_Slice - and then Is_Bit_Packed_Array (Ptyp) - then + elsif Nkind (Pref) = N_Slice and then Is_Bit_Packed_Array (Ptyp) then Rewrite (N, Make_Op_Multiply (Loc, Make_Attribute_Reference (Loc, @@ -7503,6 +7499,9 @@ package body Exp_Attr is Analyze_And_Resolve (N, Typ); end if; + -- Apply the required checks last, after rewriting has taken place + + Apply_Universal_Integer_Attribute_Checks (N); return; end if; diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 158dcb59cc5..20b3babdc30 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -11013,7 +11013,8 @@ package body Exp_Ch4 is -- 5. Prefix of an address attribute (this is an error which is caught -- elsewhere, and the expansion would interfere with generating the - -- error message). + -- error message) or of a size attribute (because 'Size may change + -- when applied to the temporary instead of the slice directly). if not Is_Packed (Typ) then @@ -11039,7 +11040,8 @@ package body Exp_Ch4 is return; elsif Nkind (Parent (N)) = N_Attribute_Reference - and then Attribute_Name (Parent (N)) = Name_Address + and then (Attribute_Name (Parent (N)) = Name_Address + or else Attribute_Name (Parent (N)) = Name_Size) then return; -- 2.30.2