diff options
author | Ed Schonberg <schonberg@adacore.com> | 2006-02-17 17:08:18 +0100 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2006-02-17 17:08:18 +0100 |
commit | 08402a6d65a25da348c28c0a539dd0923ff976d6 (patch) | |
tree | c1fa03b193cef9a8d00f313fc3f07caaa0eb3cb2 /gcc/ada | |
parent | 030d25f41343f0996b56368a54e609959428a0c6 (diff) | |
download | gcc-08402a6d65a25da348c28c0a539dd0923ff976d6.zip gcc-08402a6d65a25da348c28c0a539dd0923ff976d6.tar.gz gcc-08402a6d65a25da348c28c0a539dd0923ff976d6.tar.bz2 |
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
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/sem_ch6.adb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index 66a2430..33696df 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -2163,7 +2163,10 @@ package body Sem_Ch6 is -- Start of processing for Has_Single_Return 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; -------------------- @@ -2231,20 +2234,24 @@ package body Sem_Ch6 is then return; -- Done already. - -- Functions that return unconstrained composite types will require - -- secondary stack handling, and cannot currently be inlined. - -- Ditto for functions that return controlled types, where controlled - -- actions interfere in complex ways with inlining. + -- Functions that return unconstrained composite types require + -- secondary stack handling, and cannot currently be inlined, unless + -- all return statements return a local variable that is the first + -- local declaration in the body. elsif 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)) - and then not Has_Single_Return then - Cannot_Inline - ("cannot inline & (unconstrained return type)?", N, Subp); - return; + if not Has_Single_Return then + Cannot_Inline + ("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 and then Controlled_Type (Etype (Subp)) |