Bug 50227 - [4.7 Regression] [OOP] ICE-on-valid with allocatable class variable
Summary: [4.7 Regression] [OOP] ICE-on-valid with allocatable class variable
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2011-08-29 16:06 UTC by Andrew Benson
Modified: 2011-09-04 10:50 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-08-29 00:00:00


Attachments
Contains the files which constitute the test cases. (469 bytes, application/x-tar)
2011-08-29 16:06 UTC, Andrew Benson
Details
Further reduced test case from Janus Weil (354 bytes, application/x-tar)
2011-08-29 16:08 UTC, Andrew Benson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Benson 2011-08-29 16:06:03 UTC
Created attachment 25128 [details]
Contains the files which constitute the test cases.

The attached code causes an ICE with gfortran 4.7 r178129. Note that if I 
combine the code in the two files into a single file (as in the attached 
combined.F90), and compile that it works without any problem.

$ gfortran -v
Using built-in specs.
COLLECT_GCC=/usr/local/gcc-4.7/bin/gfortran
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.7/libexec/gcc/i686-pc-linux-
gnu/4.7.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.7/configure --prefix=/usr/local/gcc-4.7 --enable-
languages=c,c++,fortran --disable-multilib
Thread model: posix
gcc version 4.7.0 20110827 (experimental) (GCC)

$ gfortran -c module.F90 -o module.o

$ gfortran -c program.F90 -o program.o
program.F90: In function ‘test’:
program.F90:4:0: 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.

$ gfortran -c combined.F90  -o combined.o
Comment 1 Andrew Benson 2011-08-29 16:08:59 UTC
Created attachment 25129 [details]
Further reduced test case from Janus Weil

This is a further reduced test case created by Janus Weil.
Comment 2 Andrew Benson 2011-08-29 16:11:25 UTC
Original report on gfortran mailing list: http://gcc.gnu.org/ml/fortran/2011-08/msg00233.html
Comment 3 Dominique d'Humieres 2011-08-29 16:13:41 UTC
Confirmed as a 4.7 regression introduced after r171100 and before (or at) r171957 (r171654?).
Backtrace and analysis in http://gcc.gnu.org/ml/fortran/2011-08/msg00235.html .
Comment 4 janus 2011-08-29 16:26:39 UTC
(In reply to comment #3)
> (r171654?).

Rather not. This one only concerns type-bound procedures (of which Andrew's test case has none):

http://gcc.gnu.org/viewcvs?view=revision&revision=171654
Comment 5 Dominique d'Humieres 2011-08-29 17:07:55 UTC
Confirmed;-)
Comment 6 Dominique d'Humieres 2011-08-29 17:34:02 UTC
Why setting this pr as unconfirmed?
Comment 7 janus 2011-08-29 17:36:29 UTC
(In reply to comment #6)
> Why setting this pr as unconfirmed?

Oops. Did I do this? Sorry, it was not intentional ...
Comment 8 Dominique d'Humieres 2011-08-29 17:39:01 UTC
> Oops. Did I do this? Sorry, it was not intentional ...

Apparently this happens while changing the summary(?).
Comment 9 Dominique d'Humieres 2011-08-29 18:17:50 UTC
> > (r171654?).
>
> Rather not. This one only concerns type-bound procedures (of which Andrew's
> test case has none):

Sorry to be such a nuisance, but it is: r171653 works, r171654 crashes.
Comment 10 janus 2011-08-29 18:29:16 UTC
(In reply to comment #9)
> > > (r171654?).
> >
> > Rather not. This one only concerns type-bound procedures (of which Andrew's
> > test case has none):
> 
> Sorry to be such a nuisance, but it is: r171653 works, r171654 crashes.

Well, ok. If you say so :) Empirics beats intuition, I guess.

Also, you're not a nuisance at all. That's valuable information! Thanks for checking ...
Comment 11 janus 2011-08-29 19:28:42 UTC
Well, the obvious patch (based on Tobias' debugging) would be:


Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c   (revision 178253)
+++ gcc/fortran/trans-types.c   (working copy)
@@ -2109,7 +2109,8 @@ gfc_sym_type (gfc_symbol * sym)
     {
       /* We must use pointer types for potentially absent variables.  The
         optimizers assume a reference type argument is never NULL.  */
-      if (sym->attr.optional || sym->ns->proc_name->attr.entry_master)
+      if (sym->attr.optional
+         || (sym->ns->proc_name && sym->ns->proc_name->attr.entry_master))
        type = build_pointer_type (type);
       else
        {


And indeed it seems to fix the segfault. However, I still don't really see the connection to r171654.
Comment 12 janus 2011-08-30 17:09:22 UTC
(In reply to comment #11)
> And indeed it seems to fix the segfault.

... and regtests cleanly.


Unfortunately, there is one more complication: When compiling the two files from comment #1 one after the other, one gets a linker error:

> gfortran-4.7 -c module.f90
> gfortran-4.7 program.f90
/tmp/ccU0pMIF.o: In function `MAIN__':
program.f90:(.text+0x16): undefined reference to `__g_nodes_MOD___vtab_g_nodes_T0'
program.f90:(.text+0x87): undefined reference to `__g_nodes_MOD___vtab_g_nodes_T1'


Note: This seems to happen with trunk and 4.6, while it works with 4.5. I was hoping we had gotten rid of those for good (cf. e.g. PR44065 and PR45674).
Comment 13 Dominique d'Humieres 2011-08-30 17:24:31 UTC
> gfortran-4.7 -c module.f90
> gfortran-4.7 program.f90

What about
gfortran-4.7 program.f90 module.o?
AFAIK there is not "object" in the *.mod files.
Comment 14 janus 2011-08-31 11:28:41 UTC
(In reply to comment #13)
> > gfortran-4.7 -c module.f90
> > gfortran-4.7 program.f90
> 
> What about
> gfortran-4.7 program.f90 module.o?
> AFAIK there is not "object" in the *.mod files.

Of course. If I fail to include all object files in the linking process, I should not be too surprised about linker errors. Sorry about the noise, yesterday just wasn't my day :(
Comment 15 janus 2011-09-04 10:46:15 UTC
I should probably take this one. There was a patch posted at

http://gcc.gnu.org/ml/fortran/2011-09/msg00001.html

which I am about to commit.
Comment 16 janus 2011-09-04 10:49:18 UTC
Author: janus
Date: Sun Sep  4 10:49:13 2011
New Revision: 178509

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

	PR fortran/50227
	* trans-types.c (gfc_sym_type): Check for proc_name.

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

	PR fortran/50227
	* gfortran.dg/class_45a.f03: New.
	* gfortran.dg/class_45b.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_45a.f03
    trunk/gcc/testsuite/gfortran.dg/class_45b.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/testsuite/ChangeLog
Comment 17 janus 2011-09-04 10:50:22 UTC
Fixed with r178509. Closing.

Thanks for the report, Andrew!