aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2008-05-23 16:33:37 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2008-05-23 16:33:37 +0200
commitbfc157d52c26ce692eaf52c4cdbbf4b148198c9e (patch)
tree9f49fc8449cbf1726d098404a04575ba9feb7ae9
parent651a2cb04b6c24cc07179449faa0b46e9f75dac6 (diff)
downloadgcc-bfc157d52c26ce692eaf52c4cdbbf4b148198c9e.zip
gcc-bfc157d52c26ce692eaf52c4cdbbf4b148198c9e.tar.gz
gcc-bfc157d52c26ce692eaf52c4cdbbf4b148198c9e.tar.bz2
sem_attr.adb (Resolve_Attribute, [...]): If the prefix is a slice...
2008-05-23 Ed Schonberg <schonberg@adacore.com> * 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
-rw-r--r--gcc/ada/sem_attr.adb30
1 files changed, 30 insertions, 0 deletions
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;
---------------