[Bug fortran/71688] [4.9/5/6/7 Regression] ICE in analyze, at cgraphunit.c:632 with -fcoarray=lib

jamborm at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jun 29 14:16:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71688

--- Comment #5 from Martin Jambor <jamborm at gcc dot gnu.org> ---
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);


More information about the Gcc-bugs mailing list