diff mbox series

ipa/97673 - fix input_location leak

Message ID nycvar.YFH.7.76.2101191321490.30936@elmra.sevgm.obk
State New
Headers show
Series ipa/97673 - fix input_location leak | expand

Commit Message

Richard Biener Jan. 19, 2021, 12:22 p.m. UTC
This fixes input_location leaking with an invalid BLOCK from
expand_call_inline to tree_function_versioning via clone
materialization.

Bootstrapped and tested on x86_64-unknown-linux-gnu (with an
extra hunk calling verify_gimple from tree-function-versioning)

Pushed.

2021-01-19  Richard Biener  <rguenther@suse.de>

	PR ipa/97673
	* tree-inline.c (tree_function_versioning): Set input_location
	to UNKNOWN_LOCATION throughout the function.

	* gfortran.dg/pr97673.f90: New testcase.
---
 gcc/testsuite/gfortran.dg/pr97673.f90 | 14 ++++++++++++++
 gcc/tree-inline.c                     |  7 +++++++
 2 files changed, 21 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr97673.f90
diff mbox series

Patch

diff --git a/gcc/testsuite/gfortran.dg/pr97673.f90 b/gcc/testsuite/gfortran.dg/pr97673.f90
new file mode 100644
index 00000000000..33b81435806
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr97673.f90
@@ -0,0 +1,14 @@ 
+! { dg-do compile }
+! { dg-options "-O3 -fno-early-inlining --param large-stack-frame=4000" }
+
+subroutine sub3noiso(a, b)
+  use iso_c_binding
+  implicit none
+  character(len=1,kind=c_char) :: a(*), b
+  character(len=1,kind=c_char):: x,z
+  integer(c_int) :: y
+  value :: b
+  print *, a(1:2), b
+entry sub3noisoEntry(x,y,z)
+  x = 'd'
+end subroutine sub3noiso
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 84f71d9c6cc..3100b845f23 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -6215,6 +6215,12 @@  tree_function_versioning (tree old_decl, tree new_decl,
   auto_vec<gimple *, 10> init_stmts;
   tree vars = NULL_TREE;
 
+  /* We can get called recursively from expand_call_inline via clone
+     materialization.  While expand_call_inline maintains input_location
+     we cannot tolerate it to leak into the materialized clone.  */
+  location_t saved_location = input_location;
+  input_location = UNKNOWN_LOCATION;
+
   gcc_assert (TREE_CODE (old_decl) == FUNCTION_DECL
 	      && TREE_CODE (new_decl) == FUNCTION_DECL);
   DECL_POSSIBLY_INLINED (old_decl) = 1;
@@ -6517,6 +6523,7 @@  tree_function_versioning (tree old_decl, tree new_decl,
 
   gcc_assert (!id.debug_stmts.exists ());
   pop_cfun ();
+  input_location = saved_location;
   return;
 }