diff mbox

[Fortran] Component declarations overwrite types of Cray Pointee variables

Message ID CAE4aFAmpdZycpNrMo+ZQOq+d7vc5YtE7emwJnTUDM2EXXFm1XA@mail.gmail.com
State New
Headers show

Commit Message

Fritz Reese Sept. 2, 2014, 5:49 p.m. UTC
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.


---
Fritz Reese

Comments

Tobias Burnus Sept. 3, 2014, 6:50 p.m. UTC | #1
Fritz Reese wrote:
> The typespecs for Cray pointees are overwritten by the typespecs of
> components with the same name which are declared later.
> 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.

OK. Thanks for the patch. I have committed it as Rev. 214891.

> FYI, I am currently working with my employer so any future changes I
> have can comply with GNU's legal requirements.
That would be useful. In terms of complexity and number of line changes 
of the actual code, I think it still counts as "trivial" such that I 
have committed the patch without waiting for the copyright assignment.

> Also my mail client replaces tabs with spaces so I'm sorry for any whitespace issues.

An alternative would be to attach the patch – possibly such that the 
mail client uses "text/*" as MIME code (e.g. using ".txt" as suffix, 
though several programs also handle other extensions). That way it shows 
up as text in most email programs and in the mail archive as text.

> 2014-09-02  Fritz Reese  <Reese-Fritz@zai.com>
>
>          PR fortran/62174
>          * gcc/testsuite/gfortran.dg/cray_pointers_11.f90: New.

Two nits: I'd prefer if you placed both changelogs before the actual 
patch - not between different parts of the patch. And entries in 
ChangeLog files are relative to the file, i.e. in this case 
"gfortran.dg/..." instead of "gcc/testsuite/gfortran.dg/...".

Tobias
diff mbox

Patch

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