Commit 08402a6d by Ed Schonberg Committed by Arnaud Charlet

sem_ch6.adb (Build_Body_To_Inline): Enforce the rule that in order to inline a…

sem_ch6.adb (Build_Body_To_Inline): Enforce the rule that in order to inline a function that returns an...

2006-02-17  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch6.adb (Build_Body_To_Inline): Enforce the rule that in order
	to inline a function that returns an unconstrained type, the return
	expression must be the first variable declared in the body of the
	function.

From-SVN: r111194
parent 030d25f4
...@@ -2163,7 +2163,10 @@ package body Sem_Ch6 is ...@@ -2163,7 +2163,10 @@ package body Sem_Ch6 is
-- Start of processing for Has_Single_Return -- Start of processing for Has_Single_Return
begin begin
return Check_All_Returns (N) = OK; return Check_All_Returns (N) = OK
and then Present (Declarations (N))
and then Chars (Expression (Return_Statement)) =
Chars (Defining_Identifier (First (Declarations (N))));
end Has_Single_Return; end Has_Single_Return;
-------------------- --------------------
...@@ -2231,20 +2234,24 @@ package body Sem_Ch6 is ...@@ -2231,20 +2234,24 @@ package body Sem_Ch6 is
then then
return; -- Done already. return; -- Done already.
-- Functions that return unconstrained composite types will require -- Functions that return unconstrained composite types require
-- secondary stack handling, and cannot currently be inlined. -- secondary stack handling, and cannot currently be inlined, unless
-- Ditto for functions that return controlled types, where controlled -- all return statements return a local variable that is the first
-- actions interfere in complex ways with inlining. -- local declaration in the body.
elsif Ekind (Subp) = E_Function elsif Ekind (Subp) = E_Function
and then not Is_Scalar_Type (Etype (Subp)) and then not Is_Scalar_Type (Etype (Subp))
and then not Is_Access_Type (Etype (Subp)) and then not Is_Access_Type (Etype (Subp))
and then not Is_Constrained (Etype (Subp)) and then not Is_Constrained (Etype (Subp))
and then not Has_Single_Return
then then
Cannot_Inline if not Has_Single_Return then
("cannot inline & (unconstrained return type)?", N, Subp); Cannot_Inline
return; ("cannot inline & (unconstrained return type)?", N, Subp);
return;
end if;
-- Ditto for functions that return controlled types, where controlled
-- actions interfere in complex ways with inlining.
elsif Ekind (Subp) = E_Function elsif Ekind (Subp) = E_Function
and then Controlled_Type (Etype (Subp)) and then Controlled_Type (Etype (Subp))
......
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