aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/inline.adb
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2019-07-03 08:16:11 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-07-03 08:16:11 +0000
commit5460389b1fde0393afeaab5ce338ebe72a517cae (patch)
tree8ede8d2ef640803b5dc6e2a8358d56ff9cc36a3f /gcc/ada/inline.adb
parenteee51f3dd6d8e444270efb6fe191524b79a01445 (diff)
downloadgcc-5460389b1fde0393afeaab5ce338ebe72a517cae.zip
gcc-5460389b1fde0393afeaab5ce338ebe72a517cae.tar.gz
gcc-5460389b1fde0393afeaab5ce338ebe72a517cae.tar.bz2
[Ada] Crash on front-end inlining of subp. with aspect specifications
This patch fixes a gap in the handling of formals when inlining a call to a subprogram marked Inline_Always. For the inlining, the formals are replaced by the actuals in the block constructed for inlining, The traversal that performs this replacement does not apply to aspect specifications that may appear in the original body, because these aspects are only indirectly reachable from the nodes to which they apply: a separate traversal is required to perform the replacement in the expressions for any aspect specification present in the source. 2019-07-03 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * inline.adb (Process_Formals_In_Aspects): New procedure within Expand_Inlined_Call, to perform a replacement of references to formals that appear in aspect specifications within the body being inlined. gcc/testsuite/ * gnat.dg/inline16.adb, gnat.dg/inline16_gen.adb, gnat.dg/inline16_gen.ads, gnat.dg/inline16_types.ads: New testcase. From-SVN: r272983
Diffstat (limited to 'gcc/ada/inline.adb')
-rw-r--r--gcc/ada/inline.adb31
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
index 653908a..b2038a6 100644
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -2481,6 +2481,13 @@ package body Inline is
-- thunk generated for it. Replace a return statement with an assignment
-- to the target of the call, with appropriate conversions if needed.
+ function Process_Formals_In_Aspects (N : Node_Id)
+ return Traverse_Result;
+ -- Because aspects are linked indirectly to the rest of the tree,
+ -- replacement of formals appearing in aspect specifications must
+ -- be performed in a separate pass, using an instantiation of the
+ -- previous subprogram over aspect specifications reachable from N.
+
function Process_Sloc (Nod : Node_Id) return Traverse_Result;
-- If the call being expanded is that of an internal subprogram, set the
-- sloc of the generated block to that of the call itself, so that the
@@ -2821,6 +2828,29 @@ package body Inline is
procedure Replace_Formals is new Traverse_Proc (Process_Formals);
+ --------------------------------
+ -- Process_Formals_In_Aspects --
+ --------------------------------
+
+ function Process_Formals_In_Aspects (N : Node_Id)
+ return Traverse_Result
+ is
+ A : Node_Id;
+ begin
+ if Has_Aspects (N) then
+ A := First (Aspect_Specifications (N));
+ while Present (A) loop
+ Replace_Formals (Expression (A));
+
+ Next (A);
+ end loop;
+ end if;
+ return OK;
+ end Process_Formals_In_Aspects;
+
+ procedure Replace_Formals_In_Aspects is
+ new Traverse_Proc (Process_Formals_In_Aspects);
+
------------------
-- Process_Sloc --
------------------
@@ -3633,6 +3663,7 @@ package body Inline is
-- Attach block to tree before analysis and rewriting.
Replace_Formals (Blk);
+ Replace_Formals_In_Aspects (Blk);
Set_Parent (Blk, N);
if GNATprove_Mode then