https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111853
Bug ID: 111853 Summary: f951: Segmentation fault at gfc_expression_rank Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: canu7 at yahoo dot es Target Milestone: --- I'm using the following gfortran version on Arch Linux: ``` Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.1 20230801 (GCC) ``` Here is the reduced code that causes the segmentation fault: ```Fortran TYPE vec_rect_2D_real_acc INTEGER arr END TYPE CLASS(vec_rect_2D_real_acc) rvec ASSOCIATE (arr=>rvec%arr) arr(arr*arr ``` This is the result of executing it directly with `f951`: ``` /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/f951 v.f90 f951: internal compiler error: Segmentation fault 0x1a0e9c4 internal_error(char const*, ...) ???:0 0x77d375 gfc_expression_rank(gfc_expr*) ???:0 0x7392fc gfc_match_expr(gfc_expr**) ???:0 0x6c224b gfc_match_array_ref(gfc_array_ref*, gfc_array_spec*, int, int) ???:0 0x7833e8 gfc_match_varspec(gfc_expr*, int, bool, bool) ???:0 0x7398e9 gfc_match(char const*, ...) ???:0 0x739eed gfc_match_assignment() ???:0 0x7938bc gfc_parse_file() ???:0 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See <https://bugs.archlinux.org/> for instructions. ``` This is the gdb backtrace on the segmentation fault: ``` ##0 0x000000000077d375 in gfc_expression_rank (e=0x2b61b10) at /usr/src/debug/gcc/gcc/gcc/fortran/resolve.cc:5643 #1 0x00000000006d6840 in gfc_op_rank_conformable (op2=0x2b61c50, op1=0x2b61b10) at /usr/src/debug/gcc/gcc/gcc/fortran/resolve.cc:5676 #2 eval_intrinsic (op=INTRINSIC_TIMES, eval=..., op1=0x2b61b10, op2=0x2b61c50) at /usr/src/debug/gcc/gcc/gcc/fortran/arith.cc:1674 #3 0x000000000074521f in gfc_multiply (op2=<optimized out>, op1=<optimized out>) at /usr/src/debug/gcc/gcc/gcc/fortran/arith.cc:1926 #4 match_add_operand (result=result@entry=0x7fffffffd550) at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:392 #5 0x000000000073884d in match_level_2 (result=result@entry=0x7fffffffd5a0) at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:480 #6 0x0000000000738a67 in match_level_3 (result=result@entry=0x7fffffffd608) at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:551 #7 0x0000000000738be5 in match_level_4 (result=<synthetic pointer>) at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:599 #8 match_and_operand (result=result@entry=0x7fffffffd680) at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:693 #9 0x0000000000738e97 in match_or_operand (result=result@entry=0x7fffffffd6e0) at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:722 #10 0x0000000000738fe7 in match_equiv_operand (result=result@entry=0x7fffffffd740) at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:765 #11 0x0000000000739139 in match_level_5 (result=result@entry=0x7fffffffd798) at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:811 #12 0x00000000007392fd in gfc_match_expr (result=0x2bbb460) at /usr/src/debug/gcc/gcc/gcc/fortran/matchexp.cc:870 #13 0x00000000006c1aac in match_subscript (ar=ar@entry=0x2bbb338, init=init@entry=0, match_star=match_star@entry=false) at /usr/src/debug/gcc/gcc/gcc/fortran/array.cc:94 #14 0x00000000006c224c in gfc_match_array_ref (ar=0x2bbb338, as=<optimized out>, init=0, corank=0) at /usr/src/debug/gcc/gcc/gcc/fortran/array.cc:211 #15 0x00000000007833e9 in gfc_match_varspec (primary=primary@entry=0x2b612f0, equiv_flag=equiv_flag@entry=0, sub_flag=sub_flag@entry=false, ppc_arg=ppc_arg@entry=false) at /usr/src/debug/gcc/gcc/gcc/fortran/primary.cc:2166 #16 0x0000000000785043 in match_variable (result=0x7fffffffdb40, equiv_flag=0, host_flag=<optimized out>) at /usr/src/debug/gcc/gcc/gcc/fortran/primary.cc:4149 #17 0x00000000007398ea in gfc_match_variable (equiv_flag=0, result=<optimized out>) at /usr/src/debug/gcc/gcc/gcc/fortran/primary.cc:4164 #18 gfc_match (target=target@entry=0x248a286 " %v =") at /usr/src/debug/gcc/gcc/gcc/fortran/match.cc:1143 #19 0x0000000000739eee in gfc_match_assignment () at /usr/src/debug/gcc/gcc/gcc/fortran/match.cc:1321 #20 0x0000000000762a94 in match_word (old_locus=0x7fffffffdba0, subr=0x739eb0 <gfc_match_assignment()>, str=0x0) at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:56 #21 decode_statement () at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:363 #22 0x000000000076f8c2 in next_free () at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:1406 #23 next_statement () at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:1638 #24 0x0000000000775825 in parse_executable (st=st@entry=ST_NONE) at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:5824 #25 0x0000000000773ff9 in parse_associate () at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:5058 #26 parse_executable (st=<optimized out>, st@entry=ST_ASSOCIATE) at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:5878 #27 0x0000000000773a4f in parse_progunit (st=ST_ASSOCIATE, st@entry=ST_DERIVED_DECL) at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:6294 #28 0x00000000007938bd in gfc_parse_file () at /usr/src/debug/gcc/gcc/gcc/fortran/parse.cc:6854 #29 0x00000000007ced05 in gfc_be_parse_file () at /usr/src/debug/gcc/gcc/gcc/fortran/f95-lang.cc:229 #30 0x0000000000d630c1 in compile_file () at /usr/src/debug/gcc/gcc/gcc/toplev.cc:444 #31 0x00000000006ad7fb in do_compile (no_backend=false) at /usr/src/debug/gcc/gcc/gcc/toplev.cc:2125 #32 toplev::main (this=<optimized out>, argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/gcc/gcc/gcc/toplev.cc:2277 #33 0x00000000006ae0e2 in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/gcc/gcc/gcc/main.cc:39 ``` And this is the line whre gdb reports the problem: ``` Program received signal SIGSEGV, Segmentation fault. 0x000000000077d375 in gfc_expression_rank (e=0x2b61b10) at /usr/src/debug/gcc/gcc/gcc/fortran/resolve.cc:5643 Downloading source file /usr/src/debug/gcc/gcc/gcc/fortran/resolve.cc 5643 rank = ref->u.ar.as->rank; ``` And finally, here is a Compiler Explorer link reproducing the bug: https://godbolt.org/z/W3q9ceWxP Hope is enough information to pin-point the problem.