Commit 6905a049 by Arnaud Charlet

[multiple changes]

2016-04-20  Bob Duff  <duff@adacore.com>

	* s-os_lib.ads: Minor comment fix.

2016-04-20  Ed Schonberg  <schonberg@adacore.com>

	* exp_ch5.adb (Expand_N_Assignment_Statement): Do no generate
	a discriminant check for a type whose partial view has unknown
	discriminants when the full view has discriminants with defaults.

2016-04-20  Javier Miranda  <miranda@adacore.com>

	* exp_util.adb (Remove_Side_Effects): When generating C code
	remove side effect of type conversion of access to unconstrained
	array type.
	(Side_Effect_Free): Return false for the type
	conversion of access to unconstrained array type when generating
	C code.
	* sem_res.adb (Resolved_Type_Conversion): Remove side effects
	of access to unconstrained array type conversion when generating
	C code.

2016-04-20  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch13.adb (Build_Predicate_Function_Declaration): New
	function, to construct the declaration of a predicate function
	at the end of the current declarative part rather than at the
	(possibly later) freeze point of the type. This also allows uses
	of a type with predicates in instantiations elsewhere.
	(Resolve_Aspect_Expression): New procedure to detect visiblity
	errors in aspect expressions, at the end of the declarative part
	that includes the type declaration.
	* sem_ch3.adb (Complete_Private_Subtype): Propagate properly the
	predicate function from private to full view.
	* einfo.adb (Predicate_Function): Refine search for predicate
	function when type has a full view and predicate function may
	be defined on either view.

2016-04-20  Javier Miranda  <miranda@adacore.com>

	* frontend.adb: Passing the root of the tree to
	Unnest_Subprograms().
	* exp_ch6.adb (Expand_N_Subprogram_Body): Remove code that
	took care of adding subprograms to the Unest_Bodies table since
	performing such action too early disables the ability to process
	generic instantiations.
	(Unnest_Subprograms): Adding parameter.
	(Search_Unnesting_Subprograms): New subprogram.
	* exp_ch6.ads (Unnest_Subrograms): Update documentation.

