Created attachment 45534 [details] Fortran 90 file that produces an internal compiler error on cygwin Compilation of the attached file on 64-bit cygwin (on 64-bit Windows 10) produces only the .mod and .s files together with the first output below. Compilation of the same file using the Mingw-w64 cross-compiler produces the .o file in addition to the .s and .mod files, together with the second output below. How would I go about debugging this? --- $ x86_64-pc-cygwin-gfortran -v -c test_compile.f90 -save-temps -fverbose-asm -Wall -Wextra Using built-in specs. COLLECT_GCC=x86_64-pc-cygwin-gfortran Target: x86_64-pc-cygwin Configured with: /cygdrive/i/szsz/tmpp/gcc/gcc-7.4.0-1.x86_64/src/gcc-7.4.0/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-7.4.0-1.x86_64/src/gcc-7.4.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libcilkrts --enable-libgomp --enable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --enable-libada --disable-symvers --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts Thread model: posix gcc version 7.4.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-c' '-save-temps' '-fverbose-asm' '-Wall' '-Wextra' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/f951.exe test_compile.f90 -quiet -dumpbase test_compile.f90 -mtune=generic -march=x86-64 -auxbase test_compile -Wall -Wextra -version -fverbose-asm -fintrinsic-modules-path /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/finclude -o test_compile.s GNU Fortran (GCC) version 7.4.0 (x86_64-pc-cygwin) compiled by GNU C version 7.4.0, GMP version 6.1.2, MPFR version 4.0.1-p11, MPC version 1.1.0, isl version isl-0.16.1-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU Fortran2008 (GCC) version 7.4.0 (x86_64-pc-cygwin) compiled by GNU C version 7.4.0, GMP version 6.1.2, MPFR version 4.0.1-p11, MPC version 1.1.0, isl version isl-0.16.1-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 f951: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See <https://gcc.gnu.org/bugs/> for instructions. --- The output from the cross-compiler, which does run to completion, is included below: --- $ x86_64-w64-mingw32-gfortran -v -c test_compile.f90 -save-temps -fverbose-asm -Wall -Wextra Using built-in specs. COLLECT_GCC=x86_64-w64-mingw32-gfortran Target: x86_64-w64-mingw32 Configured with: /cygdrive/i/szsz/tmpp/cygwin64/mingw64-x86_64/mingw64-x86_64-gcc-7.4.0-1.x86_64/src/gcc-7.4.0/configure --srcdir=/cygdrive/i/szsz/tmpp/cygwin64/mingw64-x86_64/mingw64-x86_64-gcc-7.4.0-1.x86_64/src/gcc-7.4.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/mingw64-x86_64-gcc --htmldir=/usr/share/doc/mingw64-x86_64-gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-w64-mingw32 --without-libiconv-prefix --without-libintl-prefix --with-sysroot=/usr/x86_64-w64-mingw32/sys-root --with-build-sysroot=/usr/x86_64-w64-mingw32/sys-root --disable-multilib --disable-win32-registry --enable-languages=c,c++,fortran,lto,objc,obj-c++ --enable-fully-dynamic-string --enable-graphite --enable-libgomp --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-version-specific-runtime-libs --enable-libgomp --enable-libada --with-dwarf2 --with-gnu-ld --with-gnu-as --with-tune=generic --with-cloog-include=/usr/include/cloog-isl --with-system-zlib --enable-threads=posix --libexecdir=/usr/lib Thread model: posix gcc version 7.4.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-c' '-save-temps' '-fverbose-asm' '-Wall' '-Wextra' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-w64-mingw32/7.4.0/f951.exe test_compile.f90 -quiet -dumpbase test_compile.f90 -mtune=generic -march=x86-64 -auxbase test_compile -Wall -Wextra -version -fverbose-asm -fintrinsic-modules-path /usr/lib/gcc/x86_64-w64-mingw32/7.4.0/finclude -o test_compile.s GNU Fortran (GCC) version 7.4.0 (x86_64-w64-mingw32) compiled by GNU C version 7.4.0, GMP version 6.1.2, MPFR version 4.0.1-p11, MPC version 1.1.0, isl version isl-0.16.1-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU Fortran2008 (GCC) version 7.4.0 (x86_64-w64-mingw32) compiled by GNU C version 7.4.0, GMP version 6.1.2, MPFR version 4.0.1-p11, MPC version 1.1.0, isl version isl-0.16.1-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 COLLECT_GCC_OPTIONS='-v' '-c' '-save-temps' '-fverbose-asm' '-Wall' '-Wextra' '-mtune=generic' '-march=x86-64' /usr/lib/gcc/x86_64-w64-mingw32/7.4.0/../../../../x86_64-w64-mingw32/bin/as.exe -v -o test_compile.o test_compile.s GNU assembler version 2.31.1 (x86_64-w64-mingw32) using BFD version (GNU Binutils) 2.31.1 COMPILER_PATH=/usr/lib/gcc/x86_64-w64-mingw32/7.4.0/:/usr/lib/gcc/x86_64-w64-mingw32/7.4.0/:/usr/lib/gcc/x86_64-w64-mingw32/:/usr/lib/gcc/x86_64-w64-mingw32/7.4.0/:/usr/lib/gcc/x86_64-w64-mingw32/:/usr/lib/gcc/x86_64-w64-mingw32/7.4.0/../../../../x86_64-w64-mingw32/bin/ LIBRARY_PATH=/usr/lib/gcc/x86_64-w64-mingw32/7.4.0/:/usr/lib/gcc/x86_64-w64-mingw32/7.4.0/../../../../x86_64-w64-mingw32/lib/../lib/:/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/:/usr/lib/gcc/x86_64-w64-mingw32/7.4.0/../../../../x86_64-w64-mingw32/lib/:/usr/x86_64-w64-mingw32/sys-root/mingw/lib/ COLLECT_GCC_OPTIONS='-v' '-c' '-save-temps' '-fverbose-asm' '-Wall' '-Wextra' '-mtune=generic' '-march=x86-64' ---
WORKSFORME on darwin. Can you debug the ICE?
Running gfortran with "-wrapper gdb,--args" notes the segfault with: --- Thread 1 "f951" received signal SIGSEGV, Segmentation fault. 0x00000001004fcf20 in build_common_decl (is_init=false, union_type=<optimized out>, com=0x60013e1f0) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/trans-common.c:463 463 attributes = gfc_add_attributes_to_decl (com->head->attr, NULL_TREE); --- Running "bt full" produces --- #0 0x00000001004fcf20 in build_common_decl (is_init=false, union_type=<optimized out>, com=0x60013e1f0) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/trans-common.c:463 attributes = <optimized out> decl = 0x6fffff00ab0 identifier = 0x6ffffbd4a60 decl = <optimized out> identifier = <optimized out> size = <optimized out> attributes = <optimized out> field = <optimized out> #1 create_common (com=com@entry=0x60013e1f0, head=<optimized out>, saw_equiv=saw_equiv@entry=true) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/trans-common.c:672 s = <optimized out> next_s = <optimized out> union_type = <optimized out> field_link = <optimized out> field = <optimized out> field_init = <optimized out> rli = <optimized out> decl = <optimized out> is_init = <optimized out> is_saved = <optimized out> __FUNCTION__ = "create_common" #2 0x00000001004fd800 in finish_equivalences (ns=0x600128a00) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/trans-common.c:1270 y = <optimized out> sym = <optimized out> c = 0x60013e1f0 align = 4 z = 0x60013d510 offset = <optimized out> dummy = true z = <optimized out> y = <optimized out> sym = <optimized out> c = <optimized out> offset = <optimized out> align = <optimized out> dummy = <optimized out> #3 gfc_trans_common (ns=ns@entry=0x600128a00) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/trans-common.c:1307 c = <optimized out> #4 0x000000010050c3a0 in gfc_generate_module_vars (ns=ns@entry=0x600128a00) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/trans-decl.c:5287 __FUNCTION__ = "gfc_generate_module_vars" #5 0x00000001004e6adf in gfc_generate_module_code (ns=0x600128a00) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/trans.c:2176 n = <optimized out> entry = 0x6fffff49780 __FUNCTION__ = "gfc_generate_module_code" #6 0x00000001004982c2 in translate_all_program_units (gfc_global_ns_list=<optimized out>) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/parse.c:6062 errors = 0 errors = <optimized out> ns = <optimized out> #7 gfc_parse_file () at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/parse.c:6275 seen_program = <optimized out> errors_before = 0 errors = 0 top = {state = COMP_NONE, sym = 0x0, do_variable = 0x0, construct = 0x0, head = 0x0, tail = 0x0, previous = 0x0, ext = {end_do_label = 0xffffcb94, oacc_declare_clauses = 0xffffcb94}} s = {state = COMP_MODULE, sym = 0x6001293b0, do_variable = 0x0, construct = 0x0, head = 0x0, tail = 0x0, previous = 0xffffc7b0, ext = {end_do_label = 0x0, oacc_declare_clauses = 0x0}} st = <optimized out> prog_locus = {nextc = 0xffffca46, lb = 0xffffcb94} next = <optimized out> #8 0x00000001004df32b in gfc_be_parse_file () at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/f95-lang.c:204 No locals. #9 0x00000001008fd8ac in compile_file () at /usr/src/debug/gcc-7.4.0-1/gcc/toplev.c:467 No locals. #10 0x00000001010e7b8d in do_compile () at /usr/src/debug/gcc-7.4.0-1/gcc/toplev.c:2003 i = 1 #11 toplev::main (this=this@entry=0xffffca46, argc=<optimized out>, argc@entry=17, argv=<optimized out>, argv@entry=0xffffcac0) at /usr/src/debug/gcc-7.4.0-1/gcc/toplev.c:2138 __FUNCTION__ = "main" #12 0x0000000101107545 in main (argc=17, argv=0xffffcac0) at /usr/src/debug/gcc-7.4.0-1/gcc/main.c:39 toplev = {m_use_TV_TOTAL = true, m_init_signals = true} --- I also ran "info locals", which printed: toplev = {m_use_TV_TOTAL = true, m_init_signals = true} What other information would help narrow this down? I've exhausted my current knowledge of gcc and gdb.
The line it's stuck on seems to be: #0 0x00000001004fcf20 in build_common_decl (is_init=false, union_type=<optimized out>, com=0x60013e1f0) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/trans-common.c:463 463 attributes = gfc_add_attributes_to_decl (com->head->attr, NULL_TREE); Printing the value of "com->head" gives 0x0, which would cause the segfault. Two frames up seems to be the last time com->head gets touched, in "gfc_get_common_head", which is a macro expanding to "XCNEW (gfc_common_head)", which is a macro expanding to "((gfc_common_head *) xcalloc (1, sizeof (gfc_common_head)))". xcalloc just allocates and zeros memory, so that's not it. The Mingw-w64 compiler does not hit this problem because it returns on line 423. There's enough optimization to make it tricky to narrow down farther. Going back to the Cygwin compiler, I hit the error and check the conditions for the exit used by the Mingw-w64 compiler: --- (gdb) print is_init $2 = false (gdb) print decl $3 = (tree) 0x6fffff00ab0 --- Since the condition is ((decl != NULL_TREE) && (!is_init || ...)), I think the exit should have been taken here as well. This suggests that the issue is not with the equivalence-in-module code. I downloaded the old 7.3.0 binaries and checked again, to find the problem does not occur in that version. I then installed the 7.4.0 binaries and found the error still in place. I will check for more help on the cygwin list.
The line that the cygwin-native compiler crashes on: attributes = gfc_add_attributes_to_decl (com->head->attr, NULL_TREE); is not present in the Mingw-w64 cross compiler. Side-by-side debugging sessions reveal control flow through the two versions of build_common_decl are almost identical up to that point, except the cygwin-native compiler executes a line like TREE_PUBLIC (decl) = 1; which is not present in the Mingw-w64 execution. I asked for clarification on why the attributes line was there on the cygwin list.
> The line it's stuck on seems to be: > #0 0x00000001004fcf20 in build_common_decl (is_init=false, union_type=<optimized out>, com=0x60013e1f0) at /usr/src/debug/gcc-7.4.0-1/gcc/fortran/trans-common.c:463 > 463 attributes = gfc_add_attributes_to_decl (com->head->attr, NULL_TREE); I don't see such a line in my gcc sources.
OK, I think I have this figured out. What you are seeing is a result of a patch that has been applied to Cygwin, but not to the main gfortran sources. So, it is out of our scope. Specifically, this look like the patch in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47030 which was proposed (but not formally submitted) to the gfortran mailing list at https://gcc.gnu.org/ml/fortran/2018-11/msg00015.html . It was mentioned in https://gcc.gnu.org/ml/fortran/2019-01/msg00037.html that an earlier version of this patch had already been applied in Cygwin. So, I am closing this as a duplicate of 47030. We can then discuss there how to avoid this problem. *** This bug has been marked as a duplicate of bug 47030 ***
Thank you. I will follow the progress where you indicated.