Bug 54443 - [4.7 Regression] Segmentation Fault when Compiling for code using Fortran Polymorphic Entities
Summary: [4.7 Regression] Segmentation Fault when Compiling for code using Fortran Pol...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.2
: P4 normal
Target Milestone: 4.7.2
Assignee: janus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-31 23:23 UTC by Mark Beyer
Modified: 2012-09-10 12:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-09-01 00:00:00


Attachments
Sample Code (527 bytes, text/plain)
2012-08-31 23:23 UTC, Mark Beyer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Beyer 2012-08-31 23:23:54 UTC
Created attachment 28113 [details]
Sample Code

$gfortran --version

GNU Fortran (GCC) 4.7.2 20120818 (prerelease)
Copyright (C) 2012 Free Software Foundation, Inc.

$gfortran -C class.f03 -o class                    

f951: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

See attached code.
Comment 1 Dominique d'Humieres 2012-09-01 00:06:53 UTC
AFAICT the code is invalid:

pr54443.f90:43.25:

    select type(hp%htype)
                         1
Error: Selector in SELECT TYPE at (1) is not a named variable; use associate-name=>
...

From my archives, it seems to have been fixed on trunk between revisions 187200, 2012-05-05 (Segmentation fault) and 187291, 2012-05-08 (errors) and it has been introduced between revisions 182107, 2011-12-08 (errors) and 183001, 2012-01-27 (Segmentation fault).
Comment 2 Dominique d'Humieres 2012-09-01 00:30:05 UTC
Compiling the following reduced test

program class_test
  type hashnode
!    character(12) :: name
    character(4) :: htype
  end type hashnode
  class(hashnode), pointer :: hfirst,hcur,hp
    
    select type(hp%htype)
  
end program class_test

gives an internal compiler error: Segmentation fault with trunk, but the error

pr54443_red.f90:8.25:

    select type(hp%htype)
                         1   
Error: Selector in SELECT TYPE at (1) is not a named variable; use associate-name=>

if I uncomment the line character(12) :: name, while it still gives an ICE with 4.7.1.

The backtrace for trunk is

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
gfc_match_select_type () at ../../work/gcc/fortran/match.c:5438
5438			  && (strcmp (CLASS_DATA (expr1)->name, "_data") == 0)
(gdb) bt
#0  gfc_match_select_type () at ../../work/gcc/fortran/match.c:5438
#1  0x0000000100078fea in match_word (subr=<value temporarily unavailable, due to optimizations>, old_locus=0x100ea35e0) at ../../work/gcc/fortran/parse.c:67
#2  0x000000014180f750 in ?? ()
Previous frame inner to this frame (gdb could not unwind past this frame)
Comment 3 janus 2012-09-01 13:37:34 UTC
The test case in comment 2 ICEs on 4.7 and trunk, but gives the correct error in 4.6, so it's a regression.
Comment 4 janus 2012-09-01 14:02:05 UTC
This is apparently a duplicate of PR 54435. The patch given there also fixes the ICE here.
Comment 5 janus 2012-09-04 08:03:16 UTC
Author: janus
Date: Tue Sep  4 08:03:09 2012
New Revision: 190910

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190910
Log:
2012-09-04  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54435
	PR fortran/54443
	* match.c (gfc_match_select_type): Make sure to only access CLASS_DATA
	for BT_CLASS.

2012-09-04  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54243
	PR fortran/54244
	* gfortran.dg/select_type_29.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/select_type_29.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/match.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Richard Biener 2012-09-07 10:48:22 UTC
Fixed on trunk sofar.
Comment 7 janus 2012-09-10 12:10:27 UTC
Author: janus
Date: Mon Sep 10 12:10:12 2012
New Revision: 191135

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191135
Log:
2012-09-10  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54435
	PR fortran/54443
	* match.c (gfc_match_select_type): Make sure to only access CLASS_DATA
	for BT_CLASS.

2012-09-10  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54435
	PR fortran/54443
	* gfortran.dg/select_type_29.f03: New.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/select_type_29.f03
Modified:
    branches/gcc-4_7-branch/gcc/fortran/ChangeLog
    branches/gcc-4_7-branch/gcc/fortran/match.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 8 janus 2012-09-10 12:14:27 UTC
Fixed on trunk and 4.7. Closing.