* [patch, fortran] PR39239 Warning about EQUIVALENCE and VOLATILE
@ 2017-03-14 20:17 Nicolas Koenig
2017-03-14 21:42 ` Jerry DeLisle
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Koenig @ 2017-03-14 20:17 UTC (permalink / raw)
To: fortran; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 574 bytes --]
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
[-- Attachment #2: p7.diff --]
[-- Type: text/x-patch, Size: 2395 bytes --]
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" } } */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch, fortran] PR39239 Warning about EQUIVALENCE and VOLATILE
2017-03-14 20:17 [patch, fortran] PR39239 Warning about EQUIVALENCE and VOLATILE Nicolas Koenig
@ 2017-03-14 21:42 ` Jerry DeLisle
2017-03-14 22:54 ` Nicolas Koenig
0 siblings, 1 reply; 3+ messages in thread
From: Jerry DeLisle @ 2017-03-14 21:42 UTC (permalink / raw)
To: Nicolas Koenig, fortran; +Cc: gcc-patches
On 03/14/2017 01:17 PM, Nicolas Koenig wrote:
> 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
>
>
Hi Nicolas,
Thanks for starting in on this.
Since this results in a warning, maybe change the wording from 'shall' to should.
I did not dig into the Fortran Standards so I assume it need not be an error.
Also when you submit a patch, please also let us know what platform you
regression tested on, such as x86-64-linux, or Windows, or similar. (You can get
the whole string from subdirectory names in build directory. On mine its
x86_64-pc-linux-gnu) Sometimes we accidentally break things on different
platforms. so this way we can see it tested ok over here and seems to fail over
there.
Your patch has changed some of the scan dumps and I am wondering if you have
deleted something we use to check for?
Jerry
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch, fortran] PR39239 Warning about EQUIVALENCE and VOLATILE
2017-03-14 21:42 ` Jerry DeLisle
@ 2017-03-14 22:54 ` Nicolas Koenig
0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Koenig @ 2017-03-14 22:54 UTC (permalink / raw)
To: Jerry DeLisle, fortran; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1823 bytes --]
On 03/14/2017 10:42 PM, Jerry DeLisle wrote:
> On 03/14/2017 01:17 PM, Nicolas Koenig wrote:
>> 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
>>
>>
> Hi Nicolas,
>
> Thanks for starting in on this.
>
> Since this results in a warning, maybe change the wording from 'shall' to should.
>
> I did not dig into the Fortran Standards so I assume it need not be an error.
>
> Also when you submit a patch, please also let us know what platform you
> regression tested on, such as x86-64-linux, or Windows, or similar. (You can get
> the whole string from subdirectory names in build directory. On mine its
> x86_64-pc-linux-gnu) Sometimes we accidentally break things on different
> platforms. so this way we can see it tested ok over here and seems to fail over
> there.
>
> Your patch has changed some of the scan dumps and I am wondering if you have
> deleted something we use to check for?
>
> Jerry
>
Hello Jerry,
I have to thank for the kind feedback.
Attached is a reworked version of the patch with the changes applied. It
also should have the same scan dump now, one of the test cases was
edited stupidly.
The regression tests for both the old as well as the new test have been
performed on an x86-64-linux (x86_64-pc-linux-gnu).
Nicolas
[-- Attachment #2: p8.diff --]
[-- Type: text/x-patch, Size: 2073 bytes --]
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'
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-14 22:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14 20:17 [patch, fortran] PR39239 Warning about EQUIVALENCE and VOLATILE Nicolas Koenig
2017-03-14 21:42 ` Jerry DeLisle
2017-03-14 22:54 ` Nicolas Koenig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).