http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54608
Bug #: 54608 Summary: Wrong-code with SCAN and VERIFY Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: bur...@gcc.gnu.org Reported by James Van Buskirk in https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.fortran/5eAz5ns6AG0 Simplifing SCAN and VERIFY doesn't properly take the BACK= argument into account if it is not constant. Solution: Do the same as for INDEX, namely: --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -5249,3 +5249,4 @@ gfc_simplify_scan (gfc_expr *e, gfc_expr *c, gfc_expr *b, gfc_expr *kind) - if (e->expr_type != EXPR_CONSTANT || c->expr_type != EXPR_CONSTANT) + if (e->expr_type != EXPR_CONSTANT || c->expr_type != EXPR_CONSTANT + || ( b != NULL && b->expr_type != EXPR_CONSTANT)) return NULL; @@ -6337,3 +6338,4 @@ gfc_simplify_verify (gfc_expr *s, gfc_expr *set, gfc_expr *b, gfc_expr *kind) - if (s->expr_type != EXPR_CONSTANT || set->expr_type != EXPR_CONSTANT) + if (s->expr_type != EXPR_CONSTANT || set->expr_type != EXPR_CONSTANT + || ( b != NULL && b->expr_type != EXPR_CONSTANT)) return NULL; Test case (should print ".true."): module m1 implicit none contains subroutine s1(A) logical A integer iscan, iverify character(7), parameter :: tf(2) = ['.FALSE.','.TRUE. '] iscan = scan('AA','A',back=A) iverify = verify('xx','A',back=A) write(*,'(a)') 'SCAN test: A = '//trim(tf(iscan)) write(*,'(a)') 'VERIFY test: A = '//trim(tf(iverify)) end subroutine s1 end module m1 program p1 use m1 implicit none logical B B = .TRUE. call s1(B) end program p1