The following code is miscompiled at -O3 with trunk and 4.5.0:
! From forall_12.f90 ! Fails with loop reversal at -O3 ! character(len=1) :: b(4) = (/"1","2","3","4"/), c(4) c = b i = 1 ! This statement must be here for the abort below b(1:3)(i:i) = b(2:4)(i:i) b = c b(4:2:-1)(i:i) = b(3:1:-1)(i:i) ! This fails. If the condition is printed, the result is F F F F if (any (b .ne. (/"1","1","2","3"/))) i = 2 print *, b print *, b .ne. (/"1","1","2","3"/) if (i == 2) call abort end [macbook] f90/bug% gfc -O3 forall_12_db.f90 [macbook] f90/bug% a.out 1123 F F F F Abort Abort is not called if the test 'if (any ...' is replaced with if (any (b .ne. (/"1","1","2","4"/))) i = 2 As spotted by Tobias Burnus, the problem comes from ... static character(kind=1)[1:1] * A.5[4] = {&"1"[1]{lb: 1 sz: 1}, &"1"[1]{lb: 1 sz: 1}, &"2"[1]{lb: 1 sz: 1}, &"3"[1]{lb: 1 sz: 1}}; ... <bb 5>: D.1645_85 = A.5[3]; D.1646_86 = (*D.1645_85)[1]{lb: 1 sz: 1}; if (D.1646_86 != D.1596_154) goto <bb 7>; else goto <bb 6>; <bb 6>: ... -- Summary: [4.5/4.6 Regression] wrong code at -O3 Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dominiq at lps dot ens dot fr http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44592