Bug 71688 - [4.9/5/6/7 Regression] ICE in analyze, at cgraphunit.c:632 with -fcoarray=lib
Summary: [4.9/5/6/7 Regression] ICE in analyze, at cgraphunit.c:632 with -fcoarray=lib
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 6.1.1
: P4 normal
Target Milestone: 4.9.4
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2016-06-28 18:43 UTC by Gerhard Steinmetz
Modified: 2016-07-20 15:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.5
Known to fail: 4.9.3, 5.4.0, 6.1.0, 7.0
Last reconfirmed: 2016-06-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerhard Steinmetz 2016-06-28 18:43:32 UTC
Aborting with gfortran-7-20160626, 6.1, 5.4, 4.9 :


$ cat z1.f90
program p
   call s
contains
   subroutine s
      real, save :: x[*]
      x = 2
      block
      end block
   end
end


$ gfortran-6 -fcoarray=single z1.f90
$ gfortran-6 -fcoarray=lib z1.f90
z1.f90:1:0:

 program p

internal compiler error: in analyze, at cgraphunit.c:632
Comment 1 Gerhard Steinmetz 2016-06-28 18:44:33 UTC
Modified a bit :


$ cat z2.f90
program p
   call s
contains
   subroutine s
      real :: x[*] = 1
      block
      end block
      x = 2
   end
end


$ gfortran-6 -fcoarray=lib z2.f90
z2.f90:1:0:

 program p

internal compiler error: in analyze, at cgraphunit.c:632
Comment 2 Martin Liška 2016-06-29 08:25:53 UTC
Confirmed, regression starts with GCC 4.9.0.

  4.7.0: running command with result: OK
  4.7.1: running command with result: OK
  4.7.2: running command with result: OK
  4.7.3: running command with result: OK
  4.7.4: running command with result: OK
  4.8.0: running command with result: OK
  4.8.1: running command with result: OK
  4.8.2: running command with result: OK
  4.8.3: running command with result: OK
  4.8.4: running command with result: OK
  4.8.5: running command with result: OK
  4.9.0: running command with result: FAILED
  4.9.1: running command with result: FAILED
  4.9.2: running command with result: FAILED
  4.9.3: running command with result: FAILED
  5.1.0: running command with result: FAILED
  5.2.0: running command with result: FAILED
  5.3.0: running command with result: FAILED
  6.1.0: running command with result: FAILED
Comment 3 Dominique d'Humieres 2016-06-29 08:57:02 UTC
> Confirmed, regression starts with GCC 4.9.0.
> ...

The change occurred between revisions r201266 (2013-07-26, OK) and r201631 (2013-08-09, ICE), likely r201526 (pr57987).
Comment 4 Martin Jambor 2016-06-29 13:42:17 UTC
(In reply to Dominique d'Humieres from comment #3)
> The change occurred between revisions r201266 (2013-07-26, OK) and r201631
> (2013-08-09, ICE), likely r201526 (pr57987).

Indeed.  But I believe the problem is that lower_nested_functions does
not work properly.  At the time of calling unnest_nesting_tree, the
nesting tree seems not to contain one nested function while another
one is present twice.
Comment 5 Martin Jambor 2016-06-29 14:16:39 UTC
The nesting tree structure contains decls but is built from call graph, in
which there are two different cgraph_nodes for a single decl (s).
Unnesting is done on call graph again but the translation from decls
to nodes of course misses a call graph node which remains to be nested
in the graph and that triggers the assert.

Fortran FE creates both of those cgraph_nodes.  The following
backtrace leads to creation of the first one:

#0  cgraph_node::create (decl=<function_decl 0x7ffff6a62500 s>) at /home/mjambor/gcc/icln/src/gcc/cgraph.c:495
#1  0x0000000000808b60 in cgraph_node::get_create (decl=<optimized out>) at /home/mjambor/gcc/icln/src/gcc/cgraph.c:529
#2  0x0000000000808d69 in cgraph_node::create (decl=decl@entry=<function_decl 0x7ffff6a62600 _caf_init.1>)
    at /home/mjambor/gcc/icln/src/gcc/cgraph.c:511
#3  0x00000000006f83ec in generate_coarray_init (ns=ns@entry=0x23d5720)
    at /home/mjambor/gcc/icln/src/gcc/fortran/trans-decl.c:5086
#4  0x00000000007097cd in gfc_generate_function_code (ns=ns@entry=0x23d5720)
    at /home/mjambor/gcc/icln/src/gcc/fortran/trans-decl.c:6109
#5  0x000000000070a381 in gfc_generate_contained_functions (parent=parent@entry=0x23d4d60)
    at /home/mjambor/gcc/icln/src/gcc/fortran/trans-decl.c:5161
#6  0x000000000070978e in gfc_generate_function_code (ns=0x23d4d60)
    at /home/mjambor/gcc/icln/src/gcc/fortran/trans-decl.c:6100
#7  0x00000000006dc511 in gfc_generate_code (ns=<optimized out>) at /home/mjambor/gcc/icln/src/gcc/fortran/trans.c:2006
#8  0x000000000068da1f in translate_all_program_units (gfc_global_ns_list=0x23d4d60)
    at /home/mjambor/gcc/icln/src/gcc/fortran/parse.c:5843
#9  0x000000000069426b in gfc_parse_file () at /home/mjambor/gcc/icln/src/gcc/fortran/parse.c:6049
#10 0x00000000006d3e44 in gfc_be_parse_file () at /home/mjambor/gcc/icln/src/gcc/fortran/f95-lang.c:201
#11 0x0000000000c9358d in compile_file () at /home/mjambor/gcc/icln/src/gcc/toplev.c:465
#12 0x0000000000c953b8 in do_compile () at /home/mjambor/gcc/icln/src/gcc/toplev.c:1998
#13 0x0000000000c955eb in toplev::main (this=this@entry=0x7fffffffde50, argc=argc@entry=14,

while the following one leads to creation of the second one:

#0  cgraph_node::create (decl=decl@entry=<function_decl 0x7ffff6a62500 s>)
    at /home/mjambor/gcc/icln/src/gcc/cgraph.c:495
#1  0x000000000070a2e1 in gfc_generate_function_code (ns=ns@entry=0x23d5720)
    at /home/mjambor/gcc/icln/src/gcc/fortran/trans-decl.c:6339
#2  0x000000000070a381 in gfc_generate_contained_functions (parent=parent@entry=0x23d4d60)
    at /home/mjambor/gcc/icln/src/gcc/fortran/trans-decl.c:5161
#3  0x000000000070978e in gfc_generate_function_code (ns=0x23d4d60)
    at /home/mjambor/gcc/icln/src/gcc/fortran/trans-decl.c:6100
#4  0x00000000006dc511 in gfc_generate_code (ns=<optimized out>) at /home/mjambor/gcc/icln/src/gcc/fortran/trans.c:2006
#5  0x000000000068da1f in translate_all_program_units (gfc_global_ns_list=0x23d4d60)
    at /home/mjambor/gcc/icln/src/gcc/fortran/parse.c:5843
#6  0x000000000069426b in gfc_parse_file () at /home/mjambor/gcc/icln/src/gcc/fortran/parse.c:6049
#7  0x00000000006d3e44 in gfc_be_parse_file () at /home/mjambor/gcc/icln/src/gcc/fortran/f95-lang.c:201
#8  0x0000000000c9358d in compile_file () at /home/mjambor/gcc/icln/src/gcc/toplev.c:465
#9  0x0000000000c953b8 in do_compile () at /home/mjambor/gcc/icln/src/gcc/toplev.c:1998
#10 0x0000000000c955eb in toplev::main (this=this@entry=0x7fffffffde50, argc=argc@entry=14,

The following seems to be an obvious fix:

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 2f5e434..0e68736 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -6336,7 +6336,7 @@ gfc_generate_function_code (gfc_namespace * ns)
         function has already called cgraph_create_node, which also created
         the cgraph node for this function.  */
       if (!has_coarray_vars || flag_coarray != GFC_FCOARRAY_LIB)
-       (void) cgraph_node::create (fndecl);
+       (void) cgraph_node::get_create (fndecl);
     }
   else
     cgraph_node::finalize_function (fndecl, true);
