From: Ed Schonberg Date: Fri, 23 May 2008 14:33:37 +0000 (+0200) Subject: sem_attr.adb (Resolve_Attribute, [...]): If the prefix is a slice... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bfc157d52c26ce692eaf52c4cdbbf4b148198c9e;p=gcc.git 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 --- diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index c2536dfc70c..0735740472f 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; ---------------