summaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch8.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@gcc.gnu.org>2011-08-03 10:32:57 +0200
committerArnaud Charlet <charlet@gcc.gnu.org>2011-08-03 10:32:57 +0200
commit3f5a8feea3381fb0311e4d1a264c0661f37432dd (patch)
tree834b7da4b7d5b685e4e2c9e4b200ee9d3e306393 /gcc/ada/sem_ch8.adb
parenta96ca6001f1e6236b550e26c7459bfaa9deb57b0 (diff)
downloadgcc-3f5a8feea3381fb0311e4d1a264c0661f37432dd.tar.gz
[multiple changes]
2011-08-03 Olivier Hainque <hainque@adacore.com> * tracebak.c (STOP_FRAME ppc AIX): Stop at null return address as well. 2011-08-03 Ed Schonberg <schonberg@adacore.com> * sem_ch8.adb (Analyze_Object_Renaming): if the renamed object is an explicit dereference of an unconstrained type, create a constrained subtype for it, as is done for function calls that return an unconstrained type. 2011-08-03 Thomas Quinot <quinot@adacore.com> * g-pehage.adb (Finalize): Avoid possible double-free. 2011-08-03 Steve Baird <baird@adacore.com> * exp_attr.adb (Expand_N_Attribute_Reference): Don't expand Elab_Spec/Body attrs in CodePeer_Mode. 2011-08-03 Javier Miranda <miranda@adacore.com> * exp_aggr.adb (Flatten): Convert to positional form aggregates whose low bound is not known at compile time but they have no others choice. Done because in this case the bounds can be obtained directly from the aggregate. 2011-08-03 Ed Falis <falis@adacore.com> * s-tasinf-vxworks.ads: Update comment to reflect 0 indexing of CPUs on VxWorks SMP. Remove unusable constant ANY_CPU. From-SVN: r177242
Diffstat (limited to 'gcc/ada/sem_ch8.adb')
-rw-r--r--gcc/ada/sem_ch8.adb72
1 files changed, 48 insertions, 24 deletions
diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb
index 67a53e36399..fddb704c96f 100644
--- a/gcc/ada/sem_ch8.adb
+++ b/gcc/ada/sem_ch8.adb
@@ -688,9 +688,55 @@ package body Sem_Ch8 is
T : Entity_Id;
T2 : Entity_Id;
+ procedure Check_Constrained_Object;
+ -- If the nominal type is unconstrained but the renamed object is
+ -- constrained, as can happen with renaming an explicit dereference or
+ -- a function return, build a constrained subtype from the object. If
+ -- the renaming is for a formal in an accept statement, the analysis
+ -- has already established its actual subtype. This is only relevant
+ -- if the renamed object is an explicit dereference.
+
function In_Generic_Scope (E : Entity_Id) return Boolean;
-- Determine whether entity E is inside a generic cope
+ ------------------------------
+ -- Check_Constrained_Object --
+ ------------------------------
+
+ procedure Check_Constrained_Object is
+ Loc : constant Source_Ptr := Sloc (N);
+ Subt : Entity_Id;
+
+ begin
+ if (Nkind (Nam) = N_Function_Call
+ or else Nkind (Nam) = N_Explicit_Dereference)
+ and then Is_Composite_Type (Etype (Nam))
+ and then not Is_Constrained (Etype (Nam))
+ and then not Has_Unknown_Discriminants (Etype (Nam))
+ and then Expander_Active
+ then
+ -- If Actual_Sbutype is already set, nothing to do.
+
+ if (Ekind (Id) = E_Variable
+ or else Ekind (Id) = E_Constant)
+ and then Present (Actual_Subtype (Id))
+ then
+ null;
+
+ else
+ Subt := Make_Temporary (Loc, 'T');
+ Remove_Side_Effects (Nam);
+ Insert_Action (N,
+ Make_Subtype_Declaration (Loc,
+ Defining_Identifier => Subt,
+ Subtype_Indication =>
+ Make_Subtype_From_Expr (Nam, Etype (Nam))));
+ Rewrite (Subtype_Mark (N), New_Occurrence_Of (Subt, Loc));
+ Set_Etype (Nam, Subt);
+ end if;
+ end if;
+ end Check_Constrained_Object;
+
----------------------
-- In_Generic_Scope --
----------------------
@@ -910,33 +956,11 @@ package body Sem_Ch8 is
Nam);
end if;
- -- If the function call returns an unconstrained type, we must
- -- build a constrained subtype for the new entity, in a way
- -- similar to what is done for an object declaration with an
- -- unconstrained nominal type.
-
- if Is_Composite_Type (Etype (Nam))
- and then not Is_Constrained (Etype (Nam))
- and then not Has_Unknown_Discriminants (Etype (Nam))
- and then Expander_Active
- then
- declare
- Loc : constant Source_Ptr := Sloc (N);
- Subt : constant Entity_Id := Make_Temporary (Loc, 'T');
- begin
- Remove_Side_Effects (Nam);
- Insert_Action (N,
- Make_Subtype_Declaration (Loc,
- Defining_Identifier => Subt,
- Subtype_Indication =>
- Make_Subtype_From_Expr (Nam, Etype (Nam))));
- Rewrite (Subtype_Mark (N), New_Occurrence_Of (Subt, Loc));
- Set_Etype (Nam, Subt);
- end;
- end if;
end case;
end if;
+ Check_Constrained_Object;
+
-- An object renaming requires an exact match of the type. Class-wide
-- matching is not allowed.