This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[PATCH] Emit DECL_EXPR so that type of what pstr.N points to is gimplified (PR fortran/78757)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: fortran at gcc dot gnu dot org, Richard Biener <rguenther at suse dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 14 Dec 2016 22:55:29 +0100
- Subject: [PATCH] Emit DECL_EXPR so that type of what pstr.N points to is gimplified (PR fortran/78757)
- Authentication-results: sourceware.org; auth=none
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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