From bfc157d52c26ce692eaf52c4cdbbf4b148198c9e Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Fri, 23 May 2008 16:33:37 +0200 Subject: [PATCH] sem_attr.adb (Resolve_Attribute, [...]): If the prefix is a slice... 2008-05-23 Ed Schonberg * sem_attr.adb (Resolve_Attribute, case 'address): If the prefix is a slice, convert it to an indexed component, which is equivalent, more efficient, and usable even if the slice itself is not addressable. From-SVN: r135811 --- gcc/ada/sem_attr.adb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index c2536df..0735740 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -8083,6 +8083,36 @@ package body Sem_Attr is if Is_Entity_Name (P) then Set_Address_Taken (Entity (P)); end if; + + if Nkind (P) = N_Slice then + + -- Arr (X .. Y)'address is identical to Arr (X)'address, + -- even if the array is packed and the slice itself is not + -- addressable. Transform the prefix into an indexed component. + + declare + Loc : constant Source_Ptr := Sloc (P); + D : constant Node_Id := Discrete_Range (P); + Lo : Node_Id; + + begin + if Is_Entity_Name (D) then + Lo := + Make_Attribute_Reference (Loc, + Prefix => (New_Occurrence_Of (Entity (D), Loc)), + Attribute_Name => Name_First); + else + Lo := Low_Bound (D); + end if; + + Rewrite (P, + Make_Indexed_Component (Loc, + Prefix => Relocate_Node (Prefix (P)), + Expressions => New_List (Lo))); + + Analyze_And_Resolve (P); + end; + end if; end Address_Attribute; --------------- -- 2.7.4