From-SVN: r235268
parent 268aeaa9
2016-04-20 Bob Duff <duff@adacore.com>
* s-os_lib.ads: Minor comment fix.
2016-04-20 Ed Schonberg <schonberg@adacore.com>
* exp_ch5.adb (Expand_N_Assignment_Statement): Do no generate
a discriminant check for a type whose partial view has unknown
discriminants when the full view has discriminants with defaults.
2016-04-20 Javier Miranda <miranda@adacore.com>
* exp_util.adb (Remove_Side_Effects): When generating C code
remove side effect of type conversion of access to unconstrained
array type.
(Side_Effect_Free): Return false for the type
conversion of access to unconstrained array type when generating
C code.
* sem_res.adb (Resolved_Type_Conversion): Remove side effects
of access to unconstrained array type conversion when generating
C code.
2016-04-20 Ed Schonberg <schonberg@adacore.com>
* sem_ch13.adb (Build_Predicate_Function_Declaration): New
function, to construct the declaration of a predicate function
at the end of the current declarative part rather than at the
(possibly later) freeze point of the type. This also allows uses
of a type with predicates in instantiations elsewhere.
(Resolve_Aspect_Expression): New procedure to detect visiblity
errors in aspect expressions, at the end of the declarative part
that includes the type declaration.
* sem_ch3.adb (Complete_Private_Subtype): Propagate properly the
predicate function from private to full view.
* einfo.adb (Predicate_Function): Refine search for predicate
function when type has a full view and predicate function may
be defined on either view.
2016-04-20 Javier Miranda <miranda@adacore.com>
* frontend.adb: Passing the root of the tree to
Unnest_Subprograms().
* exp_ch6.adb (Expand_N_Subprogram_Body): Remove code that
took care of adding subprograms to the Unest_Bodies table since
performing such action too early disables the ability to process
generic instantiations.
(Unnest_Subprograms): Adding parameter.
(Search_Unnesting_Subprograms): New subprogram.
* exp_ch6.ads (Unnest_Subrograms): Update documentation.
2016-04-20 Hristian Kirtchev <kirtchev@adacore.com> 2016-04-20 Hristian Kirtchev <kirtchev@adacore.com>
* exp_util.adb, freeze.adb, sem_util.adb: Minor reformatting. * exp_util.adb, freeze.adb, sem_util.adb: Minor reformatting.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -8213,8 +8213,13 @@ package body Einfo is ...@@ -8213,8 +8213,13 @@ package body Einfo is
-- If type is private and has a completion, predicate may be defined -- If type is private and has a completion, predicate may be defined
-- on the full view. -- on the full view.
if Is_Private_Type (Id) and then Present (Full_View (Id)) then if Is_Private_Type (Id)
and then
(not Has_Predicates (Id) or else No (Subprograms_For_Type (Id)))
and then Present (Full_View (Id))
then
T := Full_View (Id); T := Full_View (Id);
else else
T := Id; T := Id;
end if; end if;
......
...@@ -1946,10 +1946,12 @@ package body Exp_Ch5 is ...@@ -1946,10 +1946,12 @@ package body Exp_Ch5 is
-- have a full view with discriminants, but those are nameable only -- have a full view with discriminants, but those are nameable only
-- in the underlying type, so convert the Rhs to it before potential -- in the underlying type, so convert the Rhs to it before potential
-- checking. Convert Lhs as well, otherwise the actual subtype might -- checking. Convert Lhs as well, otherwise the actual subtype might
-- not be constructible. -- not be constructible. If the discriminants have defaults the type
-- is unconstrained and there is nothing to check.
elsif Has_Unknown_Discriminants (Base_Type (Etype (Lhs))) elsif Has_Unknown_Discriminants (Base_Type (Etype (Lhs)))
and then Has_Discriminants (Typ) and then Has_Discriminants (Typ)
and then not Has_Defaulted_Discriminants (Typ)
then then
Rewrite (Rhs, OK_Convert_To (Base_Type (Typ), Rhs)); Rewrite (Rhs, OK_Convert_To (Base_Type (Typ), Rhs));
Rewrite (Lhs, OK_Convert_To (Base_Type (Typ), Lhs)); Rewrite (Lhs, OK_Convert_To (Base_Type (Typ), Lhs));
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -5491,28 +5491,6 @@ package body Exp_Ch6 is ...@@ -5491,28 +5491,6 @@ package body Exp_Ch6 is
Qualify_Entity_Names (N); Qualify_Entity_Names (N);
-- If we are unnesting procedures, and this is an outer level procedure
-- with nested subprograms, do the unnesting operation now.
if Opt.Unnest_Subprogram_Mode
-- We are only interested in subprograms (not generic subprograms)
and then Is_Subprogram (Spec_Id)
-- Only deal with outer level subprograms. Nested subprograms are
-- handled as part of dealing with the outer level subprogram in
-- which they are nested.
and then Enclosing_Subprogram (Spec_Id) = Empty
-- We are only interested in subprograms that have nested subprograms
and then Has_Nested_Subprogram (Spec_Id)
then
Unest_Bodies.Append ((Spec_Id, N));
end if;
Ghost_Mode := Save_Ghost_Mode; Ghost_Mode := Save_Ghost_Mode;
end Expand_N_Subprogram_Body; end Expand_N_Subprogram_Body;
...@@ -8497,8 +8475,74 @@ package body Exp_Ch6 is ...@@ -8497,8 +8475,74 @@ package body Exp_Ch6 is
-- Unnest_Subprograms -- -- Unnest_Subprograms --
------------------------ ------------------------
procedure Unnest_Subprograms is procedure Unnest_Subprograms (N : Node_Id) is
procedure Search_Unnesting_Subprograms (N : Node_Id);
-- Search for outer level procedures with nested subprograms and append
-- them to the Unnest table.
----------------------------------
-- Search_Unnesting_Subprograms --
----------------------------------
procedure Search_Unnesting_Subprograms (N : Node_Id) is
function Search_Subprograms (N : Node_Id) return Traverse_Result;
-- Tree visitor that search for outer level procedures with nested
-- subprograms and adds them to the Unnest table.
------------------------
-- Search_Subprograms --
------------------------
function Search_Subprograms (N : Node_Id) return Traverse_Result is
begin
if Nkind_In (N, N_Subprogram_Body,
N_Subprogram_Body_Stub)
then
declare
Spec_Id : constant Entity_Id := Unique_Defining_Entity (N);
begin
-- We are only interested in subprograms (not generic
-- subprograms), that have nested subprograms.
if Is_Subprogram (Spec_Id)
and then Has_Nested_Subprogram (Spec_Id)
and then Is_Library_Level_Entity (Spec_Id)
then
Unest_Bodies.Append ((Spec_Id, N));
end if;
end;
end if;
return OK;
end Search_Subprograms;
---------------
-- Do_Search --
---------------
procedure Do_Search is new Traverse_Proc (Search_Subprograms);
-- Subtree visitor instantiation
-- Start of processing for Search_Unnesting_Subprograms
begin
if Opt.Unnest_Subprogram_Mode then
Do_Search (N);
end if;
end Search_Unnesting_Subprograms;
-- Start of processing for Unnest_Subprograms
begin begin
if not Opt.Unnest_Subprogram_Mode then
return;
end if;
Search_Unnesting_Subprograms (N);
for J in Unest_Bodies.First .. Unest_Bodies.Last loop for J in Unest_Bodies.First .. Unest_Bodies.Last loop
declare declare
UBJ : Unest_Entry renames Unest_Bodies.Table (J); UBJ : Unest_Entry renames Unest_Bodies.Table (J);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -212,9 +212,9 @@ package Exp_Ch6 is ...@@ -212,9 +212,9 @@ package Exp_Ch6 is
-- parameter to identify the accessibility level of the function result -- parameter to identify the accessibility level of the function result
-- "determined by the point of call". -- "determined by the point of call".
procedure Unnest_Subprograms; procedure Unnest_Subprograms (N : Node_Id);
-- Called to unnest subprograms. If we are in unnest subprogram mode, and -- Called to unnest subprograms. If we are in unnest subprogram mode, this
-- subprograms have been gathered in the Unest_Bodies table, this is the -- is the call that traverses the tree N and locates all the library level
-- call that causes them to be processed for unnesting. -- subprograms with nested subprograms to process them.
end Exp_Ch6; end Exp_Ch6;
...@@ -7800,7 +7800,30 @@ package body Exp_Util is ...@@ -7800,7 +7800,30 @@ package body Exp_Util is
elsif Nkind (Exp) = N_Type_Conversion then elsif Nkind (Exp) = N_Type_Conversion then
Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref); Remove_Side_Effects (Expression (Exp), Name_Req, Variable_Ref);
goto Leave;
-- Generating C code the type conversion of an access to constrained
-- array type into an access to unconstrained array type involves
-- initializing a fat pointer and the expression must be free of
-- side effects to safely compute its bounds.
if Generate_C_Code
and then Is_Access_Type (Etype (Exp))
and then Is_Array_Type (Designated_Type (Etype (Exp)))
and then not Is_Constrained (Designated_Type (Etype (Exp)))
then
Def_Id := Build_Temporary (Loc, 'R', Exp);
Set_Etype (Def_Id, Exp_Type);
Res := New_Occurrence_Of (Def_Id, Loc);
Insert_Action (Exp,
Make_Object_Declaration (Loc,
Defining_Identifier => Def_Id,
Object_Definition => New_Occurrence_Of (Exp_Type, Loc),
Constant_Present => True,
Expression => Relocate_Node (Exp)));
else
goto Leave;
end if;
-- If this is an unchecked conversion that Gigi can't handle, make -- If this is an unchecked conversion that Gigi can't handle, make
-- a copy or a use a renaming to capture the value. -- a copy or a use a renaming to capture the value.
...@@ -9076,6 +9099,19 @@ package body Exp_Util is ...@@ -9076,6 +9099,19 @@ package body Exp_Util is
and then Is_Class_Wide_Type (Typ) and then Is_Class_Wide_Type (Typ)
then then
return True; return True;
-- Generating C the type conversion of an access to constrained array
-- type into an access to unconstrained array type involves initializing
-- a fat pointer and the expression cannot be assumed to be free of side
-- effects since it must referenced several times to compute its bounds.
elsif Generate_C_Code
and then Nkind (N) = N_Type_Conversion
and then Is_Access_Type (Typ)
and then Is_Array_Type (Designated_Type (Typ))
and then not Is_Constrained (Designated_Type (Typ))
then
return False;
end if; end if;
-- For other than entity names and compile time known values, -- For other than entity names and compile time known values,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -440,7 +440,7 @@ begin ...@@ -440,7 +440,7 @@ begin
-- At this stage we can unnest subprogram bodies if required -- At this stage we can unnest subprogram bodies if required
Exp_Ch6.Unnest_Subprograms; Exp_Ch6.Unnest_Subprograms (Cunit (Main_Unit));
-- List library units if requested -- List library units if requested
......
...@@ -454,7 +454,7 @@ package System.OS_Lib is ...@@ -454,7 +454,7 @@ package System.OS_Lib is
-- that is writable. Returns True if so, False otherwise. Note that this -- that is writable. Returns True if so, False otherwise. Note that this
-- function simply interrogates the file attributes (e.g. using the C -- function simply interrogates the file attributes (e.g. using the C
-- function stat), so it does not indicate a situation in which a file may -- function stat), so it does not indicate a situation in which a file may
-- not actually be writeable due to some other process having exclusive -- not actually be writable due to some other process having exclusive
-- access. -- access.
function Locate_Exec_On_Path (Exec_Name : String) return String_Access; function Locate_Exec_On_Path (Exec_Name : String) return String_Access;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2016, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -11820,8 +11820,17 @@ package body Sem_Ch3 is ...@@ -11820,8 +11820,17 @@ package body Sem_Ch3 is
-- in particular when the full type is a scalar type for which an -- in particular when the full type is a scalar type for which an
-- anonymous base type is constructed. -- anonymous base type is constructed.
-- The predicate functions are generated either at the freeze point
-- of the type or at the end of the visible part, and we must avoid
-- generating them twice.
if Has_Predicates (Priv) then if Has_Predicates (Priv) then
Set_Has_Predicates (Full); Set_Has_Predicates (Full);
if Present (Predicate_Function (Priv))
and then No (Predicate_Function (Full))
then
Set_Predicate_Function (Full, Predicate_Function (Priv));
end if;
end if; end if;
if Has_Delayed_Aspects (Priv) then if Has_Delayed_Aspects (Priv) then
......
...@@ -10847,6 +10847,23 @@ package body Sem_Res is ...@@ -10847,6 +10847,23 @@ package body Sem_Res is
then then
Set_Do_Range_Check (Operand); Set_Do_Range_Check (Operand);
end if; end if;
-- Generating C code a type conversion of an access to constrained
-- array type to access to unconstrained array type involves building
-- a fat pointer which in general cannot be generated on the fly. We
-- remove side effects in order to store the result of the conversion
-- into a temporary.
if Generate_C_Code
and then Nkind (N) = N_Type_Conversion
and then Nkind (Parent (N)) /= N_Object_Declaration
and then Is_Access_Type (Etype (N))
and then Is_Array_Type (Designated_Type (Etype (N)))
and then not Is_Constrained (Designated_Type (Etype (N)))
and then Is_Constrained (Designated_Type (Etype (Expression (N))))
then
Remove_Side_Effects (N);
end if;
end Resolve_Type_Conversion; end Resolve_Type_Conversion;
---------------------- ----------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment