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

            Bug ID: 67760
           Summary: ICE on contained subroutine in function modifying
                    function return value
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thomas.or...@uni-hamburg.de
  Target Milestone: ---
              Host: x86_64-unknown-linux-gnu

Created attachment 36414
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36414&action=edit
example code triggering the ICE

I get a reliable gfortran internal compiler error with all versions I tried so
far (version 5.1.0 picked as the one where the installation reports a backtrace 
that may be useful).

In my tests this affects gcc-4.8.3 (CentOS), gcc-4.1.2 (SLES) and
self-compiled vanilla gcc 4.9.2, 5.1.0, 5.2.0 . I therefore conclude that it
probably still is there in more current/upcoming releases.

The culprit is a contained subroutine inside a function that is accessing the 
return value of that function through the functions's name:

function fancy()
   !integer :: fancy      ! both gcc and icc happy
   !integer :: fancy(4)   ! gcc crash, icc depends on more_fancy
   integer :: fancy(3,2) ! gcc crash, icc depends on more_fancy

   call more_fancy

contains

subroutine more_fancy

   fancy = 42  ! Fine, generally.
   !fancy(:) = 42   ! icc giving error about substring
   !fancy(:,:) = 42 ! icc giving error about function name conflict
end subroutine

end function

I am not really sure what the standard says about this, especially since this 
works for a scalar return value for both gcc and the Intel compiler, and also
for an array if the first assignment in more_fancy is used. For a non-recursive
function, I actually don't see any problem when one considers the code of the
contained subroutine still being in the scope of the function.

But anyhow: At least an error should be produced instead of the compiler 
crashing. Example from gcc-5.1.0:

$ LANG=C gfortran -Wall -Wextra -o gfortran-ice gfortran-ice.f90 
gfortran-ice.f90:16:0:

 function fancy()
 ^
internal compiler error: Segmentation fault
0x90c276 crash_signal
        /usr/src/gcc-5.1.0/gcc/toplev.c:383
0x2b47551271ef ???
       
/usr/src/glibc-2.21/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0x97bd0a get_frame_type
        /usr/src/gcc-5.1.0/gcc/tree-nested.c:263
0x97bd0a get_chain_decl
        /usr/src/gcc-5.1.0/gcc/tree-nested.c:369
0x97e2ea get_chain_decl
        /usr/src/gcc-5.1.0/gcc/tree-nested.c:875
0x97e2ea get_nonlocal_debug_decl
        /usr/src/gcc-5.1.0/gcc/tree-nested.c:880
0x97e408 convert_nonlocal_reference_op
        /usr/src/gcc-5.1.0/gcc/tree-nested.c:958
0xaff4e4 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, default_hashset_traits>*, tree_node*
(*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*,
hash_set<tree_node*, default_hashset_traits>*))
        /usr/src/gcc-5.1.0/gcc/tree.c:11093
0x74f66c walk_gimple_op(gimple_statement_base*, tree_node* (*)(tree_node**,
int*, void*), walk_stmt_info*)
        /usr/src/gcc-5.1.0/gcc/gimple-walk.c:235
0x74f8d4 walk_gimple_stmt(gimple_stmt_iterator*, tree_node*
(*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**,
int*, void*), walk_stmt_info*)
        /usr/src/gcc-5.1.0/gcc/gimple-walk.c:575
0x74fab0 walk_gimple_seq_mod(gimple_statement_base**, tree_node*
(*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**,
int*, void*), walk_stmt_info*)
        /usr/src/gcc-5.1.0/gcc/gimple-walk.c:72
0x74f992 walk_gimple_stmt(gimple_stmt_iterator*, tree_node*
(*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**,
int*, void*), walk_stmt_info*)
        /usr/src/gcc-5.1.0/gcc/gimple-walk.c:585
0x74fab0 walk_gimple_seq_mod(gimple_statement_base**, tree_node*
(*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**,
int*, void*), walk_stmt_info*)
        /usr/src/gcc-5.1.0/gcc/gimple-walk.c:72
0x74f992 walk_gimple_stmt(gimple_stmt_iterator*, tree_node*
(*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**,
int*, void*), walk_stmt_info*)
        /usr/src/gcc-5.1.0/gcc/gimple-walk.c:585
0x74fab0 walk_gimple_seq_mod(gimple_statement_base**, tree_node*
(*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**,
int*, void*), walk_stmt_info*)
        /usr/src/gcc-5.1.0/gcc/gimple-walk.c:72
0x97b7b1 walk_body
        /usr/src/gcc-5.1.0/gcc/tree-nested.c:628
0x97ba5e walk_function
        /usr/src/gcc-5.1.0/gcc/tree-nested.c:639
0x97ba5e walk_all_functions
        /usr/src/gcc-5.1.0/gcc/tree-nested.c:704
0x97d2c7 lower_nested_functions(tree_node*)
        /usr/src/gcc-5.1.0/gcc/tree-nested.c:3008
0x608d7b cgraph_node::analyze()
        /usr/src/gcc-5.1.0/gcc/cgraphunit.c:640
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.


For gcc-5.2.0 on another machine, I just get 

gfortran-ice.f90: In function 'fancy':
gfortran-ice.f90:16:0: internal compiler error: Segmentation fault
 function fancy()
 ^
Please submit a full bug report,

All versions down to SuSE's gcc-4.1.2 have some variant of ICE.

Reply via email to