summaryrefslogtreecommitdiffstats
path: root/gcc/ada
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2008-05-26 15:14:52 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2008-05-26 15:14:52 +0000
commit6dfb88d8a9c82289878fc79da01dffda8cba4f8d (patch)
tree50fcecd54449d5ec4818edec2cc77b3636dbb19f /gcc/ada
parent4f9eef1d66a81fce428183c95a1116b2c98bf44e (diff)
downloadppe42-gcc-6dfb88d8a9c82289878fc79da01dffda8cba4f8d.tar.gz
ppe42-gcc-6dfb88d8a9c82289878fc79da01dffda8cba4f8d.zip
2008-05-26 Ed Schonberg <schonberg@adacore.com>
* sem_attr.adb: (Resolve_Attribute, case 'address): S (A .. B)' address can be safely converted to S (A)'address only if A .. B is known to be a non-null range. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135936 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/sem_attr.adb27
1 files changed, 20 insertions, 7 deletions
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 0735740472f..79a6f020feb 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -8089,6 +8089,8 @@ package body Sem_Attr is
-- 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.
+ -- Note that the transformation is safe only if we know that
+ -- the slice is non-null.
declare
Loc : constant Source_Ptr := Sloc (P);
@@ -8096,21 +8098,32 @@ package body Sem_Attr is
Lo : Node_Id;
begin
- if Is_Entity_Name (D) then
+ if Is_Entity_Name (D)
+ and then
+ Not_Null_Range
+ (Type_Low_Bound (Entity (D)),
+ Type_High_Bound (Entity (D)))
+ then
Lo :=
Make_Attribute_Reference (Loc,
Prefix => (New_Occurrence_Of (Entity (D), Loc)),
Attribute_Name => Name_First);
- else
+
+ elsif Not_Null_Range (Low_Bound (D), High_Bound (D)) then
Lo := Low_Bound (D);
+
+ else
+ Lo := Empty;
end if;
- Rewrite (P,
- Make_Indexed_Component (Loc,
- Prefix => Relocate_Node (Prefix (P)),
- Expressions => New_List (Lo)));
+ if Present (Lo) then
+ Rewrite (P,
+ Make_Indexed_Component (Loc,
+ Prefix => Relocate_Node (Prefix (P)),
+ Expressions => New_List (Lo)));
- Analyze_And_Resolve (P);
+ Analyze_And_Resolve (P);
+ end if;
end;
end if;
end Address_Attribute;
OpenPOWER on IntegriCloud