http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57296
Bug ID: 57296 Summary: Infinite loop in do while when using -O2 Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: antti.pekka.hynninen at nrel dot gov Created attachment 30125 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30125&action=edit Source code that produces the infinite loop Gfortran produces an infinite "do while" loop for a very simple code: DO I=1,LENIC PREF(I)=PIC(I) DO WHILE(PREF(I) < -180.0d0) PREF(I)=PREF(I)+360.0d0 ENDDO ENDDO This compiles to something like L10: movsd (%rbx,%rdx), %xmm0 ucomisd %xmm0, %xmm1 movsd %xmm0, (%rax,%rdx) jbe L18 L8: jmp L8 .align 4 L18: addq $8, %rdx cmpq $800, %rdx jne L10 Note that this only happens when pref is allocated using a subroutine: subroutine chmalloc(len, p) integer len real(kind=8), allocatable, dimension(:) :: p allocate(p(len)) return end subroutine chmalloc If I instead use "allocate(pref(lenic))" directly, code works again. I have added the source code as an attachment, compile with "gfortran -O2 test.f90". My system is Mac OSX 10.6.8.