This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Re: [PATCH] Emit DECL_EXPR so that type of what pstr.N points to is gimplified (PR fortran/78757)


On Fri, Dec 16, 2016 at 09:31:37PM +0200, Janne Blomqvist wrote:
> On Wed, Dec 14, 2016 at 11:55 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > Hi!
> >
> > The gimplifier (because of Ada :( ) doesn't recurse to POINTER_TYPE's
> > type when gimplifying types, so we need a DECL_EXPR to gimplify such
> > types if they are VLAs.  The following patch is an attempt to do that.
> >
> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> Ok, but could you name the testcase something more descriptive, say,
> char_result_16.f90?

Thanks, I've also changed the 70_8 to 30_8 in the testcase, so that it is
clearly valid.  It still ICEs without the patch and works with the patch.

So here is what I've committed:

2016-12-16  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/78757
	* trans-expr.c (gfc_conv_procedure_call): Emit DECL_EXPR for the
	type pstr var points to.

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

--- gcc/fortran/trans-expr.c.jj	2016-12-09 20:32:39.000000000 +0100
+++ gcc/fortran/trans-expr.c	2016-12-14 15:22:50.142968565 +0100
@@ -6009,6 +6009,19 @@ gfc_conv_procedure_call (gfc_se * se, gf
 	    {
 	      var = gfc_create_var (type, "pstr");
 
+	      /* Emit a DECL_EXPR for the VLA type.  */
+	      tmp = TREE_TYPE (type);
+	      if (TYPE_SIZE (tmp)
+		  && TREE_CODE (TYPE_SIZE (tmp)) != INTEGER_CST)
+		{
+		  tmp = build_decl (input_location, TYPE_DECL, NULL_TREE, tmp);
+		  DECL_ARTIFICIAL (tmp) = 1;
+		  DECL_IGNORED_P (tmp) = 1;
+		  tmp = fold_build1_loc (input_location, DECL_EXPR,
+					 TREE_TYPE (tmp), tmp);
+		  gfc_add_expr_to_block (&se->pre, tmp);
+		}
+
 	      if ((!comp && sym->attr.allocatable)
 		  || (comp && comp->attr.allocatable))
 		{
--- gcc/testsuite/gfortran.dg/char_result_16.f90.jj	2016-12-14 15:28:09.707932278 +0100
+++ gcc/testsuite/gfortran.dg/char_result_16.f90	2016-12-14 15:27:54.000000000 +0100
@@ -0,0 +1,16 @@
+! PR fortran/78757
+! { dg-do compile }
+! { dg-options "-O1" }
+
+program pr78757
+  implicit none
+  character (len = 30), target :: x
+  character (len = 30), pointer :: s
+  s => foo (30_8)
+contains
+  function foo (i)
+    integer (8) :: i
+    character (len = i), pointer :: foo
+    foo => x
+  end function foo
+end program pr78757


	Jakub


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