Commit 84f4072a by Javier Miranda Committed by Arnaud Charlet

sem_ch3.adb (Analyze_Object_Declaration): If the object declaration has an init…

sem_ch3.adb (Analyze_Object_Declaration): If the object declaration has an init expression then stop the analysis of the...

2012-03-07  Javier Miranda  <miranda@adacore.com>

	* sem_ch3.adb (Analyze_Object_Declaration): If the object
	declaration has an init expression then stop the analysis of the
	object declaration if the expression which initializes the object
	is a call to an inlined function which returns an unconstrained
	and has been expanded into a procedure call.
	* sem_ch5.adb (Has_Call_Using_Secondary_Stack): Add missing
	support to handle selected components.
	* sem_ch6.ads (Cannot_Inline): Adding parameter Is_Serious plus
	documentation.
	* sem_ch6.adb (Check_And_Build_Body_To_Inline): New
	subprogram which implements the checks required by the
	new rules for frontend inlining and builds the body to inline.
	(Analyze_Subprogram_Body_Helper): Move code that
	checks inlining of subprogram that has nested subprogram
	to Check_And_Build_Body_To_Inline.  Replace call to
	Build_Body_To_Inline by call to the new subprogram
	Check_And_Build_Body_To_Inline.
	(Cannot_Inline): New implementation.
	* sem_ch12.adb (Analyze_Package_Instantiation.Must_Inline_Subp):
	New subprogram.
	* sem_util.ad[sb] (Must_Inline): New subprogram.
	(Returns_Unconstrained_Type): New subprogram.
	* sem_res.adb (Resolve_Call): Do not create a transient scope
	for inlined calls.
	* inline.ads (Analyzing_Inlined_Bodies): Remove unreferenced variable.
	* inline.adb (Analyze_Inlined_Bodies, Initialize): Remove setting
	to false the variable Analyzing_Inlined_Bodies.  Fix comments.
	* exp_ch4.adb (Expand_N_Allocator): Fix handling of finalization master.
	* exp_ch6.ads (List_Inlining_Info): New subprogram.
	* exp_ch6.adb (Expand_Call.Do_Inline): New subprogram.
	(Expand_Call.Do_Inline_Always): New subprogram.
	(In_Unfrozen_Instance): Move the declaration of this subprogram.
	(Expand_Inlined_Call.Reset_Dispatching_Calls): New subprogram.
	(Expand_Inlined_Call): Adding new support for inlining functions
	that return unconstrained types.
	(List_Inlining_Info): New subprogram.
	* debug.adb Document flags -gnatd.j and -gnatd.k
	* gnat1drv.adb Add call to generate the new listing of inlined
	calls and calls passed to the backend.

