https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62174

            Bug ID: 62174
           Summary: Component declarations overwrite types of Cray Pointee
                    variables
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fritzoreese at gmail dot com

Created attachment 33353
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33353&action=edit
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-fr...@zai.com>
+
+    * decl.c (variable_decl): Don't overwrite typesepc of Cray pointees
+    when matching a component declaration.
+
 2014-08-17  Tobias Burnus  <bur...@net-b.de>

     * resolve.c (gfc_resolve_finalizers): Ensure that parents are

Reply via email to