Comment 6 Martin Jambor 2016-06-30 12:18:23 UTC
I have proposed the above fix on the mailing list:

https://gcc.gnu.org/ml/gcc-patches/2016-06/msg02038.html
Comment 7 Martin Jambor 2016-07-19 15:41:15 UTC
Author: jamborm
Date: Tue Jul 19 15:40:43 2016
New Revision: 238476

URL: https://gcc.gnu.org/viewcvs?rev=238476&root=gcc&view=rev
Log:
Fix PR fortran/71688

2016-07-19  Martin Jambor  <mjambor@suse.cz>

        PR fortran/71688
        * trans-decl.c (gfc_generate_function_code): Use cgraph_get_create_node
        rather than cgraph_create_node to get a call graph node.

testsuite/
        gfortran.dg/pr71688.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/pr71688.f90
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 8 Martin Jambor 2016-07-19 15:45:29 UTC
Author: jamborm
Date: Tue Jul 19 15:44:56 2016
New Revision: 238477

URL: https://gcc.gnu.org/viewcvs?rev=238477&root=gcc&view=rev
Log:
Fix PR fortran/71688

2016-07-19  Martin Jambor  <mjambor@suse.cz>

        PR fortran/71688
        * trans-decl.c (gfc_generate_function_code): Use cgraph_get_create_node
        rather than cgraph_create_node to get a call graph node.

testsuite/
        * gfortran.dg/pr71688.f90: New test.



Added:
    branches/gcc-4_9-branch/gcc/testsuite/gfortran.dg/pr71688.f90
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/fortran/trans-decl.c
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
Comment 9 Martin Jambor 2016-07-20 13:24:54 UTC
Author: jamborm
Date: Wed Jul 20 13:24:19 2016
New Revision: 238515

URL: https://gcc.gnu.org/viewcvs?rev=238515&root=gcc&view=rev
Log:
Fix PR fortran/71688

2016-07-20  Martin Jambor  <mjambor@suse.cz>

        PR fortran/71688
        * trans-decl.c (gfc_generate_function_code): Use get_create rather
        than create to get a call graph node.

testsuite/
        gfortran.dg/pr71688.f90: New test.


Added:
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/pr71688.f90
Modified:
    branches/gcc-6-branch/gcc/ChangeLog
    branches/gcc-6-branch/gcc/fortran/trans-decl.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 10 Martin Jambor 2016-07-20 13:31:51 UTC
Author: jamborm
Date: Wed Jul 20 13:31:19 2016
New Revision: 238516

URL: https://gcc.gnu.org/viewcvs?rev=238516&root=gcc&view=rev
Log:
Fix PR fortran/71688

2016-07-20  Martin Jambor  <mjambor@suse.cz>

        PR fortran/71688
        * trans-decl.c (gfc_generate_function_code): Use get_create rather
        than create to get a call graph node.

testsuite/
        * gfortran.dg/pr71688.f90: New test.


Added:
    branches/gcc-5-branch/gcc/testsuite/gfortran.dg/pr71688.f90
Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/fortran/trans-decl.c
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
Comment 11 Martin Jambor 2016-07-20 15:35:04 UTC
Fixed on all active branches.