This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch, fortran] PR39239 Warning about EQUIVALENCE and VOLATILE
- From: Nicolas Koenig <koenigni at student dot ethz dot ch>
- To: <fortran at gcc dot gnu dot org>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 14 Mar 2017 21:17:02 +0100
- Subject: [patch, fortran] PR39239 Warning about EQUIVALENCE and VOLATILE
- Authentication-results: sourceware.org; auth=none
Hello everyone,
a simple patch to throw a warning if not all and not none of the
equivalence objects are volatile. (And the according modification of
gfortran.dg/volatile11.f90)
Nicolas
Regression tested for:
GNU Fortran (GCC) 7.0.1 20170311 (experimental)
Changelog:
2017-03-13 Nicolas Koenig <koenigni@student.ethz.ch>
PR fortran/39239
* resolve.c (resolve_equivalence): Warn if not either
none or all equivalence objects are volatile
* gfortran.dg/volatile11.f90: Changed test to test for
the new warning
Index: fortran/resolve.c
===================================================================
--- fortran/resolve.c (revision 246070)
+++ 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 shall 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 246070)
+++ testsuite/gfortran.dg/volatile11.f90 (working copy)
@@ -1,8 +1,9 @@
! { dg-do compile }
-! { dg-options "-O2 -fdump-tree-optimized" }
+! { dg-options "-Wall -O2 -fdump-tree-optimized" }
! Tests that volatile can be applied to members of common blocks or
! equivalence groups (PR fortran/35037)
!
+
subroutine wait1
logical event
volatile event
@@ -14,26 +15,10 @@ subroutine wait1
end subroutine
subroutine wait2
- logical event, foo
- volatile event
- equivalence (event, foo)
- event = .false.
- do
- if (event) print *, 'NotOptimizedAway2'
- end do
-end subroutine
-
-subroutine wait3
logical event
integer foo
volatile foo
- equivalence (event, foo)
- event = .false.
- do
- if (event) print *, 'IsOptimizedAway'
- end do
+ equivalence (event, foo) ! { dg-warning "in the EQUIVALENCE set" }
end subroutine
! { dg-final { scan-tree-dump "NotOptimizedAway1" "optimized" } } */
-! { dg-final { scan-tree-dump "NotOptimizedAway2" "optimized" } } */
-! { dg-final { scan-tree-dump-not "IsOptimizedAway" "optimized" } } */