This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR fortran/38883: Fix MVBITS for subcomponent-references


Hi all,

this patch fixes PR fortran/38883. This regression turned up when I added correct dependency checking for MVBITS, which results in a temporary being created for the test-case (before, wrong-code could result). This temporary is however created with the type of the expression to mirror, which is incorrect for subcomponent-references, as the real value it is expected to hold is of the real derived-type, while the expression's type is only the type of the referenced field. This made gfortran ICE here.

The fix is to create the temporary also of the full derived-type; while this is not the "best" way (see the TODO comment) of course, it is quite simple and works; another solution could use gfc_conv_subref_array_arg but would need to modify the caller of gfc_conv_elemental_dependencies as well and may easily get complicated. Thus I'd go with this patch until we really want to optimize this (which seems unnecessary to me, I don't think this case happens often).

Regression-testing at the moment on GNU/Linux-x86-32; I hope I got it all right, this is not my strongest part of gfortran... (That's also why I introduced the regression, of course ;).) Ok for trunk if no failures?

Yours,
Daniel

PS: I just switched my system from using root for nearly everything (it was quite comfortable, though...), and now running the testsuite complains about "could not spawn". Does anybody know what could be wrong here? For now, I'm just running the regtest as root still which works flawlessly.

--
Done:  Arc-Bar-Cav-Rog-Sam-Tou-Val-Wiz
To go: Hea-Kni-Mon-Pri-Ran
2009-01-26  Daniel Kraft  <d@domob.eu>

	PR fortran/38883
	* trans-stmt.c (gfc_conv_elemental_dependencies):  Create temporary
	for the real type needed to make it work for subcomponent-references.

2009-01-26  Daniel Kraft  <d@domob.eu>

	PR fortran/38883
	* gfortran.dg/mvbits_6.f90:  New test.
	* gfortran.dg/mvbits_7.f90:  New test.
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c	(revision 143663)
+++ gcc/fortran/trans-stmt.c	(working copy)
@@ -252,7 +252,7 @@ gfc_conv_elemental_dependencies (gfc_se 
 	    && gfc_check_fncall_dependency (e, fsym->attr.intent,
 					    sym, arg0, check_variable))
 	{
-	  tree initial;
+	  tree initial, temptype;
 	  stmtblock_t temp_post;
 
 	  /* Make a local loopinfo for the temporary creation, so that
@@ -278,6 +278,17 @@ gfc_conv_elemental_dependencies (gfc_se 
 	  else
 	    initial = NULL_TREE;
 
+	  /* Find the type of the temporary to create; we don't use the type
+	     of e itself as this breaks for subcomponent-references in e (where
+	     the type of e is that of the final reference, but parmse.expr's
+	     type corresponds to the full derived-type).  */
+	  /* TODO: Fix this somehow so we don't need a temporary of the whole
+	     array but instead only the components referenced.  */
+	  temptype = TREE_TYPE (parmse.expr); /* Pointer to descriptor.  */
+	  gcc_assert (TREE_CODE (temptype) == POINTER_TYPE);
+	  temptype = TREE_TYPE (temptype);
+	  temptype = gfc_get_element_type (temptype);
+
 	  /* Generate the temporary.  Merge the block so that the
 	     declarations are put at the right binding level.  Cleaning up the
 	     temporary should be the very last thing done, so we add the code to
@@ -286,9 +297,8 @@ gfc_conv_elemental_dependencies (gfc_se 
 	  data = gfc_create_var (pvoid_type_node, NULL);
 	  gfc_start_block (&block);
 	  gfc_init_block (&temp_post);
-	  tmp = gfc_typenode_for_spec (&e->ts);
 	  tmp = gfc_trans_create_temp_array (&se->pre, &temp_post,
-					     &tmp_loop, info, tmp,
+					     &tmp_loop, info, temptype,
 					     initial,
 					     false, true, false,
 					     &arg->expr->where);
@@ -315,7 +325,7 @@ gfc_conv_elemental_dependencies (gfc_se 
 	  tmp = build_call_expr (gfor_fndecl_in_unpack, 2, parmse.expr, data);
 	  gfc_add_expr_to_block (&se->post, tmp);
 
-	  gfc_add_block_to_block (&se->pre, &parmse.pre);
+	  /* parmse.pre is already added above.  */
 	  gfc_add_block_to_block (&se->post, &parmse.post);
 	  gfc_add_block_to_block (&se->post, &temp_post);
 	}
Index: gcc/testsuite/gfortran.dg/mvbits_7.f90
===================================================================
--- gcc/testsuite/gfortran.dg/mvbits_7.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/mvbits_7.f90	(revision 0)
@@ -0,0 +1,33 @@
+! { dg-do compile }
+
+! PR fortran/38883
+! This ICE'd because the temporary-creation in the MVBITS call was wrong.
+! This is the original test from the PR, the complicated version.
+
+! Contributed by Dick Hendrickson <dick.hendrickson@gmail.com>
+
+     module yg0009_stuff
+
+      type unseq
+         integer I
+      end type
+
+      contains
+
+      SUBROUTINE YG0009(TDA2L,NF4,NF3,NF1,MF1,MF4,MF3)
+        TYPE(UNSEQ) TDA2L(NF4,NF3)
+
+        CALL MVBITS (TDA2L(NF4:NF1:MF1,NF1:NF3)%I,2, &
+          4, TDA2L(-MF4:-MF1:-NF1,-MF1:-MF3)%I, 3)
+
+      END SUBROUTINE
+
+      end module yg0009_stuff
+
+      program try_yg0009
+      use yg0009_stuff
+      type(unseq)  tda2l(4,3)
+
+      call yg0009(tda2l,4,3,1,-1,-4,-3)
+
+      end
Index: gcc/testsuite/gfortran.dg/mvbits_6.f90
===================================================================
--- gcc/testsuite/gfortran.dg/mvbits_6.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/mvbits_6.f90	(revision 0)
@@ -0,0 +1,21 @@
+! { dg-do compile }
+
+! PR fortran/38883
+! This ICE'd because the temporary-creation in the MVBITS call was wrong.
+! This is the reduced test from Tobias Burnus <burnus@gcc.gnu.org> in the PR.
+
+! Contributed by Dick Hendrickson <dick.hendrickson@gmail.com>
+
+module yg0009_stuff
+  implicit none
+  type unseq
+     integer I
+  end type
+contains
+  SUBROUTINE YG0009(A,N2)
+    TYPE(UNSEQ) A(2)
+    TYPE(UNSEQ) B(2)
+    integer :: N2
+    CALL MVBITS (A(1:2)%I,1, 1, A(1:N2)%I, 1)
+  END SUBROUTINE
+end module yg0009_stuff

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]