Created attachment 33353 [details] Proposed patch for the described problem The typespecs for Cray pointees are overwritten by the typespecs of components with the same name which are declared later. This problem was introduced with Cray pointer support in 4.1.0 and is present as far as I can tell up through the current release. Here is a proposed patch from 4.8.3. The added test case demonstrates the problem: diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 4048ac9..7b3c59a 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -1904,8 +1904,9 @@ variable_decl (int elem) } /* If this symbol has already shown up in a Cray Pointer declaration, + and this is not a component declaration, then we want to set the type & bail out. */ - if (gfc_option.flag_cray_pointer) + if (gfc_option.flag_cray_pointer && gfc_current_state () != COMP_DERIVED) { gfc_find_symbol (name, gfc_current_ns, 1, &sym); if (sym != NULL && sym->attr.cray_pointee) diff --git a/gcc/testsuite/gfortran.dg/cray_pointers_10.f90 b/gcc/testsuite/gfortran.dg/cray_pointers_10.f90 new file mode 100644 index 0000000..fcc0132 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/cray_pointers_10.f90 @@ -0,0 +1,22 @@ +! { dg-do compile } +! { dg-options "-fcray-pointer" } +! +! Since the introduction of Cray pointers in 4.1.0 as late as 4.8.3, +! component declarations within derived types would overwrite the typespec of +! variables with the same name who were Cray pointees. +implicit none + +type t1 + integer i +end type t1 +type(t1) x + +pointer (x_ptr, x) + +type t2 + real x ! should not overwrite x's type +end type t2 + +x%i = 0 ! should see no error here + +end diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 53d2691..8d8f9d5 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2014-08-18 Fritz Reese <Reese-Fritz@zai.com> + + * decl.c (variable_decl): Don't overwrite typesepc of Cray pointees + when matching a component declaration. + 2014-08-17 Tobias Burnus <burnus@net-b.de> * resolve.c (gfc_resolve_finalizers): Ensure that parents are
Patches should go to the gcc-patches at gcc.gnu.org mailing list (and in case of Fortran FE patches also CC fortran at gcc.gnu.org ml). That is where patch review happens. For a one-liner change like this, I think you don't need Copyright assignment, but if you plan to submit further patches, please consider following https://gcc.gnu.org/contribute.html
Confirmed from 4.7 up to trunk (5.0).
> Patches should go to the gcc-patches at gcc.gnu.org mailing list (and in > case of Fortran FE patches also CC fortran at gcc.gnu.org ml). That is > where patch review happens. Sorry - submitted to the mailing lists. https://gcc.gnu.org/ml/gcc-patches/2014-09/msg00175.html https://gcc.gnu.org/ml/fortran/2014-09/msg00007.html > For a one-liner change like this, I think you > don't need Copyright assignment, but if you plan to submit further patches, > please consider following https://gcc.gnu.org/contribute.html I am working with my employer now to decide how best to comply with GNU's legal requirements for future contributions.
Author: burnus Date: Wed Sep 3 18:50:27 2014 New Revision: 214891 URL: https://gcc.gnu.org/viewcvs?rev=214891&root=gcc&view=rev Log: 2014-09-03 Fritz Reese <Reese-Fritz@zai.com> PR fortran/62174 * decl.c (variable_decl): Don't overwrite typespecs of Cray * pointees when matching a component declaration. 2014-09-02 Fritz Reese <Reese-Fritz@zai.com> PR fortran/62174 * gfortran.dg/cray_pointers_11.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/cray_pointers_11.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/decl.c trunk/gcc/testsuite/ChangeLog
FIXED on the trunk (i.e. GCC 5). Thanks for the report, test case and patch!