public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran, PR58586, v1]  ICE with derived type with allocatable component passed by value
@ 2015-04-15 18:03 Andre Vehreschild
  2015-04-19 10:01 ` Mikael Morin
  0 siblings, 1 reply; 19+ messages in thread
From: Andre Vehreschild @ 2015-04-15 18:03 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

[-- Attachment #1: Type: text/plain, Size: 817 bytes --]

Hi all,

by accident I patched this pr. For short, when a structure constructor for a
structure with an allocatable component or a function returning a type with an
allocatable component is passed as actual argument to a function, then gfortran
ICEs. This patch fixes, both the ICE and a segfault at runtime.

I was pointed to the patch in comment #44 of pr61831 which seemingly fixes the
#3 comment of pr58586, too, but causes a memory leak. I therefore like to point
out, that adding the a->expr.expr_type != EXPR_STRUCTURE of Mikael's patch in
pr61831 should not be added to trans-expr.c::gfc_conv_procedure_call (), when
this patch for 58586 is applied.

Bootstraps and regtests ok on x86_64-linux-gnu/F21.

Ok, for trunk 6.0, when open again?

Regards,
	Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: pr58586_1.clog --]
[-- Type: application/octet-stream, Size: 393 bytes --]

gcc/testsuite/ChangeLog:

2015-04-15  Andre Vehreschild  <vehre@gmx.de>

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


gcc/fortran/ChangeLog:

2015-04-15  Andre Vehreschild  <vehre@gmx.de>

	* trans-expr.c (gfc_conv_procedure_call): For EXPR_STRUCTURE
	hand the tree without indirect ref. And for EXPR_FUNCTIONs
	add a temporary variable to prevent calling the function
	multiple times.


[-- Attachment #3: pr58586_1.patch --]
[-- Type: text/x-patch, Size: 1951 bytes --]

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 9e6432f..80dfed1 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -5344,8 +5344,19 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
 	    && (e->expr_type != EXPR_VARIABLE && !e->rank))
         {
 	  int parm_rank;
-	  tmp = build_fold_indirect_ref_loc (input_location,
-					 parmse.expr);
+	  /* It is known the e returns a structure type with at least one
+	     allocatable component.  When e is a function, ensure that the
+	     function is called once only by using a temporary variable.  */
+	  if (e->expr_type == EXPR_FUNCTION)
+	    parmse.expr = gfc_evaluate_now_loc (input_location,
+						parmse.expr, &se->pre);
+
+	  if (POINTER_TYPE_P (TREE_TYPE (parmse.expr)))
+	    tmp = build_fold_indirect_ref_loc (input_location,
+					       parmse.expr);
+	  else
+	    tmp = parmse.expr;
+
 	  parm_rank = e->rank;
 	  switch (parm_kind)
 	    {
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f90
new file mode 100644
index 0000000..297fae1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f90
@@ -0,0 +1,41 @@
+! { dg-do run }
+!
+! Check that pr58586 is fixed now.
+! Based on a contribution by Vladimir Fuka
+! Contibuted by Andre Vehreschild
+
+program test_pr58586
+  implicit none
+
+  type :: a
+  end type
+
+  type :: c
+     type(a), allocatable :: a
+  end type
+
+  type :: b
+     integer, allocatable :: a
+  end type
+
+  ! These two are merely to check, if compilation works
+  call add(b())
+  call add(b(null()))
+
+  ! This needs to execute, to see whether the segfault at runtime is resolved
+  call add_c(c_init())
+
+contains
+
+  subroutine add (d)
+    type(b), value :: d
+  end subroutine
+
+  subroutine add_c (d)
+    type(c), value :: d
+  end subroutine
+
+  type(c) function c_init()
+  end function
+end program test_pr58586
+

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-07-06 10:32 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-15 18:03 [Patch, Fortran, PR58586, v1] ICE with derived type with allocatable component passed by value Andre Vehreschild
2015-04-19 10:01 ` Mikael Morin
2015-04-23 18:01   ` [Patch, Fortran, PR58586, v2] " Andre Vehreschild
2015-04-24  8:37     ` Andre Vehreschild
2015-04-26 10:23     ` Mikael Morin
2015-05-05  9:00       ` [Patch, Fortran, PR58586, v3] " Andre Vehreschild
2015-05-07 10:15         ` Mikael Morin
2015-05-08 10:54           ` Andre Vehreschild
2015-05-08 13:21             ` Mikael Morin
2015-05-08 13:31               ` Andre Vehreschild
2015-05-08 14:11                 ` Andre Vehreschild
2015-05-19 14:02                   ` [Patch, Fortran, PR58586, v4] " Andre Vehreschild
2015-07-03  9:29                     ` [Ping, Patch, Fortran, PR58586, v5] " Andre Vehreschild
2015-07-04 16:25                       ` Steve Kargl
2015-07-04 19:20                         ` Andre Vehreschild
2015-07-05 16:15                           ` Steve Kargl
2015-07-05 17:48                             ` Paul Richard Thomas
2015-07-05 18:14                               ` Steve Kargl
2015-07-06 10:32                               ` [commited, " Andre Vehreschild

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).