From-SVN: r185055
parent 844ec038
2012-03-07 Javier Miranda <miranda@adacore.com>
* sem_ch3.adb (Analyze_Object_Declaration): If the object
declaration has an init expression then stop the analysis of the
object declaration if the expression which initializes the object
is a call to an inlined function which returns an unconstrained
and has been expanded into a procedure call.
* sem_ch5.adb (Has_Call_Using_Secondary_Stack): Add missing
support to handle selected components.
* sem_ch6.ads (Cannot_Inline): Adding parameter Is_Serious plus
documentation.
* sem_ch6.adb (Check_And_Build_Body_To_Inline): New
subprogram which implements the checks required by the
new rules for frontend inlining and builds the body to inline.
(Analyze_Subprogram_Body_Helper): Move code that
checks inlining of subprogram that has nested subprogram
to Check_And_Build_Body_To_Inline. Replace call to
Build_Body_To_Inline by call to the new subprogram
Check_And_Build_Body_To_Inline.
(Cannot_Inline): New implementation.
* sem_ch12.adb (Analyze_Package_Instantiation.Must_Inline_Subp):
New subprogram.
* sem_util.ad[sb] (Must_Inline): New subprogram.
(Returns_Unconstrained_Type): New subprogram.
* sem_res.adb (Resolve_Call): Do not create a transient scope
for inlined calls.
* inline.ads (Analyzing_Inlined_Bodies): Remove unreferenced variable.
* inline.adb (Analyze_Inlined_Bodies, Initialize): Remove setting
to false the variable Analyzing_Inlined_Bodies. Fix comments.
* exp_ch4.adb (Expand_N_Allocator): Fix handling of finalization master.
* exp_ch6.ads (List_Inlining_Info): New subprogram.
* exp_ch6.adb (Expand_Call.Do_Inline): New subprogram.
(Expand_Call.Do_Inline_Always): New subprogram.
(In_Unfrozen_Instance): Move the declaration of this subprogram.
(Expand_Inlined_Call.Reset_Dispatching_Calls): New subprogram.
(Expand_Inlined_Call): Adding new support for inlining functions
that return unconstrained types.
(List_Inlining_Info): New subprogram.
* debug.adb Document flags -gnatd.j and -gnatd.k
* gnat1drv.adb Add call to generate the new listing of inlined
calls and calls passed to the backend.
2012-03-07 Robert Dewar <dewar@adacore.com>
* sem_ch5.adb, s-vaflop.adb, s-taprop-vms.adb, exp_ch6.adb,
......
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2012, 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- --
......@@ -100,8 +100,8 @@ package body Debug is
-- d.g Enable conversion of raise into goto
-- d.h
-- d.i Ignore Warnings pragmas
-- d.j
-- d.k
-- d.j Generate listing of frontend inlined calls
-- d.k Enable new support for frontend inlining
-- d.l Use Ada 95 semantics for limited function returns
-- d.m For -gnatl, print full source only for main unit
-- d.n Print source file names
......@@ -533,6 +533,13 @@ package body Debug is
-- be used in particular to disable Warnings (Off) to check if any of
-- these statements are inappropriate.
-- d.j Generate listing of frontend inlined calls and inline calls passed
-- to the backend. This is useful to locate skipped calls that must be
-- inlined by the frontend.
-- d.k Enable new semantics of frontend inlining. This is useful to test
-- this new feature in all the platforms.
-- d.l Use Ada 95 semantics for limited function returns. This may be
-- used to work around the incompatibility introduced by AI-318-2.
-- It is useful only in -gnat05 mode.
......
......@@ -3525,10 +3525,12 @@ package body Exp_Ch4 is
-- Processing for anonymous access-to-controlled types. These access
-- types receive a special finalization master which appears in the
-- declarations of the enclosing semantic unit. This expansion is done
-- now to ensure that any additional types generated by this routine
-- or Expand_Allocator_Expression inherit the proper type attributes.
-- now to ensure that any additional types generated by this routine or
-- Expand_Allocator_Expression inherit the proper type attributes.
if Ekind (PtrT) = E_Anonymous_Access_Type
if (Ekind (PtrT) = E_Anonymous_Access_Type
or else
(Is_Itype (PtrT) and then No (Finalization_Master (PtrT))))
and then Needs_Finalization (Dtyp)
then
-- Anonymous access-to-controlled types allocate on the global pool.
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2012, 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- --
......@@ -157,6 +157,10 @@ package Exp_Ch6 is
-- Predicate to recognize stubbed procedures and null procedures, which
-- can be inlined unconditionally in all cases.
procedure List_Inlining_Info;
-- Generate listing of calls inlined by the frontend plus listing of
-- calls to inline subprograms passed to the backend.
procedure Make_Build_In_Place_Call_In_Allocator
(Allocator : Node_Id;
Function_Call : Node_Id);
......
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2012, 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- --
......@@ -31,6 +31,7 @@ with Debug; use Debug;
with Elists;
with Errout; use Errout;
with Exp_CG;
with Exp_Ch6; use Exp_Ch6;
with Fmap;
with Fname; use Fname;
with Fname.UF; use Fname.UF;
......@@ -1160,6 +1161,7 @@ begin
Errout.Finalize (Last_Call => True);
Errout.Output_Messages;
List_Rep_Info;
List_Inlining_Info;
-- Only write the library if the backend did not generate any error
-- messages. Otherwise signal errors to the driver program so that
......
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2012, 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- --
......@@ -642,11 +642,9 @@ package body Inline is
end if;
end Is_Ancestor_Of_Main;
-- Start of processing for Analyze_Inlined_Bodies
-- Start of processing for Analyze_Inlined_Bodies
begin
Analyzing_Inlined_Bodies := False;
if Serious_Errors_Detected = 0 then
Push_Scope (Standard_Standard);
......@@ -669,8 +667,8 @@ package body Inline is
Comp_Unit := Parent (Comp_Unit);
end loop;
-- Load the body, unless it the main unit, or is an instance whose
-- body has already been analyzed.
-- Load the body, unless it is the main unit, or is an instance
-- whose body has already been analyzed.
if Present (Comp_Unit)
and then Comp_Unit /= Cunit (Main_Unit)
......@@ -1035,7 +1033,6 @@ package body Inline is
procedure Initialize is
begin
Analyzing_Inlined_Bodies := False;
Pending_Descriptor.Init;
Pending_Instantiations.Init;
Inlined_Bodies.Init;
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2012, 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- --
......@@ -110,11 +110,6 @@ package Inline is
Table_Increment => Alloc.Pending_Instantiations_Increment,
Table_Name => "Pending_Descriptor");
Analyzing_Inlined_Bodies : Boolean;
-- This flag is set False by the call to Initialize, and then is set
-- True by the call to Analyze_Inlined_Bodies. It is used to suppress
-- generation of subprogram descriptors for inlined bodies.
-----------------
-- Subprograms --
-----------------
......
......@@ -25,6 +25,7 @@
with Aspects; use Aspects;
with Atree; use Atree;
with Debug; use Debug;
with Einfo; use Einfo;
with Elists; use Elists;
with Errout; use Errout;
......@@ -3294,6 +3295,11 @@ package body Sem_Ch12 is
-- but it is simpler than detecting the need for the body at the point
-- of inlining, when the context of the instance is not available.
function Must_Inline_Subp return Boolean;
-- If inlining is active and the generic contains inlined subprograms,
-- return True if some of the inlined subprograms must be inlined by
-- the frontend.
-----------------------
-- Delay_Descriptors --
-----------------------
......@@ -3333,6 +3339,34 @@ package body Sem_Ch12 is
return False;
end Might_Inline_Subp;
----------------------
-- Must_Inline_Subp --
----------------------
function Must_Inline_Subp return Boolean is
E : Entity_Id;
begin
if not Inline_Processing_Required then
return False;
else
E := First_Entity (Gen_Unit);
while Present (E) loop
if Is_Subprogram (E)
and then Is_Inlined (E)
and then Must_Inline (E)
then
return True;
end if;
Next_Entity (E);
end loop;
end if;
return False;
end Must_Inline_Subp;
-- Local declarations
Vis_Prims_List : Elist_Id := No_Elist;
......@@ -3613,7 +3647,16 @@ package body Sem_Ch12 is
and then Might_Inline_Subp
and then not Is_Actual_Pack
then
if Front_End_Inlining
if not Debug_Flag_Dot_K
and then Front_End_Inlining
and then (Is_In_Main_Unit (N)
or else In_Main_Context (Current_Scope))
and then Nkind (Parent (N)) /= N_Compilation_Unit
then
Inline_Now := True;
elsif Debug_Flag_Dot_K
and then Must_Inline_Subp
and then (Is_In_Main_Unit (N)
or else In_Main_Context (Current_Scope))
and then Nkind (Parent (N)) /= N_Compilation_Unit
......
......@@ -3163,6 +3163,24 @@ package body Sem_Ch3 is
Set_Etype (Id, T);
Resolve (E, T);
-- No further action needed if E is a call to an inlined function
-- which returns an unconstrained type and it has been expanded into
-- a procedure call. In that case N has been replaced by an object
-- declaration without initializing expression and it has been
-- analyzed (see Expand_Inlined_Call).
if Debug_Flag_Dot_K
and then Expander_Active
and then Nkind (E) = N_Function_Call
and then Nkind (Name (E)) in N_Has_Entity
and then Is_Inlined (Entity (Name (E)))
and then not Is_Constrained (Etype (E))
and then Analyzed (N)
and then No (Expression (N))
then
return;
end if;
-- If E is null and has been replaced by an N_Raise_Constraint_Error
-- node (which was marked already-analyzed), we need to set the type
-- to something other than Any_Access in order to keep gigi happy.
......
......@@ -1852,7 +1852,13 @@ package body Sem_Ch5 is
if Nkind (Nam) = N_Explicit_Dereference then
Subp := Etype (Nam);
-- Normal case
-- Call using a selected component notation or Ada 2005 object
-- operation notation
elsif Nkind (Nam) = N_Selected_Component then
Subp := Entity (Selector_Name (Nam));
-- Common case
else
Subp := Entity (Nam);
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2012, 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- --
......@@ -50,13 +50,33 @@ package Sem_Ch6 is
-- and body declarations. Returns the defining entity for the
-- specification N.
procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id);
procedure Cannot_Inline
(Msg : String;
N : Node_Id;
Subp : Entity_Id;
Is_Serious : Boolean := False);
-- This procedure is called if the node N, an instance of a call to
-- subprogram Subp, cannot be inlined. Msg is the message to be issued,
-- and has a ? as the last character. If Subp has a pragma Always_Inlined,
-- then an error message is issued (by removing the last character of Msg).
-- If Subp is not Always_Inlined, then a warning is issued if the flag
-- Ineffective_Inline_Warnings is set, and if not, the call has no effect.
-- and has a ? as the last character. Temporarily the behavior of this
-- routine depends on the value of -gnatd.k:
-- * If -gnatd.k is not set (ie. old inlining model) then if Subp has
-- a pragma Always_Inlined, then an error message is issued (by
-- removing the last character of Msg). If Subp is not Always_Inlined,
-- then a warning is issued if the flag Ineffective_Inline_Warnings
-- is set, and if not, the call has no effect.
-- * If -gnatd.k is set (ie. new inlining model) then:
-- - If Is_Serious is true, then an error is reported (by removing the
-- last character of Msg);
-- - otherwise:
-- * Compiling without optimizations if Subp has a pragma
-- Always_Inlined, then an error message is issued; if Subp is
-- not Always_Inlined, then a warning is issued if the flag
-- Ineffective_Inline_Warnings is set, and if not, the call
-- has no effect.
-- * Compiling with optimizations then a warning is issued if
-- the flag Ineffective_Inline_Warnings is set; otherwise the
-- call has no effect since inlining may be performed by the
-- backend.
procedure Check_Conventions (Typ : Entity_Id);
-- Ada 2005 (AI-430): Check that the conventions of all inherited and
......
......@@ -5611,6 +5611,15 @@ package body Sem_Res is
and then Has_Pragma_Inline_Always (Nam)
and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
and then not Debug_Flag_Dot_K
then
null;
elsif Is_Inlined (Nam)
and then Has_Pragma_Inline (Nam)
and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
and then Debug_Flag_Dot_K
then
null;
......
......@@ -9389,6 +9389,18 @@ package body Sem_Util is
Mark_Allocators (Root_Nod);
end Mark_Coextensions;
-----------------
-- Must_Inline --
-----------------
function Must_Inline (Subp : Entity_Id) return Boolean is
begin
return Optimization_Level = 0
and then Has_Pragma_Inline (Subp)
and then (Has_Pragma_Inline_Always (Subp)
or else Front_End_Inlining);
end Must_Inline;
----------------------
-- Needs_One_Actual --
----------------------
......@@ -11767,6 +11779,18 @@ package body Sem_Util is
Reset_Analyzed (N);
end Reset_Analyzed_Flags;
--------------------------------
-- Returns_Unconstrained_Type --
--------------------------------
function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
begin
return Ekind (Subp) = E_Function
and then not Is_Scalar_Type (Etype (Subp))
and then not Is_Access_Type (Etype (Subp))
and then not Is_Constrained (Etype (Subp));
end Returns_Unconstrained_Type;
---------------------------
-- Safe_To_Capture_Value --
---------------------------
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2012, 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- --
......@@ -1115,6 +1115,9 @@ package Sem_Util is
-- to guarantee this in all cases. Note that it is more possible to give
-- correct answer if the tree is fully analyzed.
function Must_Inline (Subp : Entity_Id) return Boolean;
-- Return true if Subp must be inlined by the frontend
function Needs_One_Actual (E : Entity_Id) return Boolean;
-- Returns True if a function has defaults for all but its first
-- formal. Used in Ada 2005 mode to solve the syntactic ambiguity that
......@@ -1307,6 +1310,9 @@ package Sem_Util is
procedure Reset_Analyzed_Flags (N : Node_Id);
-- Reset the Analyzed flags in all nodes of the tree whose root is N
function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean;
-- Return true if Subp is a function that returns an unconstrained type
function Safe_To_Capture_Value
(N : Node_Id;
Ent : Entity_Id;
......
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