See discussion at http://gcc.gnu.org/ml/fortran/2011-07/msg00281.html and see PR 45586.

This patch fixes the test case of the PR by properly using the nonrestricted type for pointer components. Before, the test case failed (ICE) in some tree checking. While the ICE only affects the trunk (more precisely: --enable-checking={yes,tree}), the issue itself also affects the branches.

I am not completely sure that the patch covers all restrict/nonrestrict issues, but it fixes the PR and I couldn't create a variant which still gave an ICE.

Build and regtested on x86-64-linux.
OK for the trunk? What about backporting to 4.6 and to 4.5?

Tobias
2011-07-27  Tobias Burnus  <bur...@net-b.de>

	PR fortran/45586
	* trans-types.c (gfc_get_derived_type): Ensure that pointer
	component types are marked as nonrestricted.

2011-07-27  Tobias Burnus  <bur...@net-b.de>

	PR fortran/45586
	* gfortran.dg/lto/pr45586-2_0.f90: New.

diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index b66941f..bec2a11 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -2421,6 +2421,9 @@ gfc_get_derived_type (gfc_symbol * derived)
 	       && !c->attr.proc_pointer)
 	field_type = build_pointer_type (field_type);
 
+      if (c->attr.pointer)
+	field_type = gfc_nonrestricted_type (field_type);
+
       /* vtype fields can point to different types to the base type.  */
       if (c->ts.type == BT_DERIVED && c->ts.u.derived->attr.vtype)
 	  field_type = build_pointer_type_for_mode (TREE_TYPE (field_type),
--- /dev/null	2011-07-27 08:24:41.216620249 +0200
+++ gcc/gcc/testsuite/gfortran.dg/lto/pr45586-2_0.f90	2011-07-27 21:44:48.000000000 +0200
@@ -0,0 +1,34 @@
+! { dg-lto-do link }
+!
+! PR fortran/45586 (comment 53)
+!
+
+MODULE M1
+  INTEGER, PARAMETER :: dp=8
+  TYPE realspace_grid_type
+     REAL(KIND=dp), DIMENSION ( :, :, : ), ALLOCATABLE :: r
+  END TYPE realspace_grid_type
+  TYPE realspace_grid_p_type
+     TYPE(realspace_grid_type), POINTER :: rs_grid
+  END TYPE realspace_grid_p_type
+  TYPE realspaces_grid_p_type
+     TYPE(realspace_grid_p_type), DIMENSION(:), POINTER :: rs
+  END TYPE realspaces_grid_p_type
+END MODULE
+
+MODULE M2
+ USE M1
+CONTAINS
+ SUBROUTINE S1()
+  INTEGER :: i,j
+  TYPE(realspaces_grid_p_type), DIMENSION(:), POINTER :: rs_gauge
+  REAL(dp), DIMENSION(:, :, :), POINTER    :: y
+  y=>rs_gauge(i)%rs(j)%rs_grid%r
+ END SUBROUTINE
+END MODULE
+
+USE M2
+  CALL S1()
+END
+
+! { dg-final { cleanup-modules "m1 m2" } }

Reply via email to