https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100551
Bug ID: 100551 Summary: [11/12 Regression] Passing return value of intrinsic to class(*) dummy argument can cause segfaults Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: bugs at colin dot moe Target Milestone: --- Created attachment 50794 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50794&action=edit Minimum working example that induces the error. When passing the return value of an intrinsic function (and possibly other temporaries) into a function with a class(*) dummy argument, the resulting code will generate a segfault in GCC 11.1 and newer. 10.2 and earlier (as early as 4.8.5 tested) worked correctly. Minimum working example attached. GCC Version (latest tested): Target: x86_64-pc-linux-gnu Configured with: ../configure --disable-multilib --enable-languages=c,c++,fortran --with-system-zlib --prefix=[]/gcc-12.0 gcc version 12.0.0 20210511 (experimental) (GCC) Command line: gfortran -Wall -Wextra mwe.f90 ./a.out Output: Compiler builds with no issues. In GCC 4.8.5, 9.3.0, 10.2.0, the program output is: 15 In 11.1.0 and 12.0 (tested against master branch for 12.0): Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x7f6e7a218f7f in ??? #1 0x401323 in __testmod_MOD_test at []/mwe.f90:15 #2 0x4015b2 in testprogram at []/mwe.f90:26 #3 0x40165b in main at []/mwe.f90:18 [1] 626265 segmentation fault (core dumped) ./a.out Output with -fsanitize=undefined: mwe.f90:15:10: runtime error: member access within misaligned address 0x7ffc6198b024 for type 'struct __class__STAR_t', which requires 8 byte alignment 0x7ffc6198b024: note: pointer points here 60 49 30 ef 0f 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 ^