summaryrefslogtreecommitdiff
path: root/gcc/ada/layout.adb
diff options
context:
space:
mode:
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-24 16:08:50 +0000
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2011-03-24 16:08:50 +0000
commit4524d1ceff28dd267d78bdd3e18bffd5d88db30a (patch)
treeb9005d8dcb786199a152d4e3d91717ba40010452 /gcc/ada/layout.adb
parent5f515621d4459b5d84f5640e0993611cbd008f3c (diff)
downloadgcc-4524d1ceff28dd267d78bdd3e18bffd5d88db30a.tar.gz
* einfo.ads (Size_Depends_On_Discriminant): Adjust description.
* layout.adb (Compute_Size_Depends_On_Discriminant): New procedure to compute Set_Size_Depends_On_Discriminant. (Layout_Type): Call it on array types in back-end layout mode. * sem_util.adb (Requires_Transient_Scope): Return true for array types only if the size depends on the value of discriminants. * gcc-interface/utils2.c (build_binary_op) <MODIFY_EXPR>: Use the RHS type if the RHS is a call to a function that returns an unconstrained type with default discriminant. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@171402 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/layout.adb')
-rw-r--r--gcc/ada/layout.adb60
1 files changed, 59 insertions, 1 deletions
diff --git a/gcc/ada/layout.adb b/gcc/ada/layout.adb
index 0c4db36b46f..7ae89b53f27 100644
--- a/gcc/ada/layout.adb
+++ b/gcc/ada/layout.adb
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 2001-2010, Free Software Foundation, Inc. --
+-- Copyright (C) 2001-2011, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -109,6 +109,12 @@ package body Layout is
-- are of an enumeration type (so that the subtraction cannot be
-- done directly) by applying the Pos operator to Hi/Lo first.
+ procedure Compute_Size_Depends_On_Discriminant (E : Entity_Id);
+ -- Given an array type or an array subtype E, compute whether its size
+ -- depends on the value of one or more discriminants and set the flag
+ -- Size_Depends_On_Discriminant accordingly. This need not be called
+ -- in front end layout mode since it does the computation on its own.
+
function Expr_From_SO_Ref
(Loc : Source_Ptr;
D : SO_Ref;
@@ -1289,6 +1295,49 @@ package body Layout is
end if;
end Layout_Array_Type;
+ ------------------------------------------
+ -- Compute_Size_Depends_On_Discriminant --
+ ------------------------------------------
+
+ procedure Compute_Size_Depends_On_Discriminant (E : Entity_Id) is
+ Indx : Node_Id;
+ Ityp : Entity_Id;
+ Lo : Node_Id;
+ Hi : Node_Id;
+ Res : Boolean := False;
+ begin
+ -- Loop to process array indexes
+
+ Indx := First_Index (E);
+ while Present (Indx) loop
+ Ityp := Etype (Indx);
+
+ -- If an index of the array is a generic formal type then there is
+ -- no point in determining a size for the array type.
+
+ if Is_Generic_Type (Ityp) then
+ return;
+ end if;
+
+ Lo := Type_Low_Bound (Ityp);
+ Hi := Type_High_Bound (Ityp);
+
+ if (Nkind (Lo) = N_Identifier
+ and then Ekind (Entity (Lo)) = E_Discriminant)
+ or else (Nkind (Hi) = N_Identifier
+ and then Ekind (Entity (Hi)) = E_Discriminant)
+ then
+ Res := True;
+ end if;
+
+ Next_Index (Indx);
+ end loop;
+
+ if Res then
+ Set_Size_Depends_On_Discriminant (E);
+ end if;
+ end Compute_Size_Depends_On_Discriminant;
+
-------------------
-- Layout_Object --
-------------------
@@ -2631,6 +2680,15 @@ package body Layout is
Set_Alignment (E, Uint_1);
end if;
end if;
+
+ -- We need to know whether the size depends on the value of one
+ -- or more discriminants to select the return mechanism. Skip if
+ -- errors are present, to prevent cascaded messages.
+
+ if Serious_Errors_Detected = 0 then
+ Compute_Size_Depends_On_Discriminant (E);
+ end if;
+
end if;
end if;