User account creation filtered due to spam.

Bug 42257 - [OOP] Compiler segmentation fault due missing public statement
Summary: [OOP] Compiler segmentation fault due missing public statement
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: janus
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2009-12-02 21:09 UTC by Oystein Olsen
Modified: 2009-12-22 17:58 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-12-11 15:54:55


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oystein Olsen 2009-12-02 21:09:49 UTC
The incorrect code below causes an segmentation fault in the latest gfortran. I am using

gcc version 4.5.0 20091130 (experimental) [trunk revision 154853] (GCC)

The program compiles and works if I make the type "time" public. However, an error message would be nice.

Code:

MODULE run_example_fortran03
  IMPLICIT NONE
  PRIVATE
  PUBLIC :: I4B, DP, epoch
  !PUBLIC :: time

  INTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9)
  INTEGER, PARAMETER :: DP = SELECTED_REAL_KIND(15,307)
    
  TYPE epoch
     INTEGER(I4B) :: i = 2451545
     REAL(DP)     :: f = 0.5_DP
  END TYPE epoch
  
  TYPE, EXTENDS(epoch) :: time
     REAL(DP) :: t = 0.0_DP   
  END TYPE time
END MODULE run_example_fortran03

PROGRAM example_fortran03
  USE  run_example_fortran03
  IMPLICIT NONE

  CLASS(epoch), ALLOCATABLE :: e4

  
  ! Allocate a class
  ALLOCATE(epoch::e4)
  WRITE(*,*) e4%i, e4%f

  STOP
END PROGRAM example_fortran03
Comment 1 janus 2009-12-03 07:32:13 UTC
Confirmed. The ICE's backtrace is

#0  0x0000000000504bcf in load_derived_extensions () at /home/jweil/gcc45/trunk/gcc/fortran/module.c:4019
#1  0x0000000000505938 in read_module () at /home/jweil/gcc45/trunk/gcc/fortran/module.c:4458
#2  0x0000000000507cd8 in gfc_use_module () at /home/jweil/gcc45/trunk/gcc/fortran/module.c:5508
#3  0x000000000050f666 in accept_statement (st=ST_USE) at /home/jweil/gcc45/trunk/gcc/fortran/parse.c:1525
#4  0x0000000000510c11 in parse_spec (st=ST_USE) at /home/jweil/gcc45/trunk/gcc/fortran/parse.c:2545
#5  0x0000000000512512 in parse_progunit (st=ST_NONE) at /home/jweil/gcc45/trunk/gcc/fortran/parse.c:3755
#6  0x0000000000512e92 in gfc_parse_file () at /home/jweil/gcc45/trunk/gcc/fortran/parse.c:4143
#7  0x00000000005534e3 in gfc_be_parse_file (set_yydebug=0) at /home/jweil/gcc45/trunk/gcc/fortran/f95-lang.c:239
#8  0x00000000009f8e96 in compile_file () at /home/jweil/gcc45/trunk/gcc/toplev.c:1049
#9  0x00000000009fb06b in do_compile () at /home/jweil/gcc45/trunk/gcc/toplev.c:2398
#10 0x00000000009fb141 in toplev_main (argc=2, argv=0x7fffffffe2c8) at /home/jweil/gcc45/trunk/gcc/toplev.c:2440
#11 0x00000000005d9374 in main (argc=2, argv=0x7fffffffe2c8) at /home/jweil/gcc45/trunk/gcc/main.c:35

i.e. the error happens in the module loading. I haven't looked at the details, but it seems this might be loosely related to PR41784.

Thanks for reporting.
Comment 2 janus 2009-12-11 15:54:55 UTC
Here is a patch which fixes the ICE:

Index: gcc/fortran/module.c
===================================================================
--- gcc/fortran/module.c        (revision 155160)
+++ gcc/fortran/module.c        (working copy)
@@ -4670,6 +4670,10 @@ write_equiv (void)
 static void
 write_dt_extensions (gfc_symtree *st)
 {
+  if (!gfc_check_access (st->n.sym->attr.access,
+                        st->n.sym->ns->default_access))
+    return;
+
   mio_lparen ();
   mio_pool_string (&st->n.sym->name);
   if (st->n.sym->module != NULL)
Comment 3 janus 2009-12-11 23:05:18 UTC
Subject: Bug 42257

Author: janus
Date: Fri Dec 11 23:05:02 2009
New Revision: 155183

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155183
Log:
gcc/fortran/
2009-12-11 Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42257
	* module.c (write_dt_extensions): Check for accessibility.

gcc/testsuite/
2009-12-11  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42257
	* gfortran.dg/extends_9.f03: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/extends_9.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/module.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 janus 2009-12-11 23:06:45 UTC
Fixed with r155183. Closing.