PR fortran/99169 - [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument

Message ID trinity-1d5f2707-39e5-491b-88a8-2a9067b9557d-1613769381805@3c-app-gmx-bs31
State New
Headers show
Series
  • PR fortran/99169 - [9/10/11 Regression] Segfault when passing allocatable scalar into intent(out) dummy argument
Related show

Commit Message

Marek Polacek via Gcc-patches Feb. 19, 2021, 9:16 p.m.
Dear all,

we should not clobber the pointer in case of an allocatable scalar being
an intent(out) dummy argument to a procedure.

Regtested on x86_64-pc-linux-gnu.

OK for master?  Since this is a regression, also for backports to 10/9?

Thanks,
Harald


PR fortran/99169 - Do not clobber allocatable intent(out) dummy argument

gcc/fortran/ChangeLog:

	* trans-expr.c (gfc_conv_procedure_call): Do not add clobber to
	allocatable intent(out) argument.

gcc/testsuite/ChangeLog:

	* gfortran.dg/intent_optimize_3.f90: New test.

Comments

Tobias Burnus Feb. 20, 2021, 9:02 p.m. | #1
Dear Harald,

On 19.02.21 22:16, Harald Anlauf via Fortran wrote:
> we should not clobber the pointer in case of an allocatable scalar being

> an intent(out) dummy argument to a procedure.

>

> Regtested on x86_64-pc-linux-gnu.

> OK for master?  Since this is a regression, also for backports to 10/9?


OK to both master and to backporting.

Thanks for the patch!

Tobias

> PR fortran/99169 - Do not clobber allocatable intent(out) dummy argument

>

> gcc/fortran/ChangeLog:

>

>       * trans-expr.c (gfc_conv_procedure_call): Do not add clobber to

>       allocatable intent(out) argument.

>

> gcc/testsuite/ChangeLog:

>

>       * gfortran.dg/intent_optimize_3.f90: New test.

>

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf

Patch

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 103cb31c664..cab58cd1bba 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -6077,6 +6079,7 @@  gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 			&& !fsym->attr.allocatable && !fsym->attr.pointer
 			&& !e->symtree->n.sym->attr.dimension
 			&& !e->symtree->n.sym->attr.pointer
+			&& !e->symtree->n.sym->attr.allocatable
 			/* See PR 41453.  */
 			&& !e->symtree->n.sym->attr.dummy
 			/* FIXME - PR 87395 and PR 41453  */
diff --git a/gcc/testsuite/gfortran.dg/intent_optimize_3.f90 b/gcc/testsuite/gfortran.dg/intent_optimize_3.f90
new file mode 100644
index 00000000000..6ecd722da76
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/intent_optimize_3.f90
@@ -0,0 +1,16 @@ 
+! { dg-do run }
+! { dg-options "-O2" }
+! PR99169 - Segfault passing allocatable scalar into intent(out) dummy argument
+
+program p
+  implicit none
+  integer, allocatable :: i
+  allocate (i)
+  call set (i)
+  if (i /= 5) stop 1
+contains
+  subroutine set (i)
+    integer, intent(out) :: i
+    i = 5
+  end subroutine set
+end program p