As reported by Thomas Robitaille at http://gcc.gnu.org/ml/fortran/2009-10/msg00220.html the following code gives wrong-code (segfault/buserror) at run time with GCC 4.2/4.3/4.4/4.5. (4.1 does not support allocatable dummies.)
$ ./a.out in sub1 Bus error module test_module implicit none contains subroutine sub2(a) implicit none real,allocatable,intent(out),optional :: a(:) print *,'in sub2' end subroutine sub2 subroutine sub1(a) implicit none real,allocatable,intent(out),optional :: a(:) print *,'in sub1' call sub2(a) end subroutine sub1 end module test_module program test use test_module implicit none call sub1() end program The problem is that the argument can be "NULL" - and there is no check for the case "a == NULL"; i.e. the INTENT(OUT) autodeallocation block needs to be enclosed with a "if (a !=NULL)" as remarked by Dennis (http://gcc.gnu.org/ml/fortran/2009-10/msg00221.html). sub1 (a) { [...snip printing "in sub1" stuff...] { struct array1_real(kind=4) * D.555; if (a->data != 0B) { __builtin_free (a->data); } a->data = 0B; D.555 = a != 0B ? a : 0B; sub2 (D.555); } By the way the line "D.555 = a != 0B ? a : 0B;" is redundant - and also not nice because making the alias analysis for the middle end more difficult. -- Summary: Wong-code with optional allocatable arrays Product: gcc Version: 4.5.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: burnus at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41850