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)


Hi Jakub,

the patch looks ok to me. I am wondering whether we should setup a routine
or a macro for doing such a DECL_EXPR like Fortran needs it. In your case the
TYPE_DECL is marked artificial and ignored in other cases not. Would that be
need also at the six other locations gfortran uses a type decl?

My idea of using a common way to do these DECL_EXPR is to prevent us 
fortraneers from doing something wrong, because we don't usually need this
construct. And a "templated" way prevents us from reinventing the wheel anew
with the all pits one can fall in.

Regards,
	Andre

On Wed, 14 Dec 2016 22:55:29 +0100
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?
> 
> 2016-12-14  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/pr78757.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/pr78757.f90.jj	2016-12-14
> 15:28:09.707932278 +0100 +++ gcc/testsuite/gfortran.dg/pr78757.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 (70_8)
> +contains
> +  function foo (i)
> +    integer (8) :: i
> +    character (len = i), pointer :: foo
> +    foo => x
> +  end function foo
> +end program pr78757
> 
> 	Jakub


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


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