comparison gcc/ada/inline.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
4 -- -- 4 -- --
5 -- I N L I N E -- 5 -- I N L I N E --
6 -- -- 6 -- --
7 -- B o d y -- 7 -- B o d y --
8 -- -- 8 -- --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- 9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
10 -- -- 10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under -- 11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- -- 12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- -- 13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- 14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
195 -- If a candidate for inlining contains type declarations for types with 195 -- If a candidate for inlining contains type declarations for types with
196 -- nontrivial initialization procedures, they are not worth inlining. 196 -- nontrivial initialization procedures, they are not worth inlining.
197 197
198 function Has_Single_Return (N : Node_Id) return Boolean; 198 function Has_Single_Return (N : Node_Id) return Boolean;
199 -- In general we cannot inline functions that return unconstrained type. 199 -- In general we cannot inline functions that return unconstrained type.
200 -- However, we can handle such functions if all return statements return a 200 -- However, we can handle such functions if all return statements return
201 -- local variable that is the only declaration in the body of the function. 201 -- a local variable that is the first declaration in the body of the
202 -- In that case the call can be replaced by that local variable as is done 202 -- function. In that case the call can be replaced by that local
203 -- for other inlined calls. 203 -- variable as is done for other inlined calls.
204 204
205 function In_Main_Unit_Or_Subunit (E : Entity_Id) return Boolean; 205 function In_Main_Unit_Or_Subunit (E : Entity_Id) return Boolean;
206 -- Return True if E is in the main unit or its spec or in a subunit 206 -- Return True if E is in the main unit or its spec or in a subunit
207 207
208 function Is_Nested (E : Entity_Id) return Boolean; 208 function Is_Nested (E : Entity_Id) return Boolean;
296 -- Level of inlining for the call: Dont_Inline means no inlining, 296 -- Level of inlining for the call: Dont_Inline means no inlining,
297 -- Inline_Call means that only the call is considered for inlining, 297 -- Inline_Call means that only the call is considered for inlining,
298 -- Inline_Package means that the call is considered for inlining and 298 -- Inline_Package means that the call is considered for inlining and
299 -- its package compiled and scanned for more inlining opportunities. 299 -- its package compiled and scanned for more inlining opportunities.
300 300
301 function Is_Non_Loading_Expression_Function
302 (Id : Entity_Id) return Boolean;
303 -- Determine whether arbitrary entity Id denotes a subprogram which is
304 -- either
305 --
306 -- * An expression function
307 --
308 -- * A function completed by an expression function where both the
309 -- spec and body are in the same context.
310
301 function Must_Inline return Inline_Level_Type; 311 function Must_Inline return Inline_Level_Type;
302 -- Inlining is only done if the call statement N is in the main unit, 312 -- Inlining is only done if the call statement N is in the main unit,
303 -- or within the body of another inlined subprogram. 313 -- or within the body of another inlined subprogram.
314
315 ----------------------------------------
316 -- Is_Non_Loading_Expression_Function --
317 ----------------------------------------
318
319 function Is_Non_Loading_Expression_Function
320 (Id : Entity_Id) return Boolean
321 is
322 Body_Decl : Node_Id;
323 Body_Id : Entity_Id;
324 Spec_Decl : Node_Id;
325
326 begin
327 -- A stand-alone expression function is transformed into a spec-body
328 -- pair in-place. Since both the spec and body are in the same list,
329 -- the inlining of such an expression function does not need to load
330 -- anything extra.
331
332 if Is_Expression_Function (Id) then
333 return True;
334
335 -- A function may be completed by an expression function
336
337 elsif Ekind (Id) = E_Function then
338 Spec_Decl := Unit_Declaration_Node (Id);
339
340 if Nkind (Spec_Decl) = N_Subprogram_Declaration then
341 Body_Id := Corresponding_Body (Spec_Decl);
342
343 if Present (Body_Id) then
344 Body_Decl := Unit_Declaration_Node (Body_Id);
345
346 -- The inlining of a completing expression function does
347 -- not need to load anything extra when both the spec and
348 -- body are in the same context.
349
350 return
351 Was_Expression_Function (Body_Decl)
352 and then Parent (Spec_Decl) = Parent (Body_Decl);
353 end if;
354 end if;
355 end if;
356
357 return False;
358 end Is_Non_Loading_Expression_Function;
304 359
305 ----------------- 360 -----------------
306 -- Must_Inline -- 361 -- Must_Inline --
307 ----------------- 362 -----------------
308 363
413 and then Is_Predefined_Unit (Get_Source_Unit (E)) 468 and then Is_Predefined_Unit (Get_Source_Unit (E))
414 then 469 then
415 Set_Needs_Debug_Info (E, False); 470 Set_Needs_Debug_Info (E, False);
416 end if; 471 end if;
417 472
418 -- If the subprogram is an expression function, then there is no need to 473 -- If the subprogram is an expression function, or is completed by one
419 -- load any package body since the body of the function is in the spec. 474 -- where both the spec and body are in the same context, then there is
420 475 -- no need to load any package body since the body of the function is
421 if Is_Expression_Function (E) then 476 -- in the spec.
477
478 if Is_Non_Loading_Expression_Function (E) then
422 Set_Is_Called (E); 479 Set_Is_Called (E);
423 return; 480 return;
424 end if; 481 end if;
425 482
426 -- Find unit containing E, and add to list of inlined bodies if needed. 483 -- Find unit containing E, and add to list of inlined bodies if needed.
820 Analysis_Status : constant Boolean := Full_Analysis; 877 Analysis_Status : constant Boolean := Full_Analysis;
821 Original_Body : Node_Id; 878 Original_Body : Node_Id;
822 Body_To_Analyze : Node_Id; 879 Body_To_Analyze : Node_Id;
823 Max_Size : constant := 10; 880 Max_Size : constant := 10;
824 881
882 function Has_Extended_Return return Boolean;
883 -- This function returns True if the subprogram has an extended return
884 -- statement.
885
825 function Has_Pending_Instantiation return Boolean; 886 function Has_Pending_Instantiation return Boolean;
826 -- If some enclosing body contains instantiations that appear before 887 -- If some enclosing body contains instantiations that appear before
827 -- the corresponding generic body, the enclosing body has a freeze node 888 -- the corresponding generic body, the enclosing body has a freeze node
828 -- so that it can be elaborated after the generic itself. This might 889 -- so that it can be elaborated after the generic itself. This might
829 -- conflict with subsequent inlinings, so that it is unsafe to try to 890 -- conflict with subsequent inlinings, so that it is unsafe to try to
837 -- inlining would generate gotos in that case as well (although the 898 -- inlining would generate gotos in that case as well (although the
838 -- goto is useless in that case). 899 -- goto is useless in that case).
839 900
840 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean; 901 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean;
841 -- If the body of the subprogram includes a call that returns an 902 -- If the body of the subprogram includes a call that returns an
842 -- unconstrained type, the secondary stack is involved, and it 903 -- unconstrained type, the secondary stack is involved, and it is
843 -- is not worth inlining. 904 -- not worth inlining.
905
906 -------------------------
907 -- Has_Extended_Return --
908 -------------------------
909
910 function Has_Extended_Return return Boolean is
911 Body_To_Inline : constant Node_Id := N;
912
913 function Check_Return (N : Node_Id) return Traverse_Result;
914 -- Returns OK on node N if this is not an extended return statement
915
916 ------------------
917 -- Check_Return --
918 ------------------
919
920 function Check_Return (N : Node_Id) return Traverse_Result is
921 begin
922 case Nkind (N) is
923 when N_Extended_Return_Statement =>
924 return Abandon;
925
926 -- Skip locally declared subprogram bodies inside the body to
927 -- inline, as the return statements inside those do not count.
928
929 when N_Subprogram_Body =>
930 if N = Body_To_Inline then
931 return OK;
932 else
933 return Skip;
934 end if;
935
936 when others =>
937 return OK;
938 end case;
939 end Check_Return;
940
941 function Check_All_Returns is new Traverse_Func (Check_Return);
942
943 -- Start of processing for Has_Extended_Return
944
945 begin
946 return Check_All_Returns (N) /= OK;
947 end Has_Extended_Return;
844 948
845 ------------------------------- 949 -------------------------------
846 -- Has_Pending_Instantiation -- 950 -- Has_Pending_Instantiation --
847 ------------------------------- 951 -------------------------------
848 952
979 and then not Has_Single_Return_In_GNATprove_Mode 1083 and then not Has_Single_Return_In_GNATprove_Mode
980 then 1084 then
981 Cannot_Inline ("cannot inline & (multiple returns)?", N, Spec_Id); 1085 Cannot_Inline ("cannot inline & (multiple returns)?", N, Spec_Id);
982 return; 1086 return;
983 1087
984 -- Functions that return unconstrained composite types require 1088 -- Functions that return controlled types cannot currently be inlined
985 -- secondary stack handling, and cannot currently be inlined, unless 1089 -- because they require secondary stack handling; controlled actions
986 -- all return statements return a local variable that is the first 1090 -- may also interfere in complex ways with inlining.
987 -- local declaration in the body.
988
989 elsif Ekind (Spec_Id) = E_Function
990 and then not Is_Scalar_Type (Etype (Spec_Id))
991 and then not Is_Access_Type (Etype (Spec_Id))
992 and then not Is_Constrained (Etype (Spec_Id))
993 then
994 if not Has_Single_Return (N) then
995 Cannot_Inline
996 ("cannot inline & (unconstrained return type)?", N, Spec_Id);
997 return;
998 end if;
999
1000 -- Ditto for functions that return controlled types, where controlled
1001 -- actions interfere in complex ways with inlining.
1002 1091
1003 elsif Ekind (Spec_Id) = E_Function 1092 elsif Ekind (Spec_Id) = E_Function
1004 and then Needs_Finalization (Etype (Spec_Id)) 1093 and then Needs_Finalization (Etype (Spec_Id))
1005 then 1094 then
1006 Cannot_Inline 1095 Cannot_Inline
1097 Set_Declarations (N, New_List (Body_To_Analyze)); 1186 Set_Declarations (N, New_List (Body_To_Analyze));
1098 else 1187 else
1099 Append (Body_To_Analyze, Declarations (N)); 1188 Append (Body_To_Analyze, Declarations (N));
1100 end if; 1189 end if;
1101 1190
1102 -- The body to inline is pre-analyzed. In GNATprove mode we must disable 1191 -- The body to inline is preanalyzed. In GNATprove mode we must disable
1103 -- full analysis as well so that light expansion does not take place 1192 -- full analysis as well so that light expansion does not take place
1104 -- either, and name resolution is unaffected. 1193 -- either, and name resolution is unaffected.
1105 1194
1106 Expander_Mode_Save_And_Set (False); 1195 Expander_Mode_Save_And_Set (False);
1107 Full_Analysis := False; 1196 Full_Analysis := False;
1119 1208
1120 if In_Instance and then Scope (Current_Scope) /= Standard_Standard then 1209 if In_Instance and then Scope (Current_Scope) /= Standard_Standard then
1121 Restore_Env; 1210 Restore_Env;
1122 end if; 1211 end if;
1123 1212
1213 -- Functions that return unconstrained composite types require
1214 -- secondary stack handling, and cannot currently be inlined, unless
1215 -- all return statements return a local variable that is the first
1216 -- local declaration in the body. We had to delay this check until
1217 -- the body of the function is analyzed since Has_Single_Return()
1218 -- requires a minimum decoration.
1219
1220 if Ekind (Spec_Id) = E_Function
1221 and then not Is_Scalar_Type (Etype (Spec_Id))
1222 and then not Is_Access_Type (Etype (Spec_Id))
1223 and then not Is_Constrained (Etype (Spec_Id))
1224 then
1225 if not Has_Single_Return (Body_To_Analyze)
1226
1227 -- Skip inlining if the function returns an unconstrained type
1228 -- using an extended return statement, since this part of the
1229 -- new inlining model is not yet supported by the current
1230 -- implementation. ???
1231
1232 or else (Returns_Unconstrained_Type (Spec_Id)
1233 and then Has_Extended_Return)
1234 then
1235 Cannot_Inline
1236 ("cannot inline & (unconstrained return type)?", N, Spec_Id);
1237 return;
1238 end if;
1239
1124 -- If secondary stack is used, there is no point in inlining. We have 1240 -- If secondary stack is used, there is no point in inlining. We have
1125 -- already issued the warning in this case, so nothing to do. 1241 -- already issued the warning in this case, so nothing to do.
1126 1242
1127 if Uses_Secondary_Stack (Body_To_Analyze) then 1243 elsif Uses_Secondary_Stack (Body_To_Analyze) then
1128 return; 1244 return;
1129 end if; 1245 end if;
1130 1246
1131 Set_Body_To_Inline (Decl, Original_Body); 1247 Set_Body_To_Inline (Decl, Original_Body);
1132 Set_Ekind (Defining_Entity (Original_Body), Ekind (Spec_Id)); 1248 Set_Ekind (Defining_Entity (Original_Body), Ekind (Spec_Id));
1489 if Is_Predefined_Unit (Get_Source_Unit (Subp)) 1605 if Is_Predefined_Unit (Get_Source_Unit (Subp))
1490 and then not In_Extended_Main_Source_Unit (Subp) 1606 and then not In_Extended_Main_Source_Unit (Subp)
1491 then 1607 then
1492 null; 1608 null;
1493 1609
1494 -- In GNATprove mode, issue a warning, and indicate that the 1610 -- In GNATprove mode, issue a warning when -gnatd_f is set, and
1495 -- subprogram is not always inlined by setting flag Is_Inlined_Always 1611 -- indicate that the subprogram is not always inlined by setting
1496 -- to False. 1612 -- flag Is_Inlined_Always to False.
1497 1613
1498 elsif GNATprove_Mode then 1614 elsif GNATprove_Mode then
1499 Set_Is_Inlined_Always (Subp, False); 1615 Set_Is_Inlined_Always (Subp, False);
1500 Error_Msg_NE (Msg & "p?", N, Subp); 1616
1617 if Debug_Flag_Underscore_F then
1618 Error_Msg_NE (Msg, N, Subp);
1619 end if;
1501 1620
1502 elsif Has_Pragma_Inline_Always (Subp) then 1621 elsif Has_Pragma_Inline_Always (Subp) then
1503 1622
1504 -- Remove last character (question mark) to make this into an 1623 -- Remove last character (question mark) to make this into an
1505 -- error, because the Inline_Always pragma cannot be obeyed. 1624 -- error, because the Inline_Always pragma cannot be obeyed.
1516 1635
1517 -- Remove last character (question mark) to make this into an error. 1636 -- Remove last character (question mark) to make this into an error.
1518 1637
1519 Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp); 1638 Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp);
1520 1639
1521 -- In GNATprove mode, issue a warning, and indicate that the subprogram 1640 -- In GNATprove mode, issue a warning when -gnatd_f is set, and
1522 -- is not always inlined by setting flag Is_Inlined_Always to False. 1641 -- indicate that the subprogram is not always inlined by setting
1642 -- flag Is_Inlined_Always to False.
1523 1643
1524 elsif GNATprove_Mode then 1644 elsif GNATprove_Mode then
1525 Set_Is_Inlined_Always (Subp, False); 1645 Set_Is_Inlined_Always (Subp, False);
1526 Error_Msg_NE (Msg & "p?", N, Subp); 1646
1647 if Debug_Flag_Underscore_F then
1648 Error_Msg_NE (Msg, N, Subp);
1649 end if;
1527 1650
1528 else 1651 else
1529 1652
1530 -- Do not emit warning if this is a predefined unit which is not 1653 -- Do not emit warning if this is a predefined unit which is not
1531 -- the main unit. This behavior is currently provided for backward 1654 -- the main unit. This behavior is currently provided for backward
1610 -- occurrences of pragmas referencing the formals are removed since 1733 -- occurrences of pragmas referencing the formals are removed since
1611 -- they have no meaning when the body is inlined and the formals are 1734 -- they have no meaning when the body is inlined and the formals are
1612 -- rewritten (the analysis of the non-inlined body will handle these 1735 -- rewritten (the analysis of the non-inlined body will handle these
1613 -- pragmas). A new internal name is associated with Body_To_Inline. 1736 -- pragmas). A new internal name is associated with Body_To_Inline.
1614 1737
1615 ----------------------------- 1738 ------------------------------
1616 -- Generate_Body_To_Inline -- 1739 -- Generate_Subprogram_Body --
1617 ----------------------------- 1740 ------------------------------
1618 1741
1619 procedure Generate_Subprogram_Body 1742 procedure Generate_Subprogram_Body
1620 (N : Node_Id; 1743 (N : Node_Id;
1621 Body_To_Inline : out Node_Id) 1744 Body_To_Inline : out Node_Id)
1622 is 1745 is
2210 procedure Expand_Inlined_Call 2333 procedure Expand_Inlined_Call
2211 (N : Node_Id; 2334 (N : Node_Id;
2212 Subp : Entity_Id; 2335 Subp : Entity_Id;
2213 Orig_Subp : Entity_Id) 2336 Orig_Subp : Entity_Id)
2214 is 2337 is
2338 Decls : constant List_Id := New_List;
2339 Is_Predef : constant Boolean :=
2340 Is_Predefined_Unit (Get_Source_Unit (Subp));
2215 Loc : constant Source_Ptr := Sloc (N); 2341 Loc : constant Source_Ptr := Sloc (N);
2216 Is_Predef : constant Boolean := 2342 Orig_Bod : constant Node_Id :=
2217 Is_Predefined_Unit (Get_Source_Unit (Subp));
2218 Orig_Bod : constant Node_Id :=
2219 Body_To_Inline (Unit_Declaration_Node (Subp)); 2343 Body_To_Inline (Unit_Declaration_Node (Subp));
2344
2345 Uses_Back_End : constant Boolean :=
2346 Back_End_Inlining and then Optimization_Level > 0;
2347 -- The back-end expansion is used if the target supports back-end
2348 -- inlining and some level of optimixation is required; otherwise
2349 -- the inlining takes place fully as a tree expansion.
2220 2350
2221 Blk : Node_Id; 2351 Blk : Node_Id;
2222 Decl : Node_Id; 2352 Decl : Node_Id;
2223 Decls : constant List_Id := New_List; 2353 Exit_Lab : Entity_Id := Empty;
2224 Exit_Lab : Entity_Id := Empty;
2225 F : Entity_Id; 2354 F : Entity_Id;
2226 A : Node_Id; 2355 A : Node_Id;
2227 Lab_Decl : Node_Id; 2356 Lab_Decl : Node_Id := Empty;
2228 Lab_Id : Node_Id; 2357 Lab_Id : Node_Id;
2229 New_A : Node_Id; 2358 New_A : Node_Id;
2230 Num_Ret : Nat := 0; 2359 Num_Ret : Nat := 0;
2231 Ret_Type : Entity_Id; 2360 Ret_Type : Entity_Id;
2232
2233 Targ : Node_Id;
2234 -- The target of the call. If context is an assignment statement then
2235 -- this is the left-hand side of the assignment, else it is a temporary
2236 -- to which the return value is assigned prior to rewriting the call.
2237
2238 Targ1 : Node_Id := Empty;
2239 -- A separate target used when the return type is unconstrained
2240
2241 Temp : Entity_Id; 2361 Temp : Entity_Id;
2242 Temp_Typ : Entity_Id; 2362 Temp_Typ : Entity_Id;
2243
2244 Return_Object : Entity_Id := Empty;
2245 -- Entity in declaration in an extended_return_statement
2246 2363
2247 Is_Unc : Boolean; 2364 Is_Unc : Boolean;
2248 Is_Unc_Decl : Boolean; 2365 Is_Unc_Decl : Boolean;
2249 -- If the type returned by the function is unconstrained and the call 2366 -- If the type returned by the function is unconstrained and the call
2250 -- can be inlined, special processing is required. 2367 -- can be inlined, special processing is required.
2368
2369 Return_Object : Entity_Id := Empty;
2370 -- Entity in declaration in an extended_return_statement
2371
2372 Targ : Node_Id := Empty;
2373 -- The target of the call. If context is an assignment statement then
2374 -- this is the left-hand side of the assignment, else it is a temporary
2375 -- to which the return value is assigned prior to rewriting the call.
2376
2377 Targ1 : Node_Id := Empty;
2378 -- A separate target used when the return type is unconstrained
2251 2379
2252 procedure Declare_Postconditions_Result; 2380 procedure Declare_Postconditions_Result;
2253 -- When generating C code, declare _Result, which may be used in the 2381 -- When generating C code, declare _Result, which may be used in the
2254 -- inlined _Postconditions procedure to verify the return value. 2382 -- inlined _Postconditions procedure to verify the return value.
2255 2383
2423 Num_Ret := Num_Ret + 1; 2551 Num_Ret := Num_Ret + 1;
2424 Make_Exit_Label; 2552 Make_Exit_Label;
2425 end if; 2553 end if;
2426 2554
2427 -- Because of the presence of private types, the views of the 2555 -- Because of the presence of private types, the views of the
2428 -- expression and the context may be different, so place an 2556 -- expression and the context may be different, so place
2429 -- unchecked conversion to the context type to avoid spurious 2557 -- a type conversion to the context type to avoid spurious
2430 -- errors, e.g. when the expression is a numeric literal and 2558 -- errors, e.g. when the expression is a numeric literal and
2431 -- the context is private. If the expression is an aggregate, 2559 -- the context is private. If the expression is an aggregate,
2432 -- use a qualified expression, because an aggregate is not a 2560 -- use a qualified expression, because an aggregate is not a
2433 -- legal argument of a conversion. Ditto for numeric literals 2561 -- legal argument of a conversion. Ditto for numeric, character
2434 -- and attributes that yield a universal type, because those 2562 -- and string literals, and attributes that yield a universal
2435 -- must be resolved to a specific type. 2563 -- type, because those must be resolved to a specific type.
2436 2564
2437 if Nkind_In (Expression (N), N_Aggregate, N_Null) 2565 if Nkind_In (Expression (N), N_Aggregate,
2566 N_Character_Literal,
2567 N_Null,
2568 N_String_Literal)
2438 or else Yields_Universal_Type (Expression (N)) 2569 or else Yields_Universal_Type (Expression (N))
2439 then 2570 then
2440 Ret := 2571 Ret :=
2441 Make_Qualified_Expression (Sloc (N), 2572 Make_Qualified_Expression (Sloc (N),
2442 Subtype_Mark => New_Occurrence_Of (Ret_Type, Sloc (N)), 2573 Subtype_Mark => New_Occurrence_Of (Ret_Type, Sloc (N)),
2443 Expression => Relocate_Node (Expression (N))); 2574 Expression => Relocate_Node (Expression (N)));
2444 else 2575
2576 -- Use an unchecked type conversion between access types, for
2577 -- which a type conversion would not always be valid, as no
2578 -- check may result from the conversion.
2579
2580 elsif Is_Access_Type (Ret_Type) then
2445 Ret := 2581 Ret :=
2446 Unchecked_Convert_To 2582 Unchecked_Convert_To
2447 (Ret_Type, Relocate_Node (Expression (N))); 2583 (Ret_Type, Relocate_Node (Expression (N)));
2584
2585 -- Otherwise use a type conversion, which may trigger a check
2586
2587 else
2588 Ret :=
2589 Make_Type_Conversion (Sloc (N),
2590 Subtype_Mark => New_Occurrence_Of (Ret_Type, Sloc (N)),
2591 Expression => Relocate_Node (Expression (N)));
2448 end if; 2592 end if;
2449 2593
2450 if Nkind (Targ) = N_Defining_Identifier then 2594 if Nkind (Targ) = N_Defining_Identifier then
2451 Rewrite (N, 2595 Rewrite (N,
2452 Make_Assignment_Statement (Loc, 2596 Make_Assignment_Statement (Loc,
2765 -- Start of processing for Expand_Inlined_Call 2909 -- Start of processing for Expand_Inlined_Call
2766 2910
2767 begin 2911 begin
2768 -- Initializations for old/new semantics 2912 -- Initializations for old/new semantics
2769 2913
2770 if not Back_End_Inlining then 2914 if not Uses_Back_End then
2771 Is_Unc := Is_Array_Type (Etype (Subp)) 2915 Is_Unc := Is_Array_Type (Etype (Subp))
2772 and then not Is_Constrained (Etype (Subp)); 2916 and then not Is_Constrained (Etype (Subp));
2773 Is_Unc_Decl := False; 2917 Is_Unc_Decl := False;
2774 else 2918 else
2775 Is_Unc := Returns_Unconstrained_Type (Subp) 2919 Is_Unc := Returns_Unconstrained_Type (Subp)
2792 -- Skip inlining if this is not a true inlining since the attribute 2936 -- Skip inlining if this is not a true inlining since the attribute
2793 -- Body_To_Inline is also set for renamings (see sinfo.ads). For a 2937 -- Body_To_Inline is also set for renamings (see sinfo.ads). For a
2794 -- true inlining, Orig_Bod has code rather than being an entity. 2938 -- true inlining, Orig_Bod has code rather than being an entity.
2795 2939
2796 elsif Nkind (Orig_Bod) in N_Entity then 2940 elsif Nkind (Orig_Bod) in N_Entity then
2797 return;
2798
2799 -- Skip inlining if the function returns an unconstrained type using
2800 -- an extended return statement since this part of the new inlining
2801 -- model which is not yet supported by the current implementation. ???
2802
2803 elsif Is_Unc
2804 and then
2805 Nkind (First (Statements (Handled_Statement_Sequence (Orig_Bod)))) =
2806 N_Extended_Return_Statement
2807 and then not Back_End_Inlining
2808 then
2809 return; 2941 return;
2810 end if; 2942 end if;
2811 2943
2812 if Nkind (Orig_Bod) = N_Defining_Identifier 2944 if Nkind (Orig_Bod) = N_Defining_Identifier
2813 or else Nkind (Orig_Bod) = N_Defining_Operator_Symbol 2945 or else Nkind (Orig_Bod) = N_Defining_Operator_Symbol
2839 Save_Env (Subp, Empty); 2971 Save_Env (Subp, Empty);
2840 Set_Copied_Sloc_For_Inlined_Body (N, Defining_Entity (Orig_Bod)); 2972 Set_Copied_Sloc_For_Inlined_Body (N, Defining_Entity (Orig_Bod));
2841 2973
2842 -- Old semantics 2974 -- Old semantics
2843 2975
2844 if not Back_End_Inlining then 2976 if not Uses_Back_End then
2845 declare 2977 declare
2846 Bod : Node_Id; 2978 Bod : Node_Id;
2847 2979
2848 begin 2980 begin
2849 Bod := Copy_Generic_Node (Orig_Bod, Empty, Instantiating => True); 2981 Bod := Copy_Generic_Node (Orig_Bod, Empty, Instantiating => True);
2882 declare 3014 declare
2883 First_Decl : Node_Id; 3015 First_Decl : Node_Id;
2884 3016
2885 begin 3017 begin
2886 First_Decl := First (Declarations (Blk)); 3018 First_Decl := First (Declarations (Blk));
3019
3020 -- If the body is a single extended return statement,the
3021 -- resulting block is a nested block.
3022
3023 if No (First_Decl) then
3024 First_Decl :=
3025 First (Statements (Handled_Statement_Sequence (Blk)));
3026
3027 if Nkind (First_Decl) = N_Block_Statement then
3028 First_Decl := First (Declarations (First_Decl));
3029 end if;
3030 end if;
3031
3032 -- No front-end inlining possible
2887 3033
2888 if Nkind (First_Decl) /= N_Object_Declaration then 3034 if Nkind (First_Decl) /= N_Object_Declaration then
2889 return; 3035 return;
2890 end if; 3036 end if;
2891 3037
3154 3300
3155 if GNATprove_Mode 3301 if GNATprove_Mode
3156 and then Ekind (F) /= E_Out_Parameter 3302 and then Ekind (F) /= E_Out_Parameter
3157 and then not Same_Type (Etype (F), Etype (A)) 3303 and then not Same_Type (Etype (F), Etype (A))
3158 then 3304 then
3159 pragma Assert (not (Is_By_Reference_Type (Etype (A)))); 3305 pragma Assert (not Is_By_Reference_Type (Etype (A)));
3160 pragma Assert (not (Is_Limited_Type (Etype (A)))); 3306 pragma Assert (not Is_Limited_Type (Etype (A)));
3161 3307
3162 Append_To (Decls, 3308 Append_To (Decls,
3163 Make_Object_Declaration (Loc, 3309 Make_Object_Declaration (Loc,
3164 Defining_Identifier => Make_Temporary (Loc, 'C'), 3310 Defining_Identifier => Make_Temporary (Loc, 'C'),
3165 Constant_Present => True, 3311 Constant_Present => True,
3213 3359
3214 -- New semantics: In an object declaration avoid an extra copy 3360 -- New semantics: In an object declaration avoid an extra copy
3215 -- of the result of a call to an inlined function that returns 3361 -- of the result of a call to an inlined function that returns
3216 -- an unconstrained type 3362 -- an unconstrained type
3217 3363
3218 elsif Back_End_Inlining 3364 elsif Uses_Back_End
3219 and then Nkind (Parent (N)) = N_Object_Declaration 3365 and then Nkind (Parent (N)) = N_Object_Declaration
3220 and then Is_Unc 3366 and then Is_Unc
3221 then 3367 then
3222 Targ := Defining_Identifier (Parent (N)); 3368 Targ := Defining_Identifier (Parent (N));
3223 3369
3766 begin 3912 begin
3767 if Nkind (N) = N_Simple_Return_Statement then 3913 if Nkind (N) = N_Simple_Return_Statement then
3768 if Present (Expression (N)) 3914 if Present (Expression (N))
3769 and then Is_Entity_Name (Expression (N)) 3915 and then Is_Entity_Name (Expression (N))
3770 then 3916 then
3917 pragma Assert (Present (Entity (Expression (N))));
3918
3771 if No (Return_Statement) then 3919 if No (Return_Statement) then
3772 Return_Statement := N; 3920 Return_Statement := N;
3773 return OK; 3921 return OK;
3774 3922
3775 elsif Chars (Expression (N)) =
3776 Chars (Expression (Return_Statement))
3777 then
3778 return OK;
3779
3780 else 3923 else
3781 return Abandon; 3924 pragma Assert
3925 (Present (Entity (Expression (Return_Statement))));
3926
3927 if Entity (Expression (N)) =
3928 Entity (Expression (Return_Statement))
3929 then
3930 return OK;
3931 else
3932 return Abandon;
3933 end if;
3782 end if; 3934 end if;
3783 3935
3784 -- A return statement within an extended return is a noop 3936 -- A return statement within an extended return is a noop after
3785 -- after inlining. 3937 -- inlining.
3786 3938
3787 elsif No (Expression (N)) 3939 elsif No (Expression (N))
3788 and then 3940 and then Nkind (Parent (Parent (N))) =
3789 Nkind (Parent (Parent (N))) = N_Extended_Return_Statement 3941 N_Extended_Return_Statement
3790 then 3942 then
3791 return OK; 3943 return OK;
3792 3944
3793 else 3945 else
3794 -- Expression has wrong form 3946 -- Expression has wrong form
3823 3975
3824 elsif Nkind (Return_Statement) = N_Extended_Return_Statement then 3976 elsif Nkind (Return_Statement) = N_Extended_Return_Statement then
3825 return True; 3977 return True;
3826 3978
3827 else 3979 else
3828 return Present (Declarations (N)) 3980 return
3829 and then Present (First (Declarations (N))) 3981 Present (Declarations (N))
3830 and then Chars (Expression (Return_Statement)) = 3982 and then Present (First (Declarations (N)))
3831 Chars (Defining_Identifier (First (Declarations (N)))); 3983 and then Entity (Expression (Return_Statement)) =
3984 Defining_Identifier (First (Declarations (N)));
3832 end if; 3985 end if;
3833 end Has_Single_Return; 3986 end Has_Single_Return;
3834 3987
3835 ----------------------------- 3988 -----------------------------
3836 -- In_Main_Unit_Or_Subunit -- 3989 -- In_Main_Unit_Or_Subunit --