re PR fortran/80668 (wrong error message with -finit-derived)
authorFritz Reese <fritzoreese@gmail.com>
Wed, 17 May 2017 15:13:58 +0000 (15:13 +0000)
committerFritz Reese <foreese@gcc.gnu.org>
Wed, 17 May 2017 15:13:58 +0000 (15:13 +0000)
2017-05-17  Fritz Reese <fritzoreese@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-SVN: r248158

gcc/fortran/ChangeLog
gcc/fortran/expr.c
gcc/fortran/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr80668.f90 [new file with mode: 0644]

index a364e4460f91637388e2c08af215018f84914c94..e978f32b8be7430e26436ea3c548be455321eff9 100644 (file)
@@ -1,3 +1,10 @@
+2017-05-17  Fritz Reese <fritzoreese@gmail.com>
+
+       PR fortran/80668
+       * expr.c (component_initializer): Don't generate initializers for
+       pointer components.
+       * invoke.texi (-finit-derived): Document.
+
 2017-05-16  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/80554
index c7d3e549c5b9edc0339865aa0262177e4bc2f262..9b2e5657a1a956203723d233e2fb6c573ae08c42 100644 (file)
@@ -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.  */
index 636432fead8b8645490112cd58ff679f6c1f32b2..8a1d09dd5e524c394d7370405373d855daba3ad5 100644 (file)
@@ -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.
index 8f62adb2d620014afd387dfaeeb3d0f41c7eb4f9..d75f985c5d41b06a479957f772e26dc7d50d94da 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-17  Fritz Reese <fritzoreese@gmail.com>
+
+       PR fortran/80668
+       * gfortran.dg/pr80668.f90: New.
+
 2017-05-17  Peter Bergner  <bergner@vnet.ibm.com>
 
        PR middle-end/80775
diff --git a/gcc/testsuite/gfortran.dg/pr80668.f90 b/gcc/testsuite/gfortran.dg/pr80668.f90
new file mode 100644 (file)
index 0000000..63bd0d3
--- /dev/null
@@ -0,0 +1,29 @@
+! { 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
+  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