https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87270
Bug ID: 87270 Summary: "FINAL" subroutine is called when compiled with "gfortran -O1", but not "gfortran -O0" Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: andrew at fluidgravity dot co.uk Target Milestone: --- Created attachment 44676 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44676&action=edit code.f90 Compile and the attached code with gfortran 8.1.0: > gfortran -O1 code.f90 && ./a.out main: check 1 create: check 1 create: check 2 main: check 2 cleanup: check 1 Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x10e293f3c #1 0x10e2932e3 #2 0x7fff670f4f59 #3 0x10e28bbe2 #4 0x10e28bddf #5 0x10e28c6f1 #6 0x10e28c7ad Segmentation fault: 11 The error does not occur if compiled without "-O1" or with "-O0". It also works with gfortran 7.3.1 Using "-O0", I get this: > gfortran -O0 test01.f90 && ./a.out main: check 1 create: check 1 create: check 2 main: check 2 create: check 1 create: check 2 main: check 3 So, the 'cleanup' function is called with one option, but not the other.