https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100651
Bug ID: 100651
Summary: Weird memory corruption with multiple triggers
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: matthew.thompson at nasa dot gov
Target Milestone: ---
Created attachment 50838
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50838&action=edit
Reproducing program
This is a bug that is tripped by GCC 9.3.0, 10.1.0, and 11.1.0 (at least, but I
only have access to those) on Linux and macOS. For the rest of this bug report,
I'll be using macOS (as it's my main workstation). First:
❯ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/Users/mathomp4/installed/Core/gcc-gfortran/11.1.0/libexec/gcc/x86_64-apple-darwin19.6.0/11.1.0/lto-wrapper
Target: x86_64-apple-darwin19.6.0
Configured with: ../gcc-11.1.0/configure
--prefix=/Users/mathomp4/installed/Core/gcc-gfortran/11.1.0
--enable-languages=c,c++,fortran
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.1.0 (GCC)
If you compile and run (NOTE: the -g -O0 is not necessary, I only use it to
make the traceback a bit better):
❯ gfortran -g -O0 opt_string.F90
❯ ./a.out
opt_string.F90 122 T
opt_string.F90 123 542594713
a.out(15473,0x1129d4e00) malloc: can't allocate region
:*** mach_vm_map(size=140733735985152, flags: 100) failed (error code=3)
a.out(15473,0x1129d4e00) malloc: *** set a breakpoint in malloc_error_break to
debug
Operating system error: Cannot allocate memory
Memory allocation failure in xrealloc
Error termination. Backtrace:
#0 0x103249de2 in ???
#1 0x10324aab5 in ???
#2 0x10324acb3 in ???
#3 0x10324939a in ???
#4 0x10347a455 in ???
#5 0x10346bb99 in ???
#6 0x1034740a7 in ???
#7 0x1034792be in ???
#8 0x10347a237 in ???
#9 0x103231c2d in __test_intnode_MOD_test_casting_fail
at /Users/mathomp4/F90Files/TomOptStringGCCBug/opt_string.F90:124
#10 0x103231c5c in MAIN__
at /Users/mathomp4/F90Files/TomOptStringGCCBug/opt_string.F90:135
#11 0x103231c98 in main
at /Users/mathomp4/F90Files/TomOptStringGCCBug/opt_string.F90:132
The (runtime) error disappears if *any* of the following 3 lines are commented
out/deleted:
* Line 31 (generic assignment)
* Line 85 (unused component of a derived type)
* Line 121 (unused local variable)
On Linux the output is:
$ ./a.out
opt_string.F90 122 T
opt_string.F90 123 -1431350024
Operating system error: Cannot allocate memory
Memory allocation failure in xrealloc
Error termination. Backtrace:
#0 0x2aaaaaf20a07 in write_character
at ../../../gcc-11.1.0/libgfortran/io/write.c:1416
#1 0x2aaaaaf25ba6 in list_formatted_write_scalar
at ../../../gcc-11.1.0/libgfortran/io/write.c:1900
#2 0x400cef in __test_intnode_MOD_test_casting_fail
at /home/mathomp4/F90Files/TomOptStringGCCBug/opt_string.F90:124
#3 0x400d1e in MAIN__
at /home/mathomp4/F90Files/TomOptStringGCCBug/opt_string.F90:135
#4 0x400d55 in main
at /home/mathomp4/F90Files/TomOptStringGCCBug/opt_string.F90:132