Index: fortran/resolve.c =================================================================== --- fortran/resolve.c (revision 246143) +++ fortran/resolve.c (working copy) @@ -15560,7 +15560,7 @@ resolve_equivalence (gfc_equiv *eq) locus *last_where = NULL; seq_type eq_type, last_eq_type; gfc_typespec *last_ts; - int object, cnt_protected; + int object, cnt_protected, cnt_volatile; const char *msg; last_ts = &eq->expr->symtree->n.sym->ts; @@ -15569,6 +15569,8 @@ resolve_equivalence (gfc_equiv *eq) cnt_protected = 0; + cnt_volatile = 0; + for (object = 1; eq; eq = eq->eq, object++) { e = eq->expr; @@ -15641,6 +15643,17 @@ resolve_equivalence (gfc_equiv *eq) sym = e->symtree->n.sym; + if(sym->attr.volatile_) + cnt_volatile++; + if(cnt_volatile > 0 && cnt_volatile != object) + { + gfc_warning (0, "Either all or none of the objects in " + "the EQUIVALENCE set at %L should have the " + "VOLATILE attribute", + &e->where); + break; + } + if (sym->attr.is_protected) cnt_protected++; if (cnt_protected > 0 && cnt_protected != object) Index: testsuite/gfortran.dg/volatile11.f90 =================================================================== --- testsuite/gfortran.dg/volatile11.f90 (revision 246140) +++ testsuite/gfortran.dg/volatile11.f90 (working copy) @@ -3,6 +3,7 @@ ! Tests that volatile can be applied to members of common blocks or ! equivalence groups (PR fortran/35037) ! + subroutine wait1 logical event volatile event @@ -16,7 +17,7 @@ end subroutine subroutine wait2 logical event, foo volatile event - equivalence (event, foo) + equivalence (event, foo) ! { dg-warning "in the EQUIVALENCE set" } event = .false. do if (event) print *, 'NotOptimizedAway2' @@ -27,7 +28,7 @@ subroutine wait3 logical event integer foo volatile foo - equivalence (event, foo) + equivalence (event, foo) ! { dg-warning "in the EQUIVALENCE set" } event = .false. do if (event) print *, 'IsOptimizedAway'