https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80668
All, The following fixes a bug exposed in PR 80668 in which the compiler attempted to generate an initializer for components of derived types with the POINTER attribute when compiling with -finit-derived and -finit-*=*. It is nonsensical for components with the POINTER attribute to have initializers generated in this way. The resolution phase caught the resulting contradictions, resulting in an error for the testcase given in the PR. With the patch all regression tests pass except for the following, which already fail in the current trunk (r247800): Running /data/midas/foreese/src/gcc-dev/gcc/testsuite/gfortran.dg/dg.exp ... FAIL: gfortran.dg/coarray_lock_7.f90 -O scan-tree-dump-times original "_gfortran_caf_lock \\(caf_token.., \\(3 - \\(integer\\(kind=4\\)\\) parm...dim\\[0\\].lbound\\) \\+ \\(integer\\(kind=4\\)\\) MAX_EXPR <\\(parm...dim\\[0\\].ubound - parm...dim\\[0\\].lbound\\) \\+ 1, 0> \\* \\(3 - \\(integer\\(kind=4\\)\\) parm...dim\\[1\\].lbound\\), 0, 0B, &ii, 0B, 0\\);|_gfortran_caf_lock \\(caf_token.1, \\(3 - parm...dim\\[0\\].lbound\\) \\+ MAX_EXPR <\\(parm...dim\\[0\\].ubound - parm...dim\\[0\\].lbound\\) \\+ 1, 0> \\* \\(3 - parm...dim\\[1\\].lbound\\), 0, 0B, &ii, 0B, 0\\);" 1 FAIL: gfortran.dg/coarray_lock_7.f90 -O scan-tree-dump-times original "_gfortran_caf_unlock \\(caf_token.., \\(2 - \\(integer\\(kind=4\\)\\) parm...dim\\[0\\].lbound\\) \\+ \\(integer\\(kind=4\\)\\) MAX_EXPR <\\(parm...dim\\[0\\].ubound - parm...dim\\[0\\].lbound\\) \\+ 1, 0> \\* \\(3 - \\(integer\\(kind=4\\)\\) parm...dim\\[1\\].lbound\\), 0, &ii, 0B, 0\\);|_gfortran_caf_unlock \\(caf_token.., \\(2 - parm...dim\\[0\\].lbound\\) \\+ MAX_EXPR <\\(parm...dim\\[0\\].ubound - parm...dim\\[0\\].lbound\\) \\+ 1, 0> \\* \\(3 - parm...dim\\[1\\].lbound\\), 0, &ii, 0B, 0\\);" 1 FAIL: gfortran.dg/mvbits_7.f90 -O0 (test for warnings, line 28) OK for trunk? --- Fritz Reese 2017-05-09 Fritz Reese <fritzore...@gmail.com> PR fortran/80668 gcc/fortran/ChangeLog: PR fortran/80668 * expr.c (component_initializer): Don't generate initializers for pointer components. * invoke.texi (-finit-derived): Document. gcc/testsuite/ChangeLog: PR fortran/80668 * gfortran.dg/pr80668.f90: New.
From bd14dcb2026636052a50bb5a7f7075de0fc3b856 Mon Sep 17 00:00:00 2001 From: Fritz Reese <fritzore...@gmail.com> Date: Tue, 9 May 2017 08:42:19 -0400 Subject: [PATCH] 2017-05-09 Fritz Reese <fritzore...@gmail.com> PR fortran/80668 gcc/fortran/ * expr.c (component_initializer): Don't generate initializers for pointer components. * invoke.texi (-finit-derived): Document. * gcc/testsuite/gfortran.dg/pr80668.f90: New. --- gcc/fortran/expr.c | 8 ++++++-- gcc/fortran/invoke.texi | 2 ++ gcc/testsuite/gfortran.dg/pr80668.f90 | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr80668.f90 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index c8be9513af5..7ea9d8233a9 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -4280,9 +4280,13 @@ component_initializer (gfc_typespec *ts, gfc_component *c, bool generate) { gfc_expr *init = NULL; - /* See if we can find the initializer immediately. */ + /* See if we can find the initializer immediately. + Some components should never get initializers. */ if (c->initializer || !generate - || (ts->type == BT_CLASS && !c->attr.allocatable)) + || (ts->type == BT_CLASS && !c->attr.allocatable) + || c->attr.pointer + || c->attr.class_pointer + || c->attr.proc_pointer) return c->initializer; /* Recursively handle derived type components. */ diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 636432fead8..8a1d09dd5e5 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -1665,6 +1665,8 @@ according to these flags only with @option{-finit-derived}. These options do not initialize @itemize @bullet @item +objects with the POINTER attribute +@item allocatable arrays @item variables that appear in an @code{EQUIVALENCE} statement. diff --git a/gcc/testsuite/gfortran.dg/pr80668.f90 b/gcc/testsuite/gfortran.dg/pr80668.f90 new file mode 100644 index 00000000000..f69327c3302 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr80668.f90 @@ -0,0 +1,32 @@ +! { dg-do compile } +! { dg-options "-finit-derived -finit-integer=12345678" } +! +! PR fortran/80668 +! +! Test a regression where structure constructor expressions were created for +! POINTER components with -finit-derived. +! + +MODULE pr80668 + IMPLICIT NONE + TYPE :: dist_t + INTEGER :: TYPE,nblks_loc,nblks + INTEGER,DIMENSION(:),POINTER :: dist ! regression: "element in structure + ! constructor... should be a POINTER" + END TYPE dist_t + +CONTAINS + + SUBROUTINE hfx_new() + TYPE(dist_t) :: dist + integer,pointer :: bob + CALL release_dist(dist, bob) + END SUBROUTINE hfx_new + + SUBROUTINE release_dist(dist,p) + TYPE(dist_t) :: dist + integer, pointer, intent(in) :: p + END SUBROUTINE release_dist +END MODULE + +! { dg-final { cleanup-modules "pr80668" } } -- 2.12.2