The following code demonstrates that when optimization is turned on, the memory reference is being moved out of the loop. Thus, the volatile attribute is not being honored.
As a workaround (and perhaps better solution), the user could use a module instead of a common block. Gfortran works ok in the case of module variables. The below example is from x86 cygwin. But the same thing happens with x86_64 Linux on the current trunk. $ cat vol.f subroutine wait4it () implicit none logical event volatile event common /xyzzy/ event do if (event) exit end do end subroutine $ gfortran -O -S vol.f $ cat vol.s .file "vol.f" .text .globl _wait4it_ .def _wait4it_; .scl 2; .type 32; .endef _wait4it_: pushl %ebp movl %esp, %ebp cmpl $0, _xyzzy_ jne L4 L5: jmp L5 L4: popl %ebp ret .comm _xyzzy_, 16 # 4 $ $ gfortran --version GNU Fortran (GCC) 4.3.0 20071222 (experimental) [trunk revision 127783] Copyright (C) 2007 Free Software Foundation, Inc. GNU Fortran comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of GNU Fortran under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING $ -- Summary: VOLATILE attribute not being honored with common block variable Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: w6ws at earthlink dot net GCC build triplet: i686-pc-cygwin GCC host triplet: i686-pc-cygwin GCC target triplet: i686-pc-cygwin http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35037