Bug 1134560 - Component declarations overwrite types of Cray Pointee variables
Summary: Component declarations overwrite types of Cray Pointee variables
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: gcc
Version: 6.4
Hardware: x86_64
OS: Linux
Target Milestone: rc
: ---
Assignee: Jakub Jelinek
QA Contact: Miroslav Franc
URL: https://gcc.gnu.org/bugzilla/show_bug...
Depends On:
TreeView+ depends on / blocked
Reported: 2014-08-27 19:07 UTC by Fritz Reese
Modified: 2016-02-01 02:29 UTC (History)
6 users (show)

Fixed In Version: gcc-4.4.7-12.el6
Doc Type: Bug Fix
Doc Text:
In previous versions of the GNU Fortran compiler, the type specifiers for Cray pointees were incorrectly overwritten by the type specifiers of components with the same name. Consequently, compiling failed with an error message. This bug has been fixed, and the Cray pointers are now handled correctly.
Clone Of:
Last Closed: 2015-07-22 06:48:16 UTC

Attachments (Terms of Use)
Patch and testcase (1.26 KB, patch)
2014-08-27 19:13 UTC, Fritz Reese
no flags Details | Diff

System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:1339 normal SHIPPED_LIVE gcc bug fix and enhancement update 2015-07-20 18:00:00 UTC
GNU Compiler Collection 62174 None None None Never

Description Fritz Reese 2014-08-27 19:07:49 UTC
User-Agent:       Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0
Build Identifier: 

The typespecs for Cray pointees are overwritten by the typespecs of components with the same name which are declared later. The problem is present as far as I can tell from gcc-4.1.0 all the way up through gcc-4.8.3.

Reproducible: Always

Steps to Reproduce:

type t1
  integer i
end type t1
type(t1) x

pointer (x_ptr, x)

type t2
  real x ! this declaration overwrites x's type
end type t2

x%i = 0 ! this causes an error; the compiler thinks x is a real

Actual Results:  
Running gfortran-4.4.7 shipped with RH6.4:

$ gfortran test.f90

x%i = 0 ! this causes an error; the compiler thinks x is a real
Error: Unexpected '%' for nonderived-type variable 'x' at (1)

Expected Results:  
There should be no compile errors.

Submitted the bug report to GNU (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62174) but have not heard back. I have a patch which I will attach.

Comment 2 Fritz Reese 2014-08-27 19:13:52 UTC
Created attachment 931658 [details]
Patch and testcase

Here is a proposed patch and testcase. When variable_decl() finds a declaration which shares a name with a Cray pointee, it should not care if the declaration is actually a component declaration.

2014-08-18  Fritz Reese  <Reese-Fritz@zai.com>

	* 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)
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

Comment 9 errata-xmlrpc 2015-07-22 06:48:16 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.