https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92208
Bug ID: 92208 Summary: internal compile error, character array of dynamic length returned from function and passed to subroutine Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: nils.reiche at dlr dot de Target Milestone: --- Description: A function creates and return an array of characters of a certain length that is allocated at the call of the function. When the returned array is not passed to any other function, the code compiles and runs perfectly. But passing this character array to another subroutine causes an internal compiler error. Attached is the source code of the test program. It has been working for compiler versions gcc-5.2 and gcc-8.2, others were not tested. Source code: program stringtest implicit none integer, parameter :: noVars = 2 print*, "varNames: ", createVarnames("var",noVars) call function1(noVars,createVarnames("var",noVars),"path") contains function createVarnames(string,noVars) result(stringArray) implicit none character(len=*), intent(in) :: string integer, intent(in) :: noVars character(len=len_trim(string)+6), dimension(noVars) :: stringArray integer :: i do i=1,noVars write(stringArray(i),'(a,i0)') string, i enddo end function createVarnames subroutine function1(noVars,varNames,path) implicit none integer, intent(in) :: noVars character(len=*), intent(in) :: path character(len=*), dimension(noVars) :: varNames print*, "function1-path : ", trim(path) print*, "function1-varNames: ", varNames end subroutine function1 end program stringtest Compiler specifications: gfortran -v Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/home_as/ta/moes_mc/software_rhel7/compilers/gcc-9.2.0-install/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-9.2.0/configure --prefix=/home_as/ta/moes_mc/software_rhel7/compilers/gcc-9.2.0-install --enable-threads Thread model: posix gcc version 9.2.0 (GCC) Compiler error message: gfortran -Wall -Wextra string_test.F90 string_test.F90:1:0: 1 | program stringtest | internal compiler error: ..__result from createvarnames referenced in stringtest 0xbbac19 convert_nonlocal_reference_op ../../gcc-9.2.0/gcc/tree-nested.c:1053 0xd84882 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*)) ../../gcc-9.2.0/gcc/tree.c:12151 0x909619 walk_gimple_op(gimple*, tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) ../../gcc-9.2.0/gcc/gimple-walk.c:253 0x9099f1 walk_gimple_stmt(gimple_stmt_iterator*, tree_node* (*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) ../../gcc-9.2.0/gcc/gimple-walk.c:586 0x909b30 walk_gimple_seq_mod(gimple**, tree_node* (*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) ../../gcc-9.2.0/gcc/gimple-walk.c:51 0x909ab1 walk_gimple_stmt(gimple_stmt_iterator*, tree_node* (*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) ../../gcc-9.2.0/gcc/gimple-walk.c:631 0x909b30 walk_gimple_seq_mod(gimple**, tree_node* (*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) ../../gcc-9.2.0/gcc/gimple-walk.c:51 0x909a71 walk_gimple_stmt(gimple_stmt_iterator*, tree_node* (*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) ../../gcc-9.2.0/gcc/gimple-walk.c:675 0x909b30 walk_gimple_seq_mod(gimple**, tree_node* (*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) ../../gcc-9.2.0/gcc/gimple-walk.c:51 0x909a71 walk_gimple_stmt(gimple_stmt_iterator*, tree_node* (*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) ../../gcc-9.2.0/gcc/gimple-walk.c:675 0x909b30 walk_gimple_seq_mod(gimple**, tree_node* (*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) ../../gcc-9.2.0/gcc/gimple-walk.c:51 0xbb8708 walk_body ../../gcc-9.2.0/gcc/tree-nested.c:703 0xbb8ee0 walk_function ../../gcc-9.2.0/gcc/tree-nested.c:714 0xbb8ee0 walk_all_functions ../../gcc-9.2.0/gcc/tree-nested.c:779 0xbbbe0c lower_nested_functions(tree_node*) ../../gcc-9.2.0/gcc/tree-nested.c:3507 0x7cae9c cgraph_node::analyze() ../../gcc-9.2.0/gcc/cgraphunit.c:673 0x7cd4d7 analyze_functions ../../gcc-9.2.0/gcc/cgraphunit.c:1126 0x7ce0c2 symbol_table::finalize_compilation_unit() ../../gcc-9.2.0/gcc/cgraphunit.c:2837 Please submit a full bug report,