This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] Component declarations overwrite types of Cray Pointee variables


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

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
confirmed up through trunk (5.0).

Here is a proposed patch from 4.8.3 (test case comments/ChangeLog
descriptions are updated from the submission on bugzilla). The test
case demonstrates the problem.

FYI, I am currently working with my employer so any future changes I
have can comply with GNU's legal requirements. Also my mail client
replaces tabs with spaces so I'm sorry for any whitespace issues.

2014-09-02  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.

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)


2014-09-02  Fritz Reese  <Reese-Fritz@zai.com>

        PR fortran/62174
        * gcc/testsuite/gfortran.dg/cray_pointers_11.f90: New.

diff --git a/gcc/testsuite/gfortran.dg/cray_pointers_11.f90
b/gcc/testsuite/gfortran.dg/cray_pointers_11.f90
new file mode 100644
index 0000000..038e4dc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/cray_pointers_11.f90
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! { dg-options "-fcray-pointer" }
+!
+! PR fortran/62174
+! 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

---
Fritz Reese


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]