Patchwork [Fortran] PR 45742 Fix VOLATILE handling

login
register
mail settings
Submitter Tobias Burnus
Date Nov. 13, 2010, 7:58 a.m.
Message ID <4CDE4523.7000605@net-b.de>
Download mbox | patch
Permalink /patch/71039/
State New
Headers show

Comments

Tobias Burnus - Nov. 13, 2010, 7:58 a.m.
This patch fixes two problems:

a) For volatile, a decl not only needs TREE_THIS_VOLATILE but also 
TREE_SIDE_EFFECTS - otherwise, the middle end does not always honour the 
volatile attribute.

b) Decls of dummy arguments were not marked as volatile.


Thanks to Thomas for the bugreport. Thanks to Andrew, Ian and Richard 
for helping to debug this.

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias
Tobias Burnus - Nov. 13, 2010, 10:30 a.m.
On November 13, 2010, Tobias Burnus wrote:
> This patch fixes two problems:  [...]
>
> Build and regtested on x86-64-linux.
> OK for the trunk?

I just saw that Jerry wrote an OK in IRC #gfortran. I thus have 
submitted it to the trunk (Rev. 166701).

Additionally, I think it should be submitted to the branches - at least 
to 4.5, maybe also to 4.4. Comments?

Tobias,
who now bootstraps the patch on 4.5.
Thomas Koenig - Nov. 13, 2010, 11:54 a.m.
Hi Tobias,
> 
> Additionally, I think it should be submitted to the branches - at
> least 
> to 4.5, maybe also to 4.4. Comments?

I'd vote for both 4.5 and 4.4 (OK for both), as without this patch,
volatile is really broken.

	Thomas
Steve Kargl - Nov. 13, 2010, 4:15 p.m.
On Sat, Nov 13, 2010 at 11:30:14AM +0100, Tobias Burnus wrote:
> On November 13, 2010, Tobias Burnus wrote:
> >This patch fixes two problems:  [...]
> >
> >Build and regtested on x86-64-linux.
> >OK for the trunk?
> 
> I just saw that Jerry wrote an OK in IRC #gfortran. I thus have 
> submitted it to the trunk (Rev. 166701).
> 
> Additionally, I think it should be submitted to the branches - at least 
> to 4.5, maybe also to 4.4. Comments?
> 

OK for both.

Patch

2010-11-13  Tobias Burnus  <burnus@net-b.de>

	PR fortran/45742
	* trans-common.c (build_field): Add TREE_SIDE_EFFECTS for volatile.
	* trans-decl.c (gfc_finish_var_decl): Ditto.
	(create_function_arglist): Handle volatile dummy arguments.

2010-11-13  Tobias Burnus  <burnus@net-b.de>

	PR fortran/45742
	* gfortran.dg/volatile12.f90: New.

diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c
index 486fbbb..1f59a69 100644
--- a/gcc/fortran/trans-common.c
+++ b/gcc/fortran/trans-common.c
@@ -321,8 +321,9 @@  build_field (segment_info *h, tree union_type, record_layout_info rli)
   if (h->sym->attr.volatile_)
     {
       tree new_type;
       TREE_THIS_VOLATILE (field) = 1;
+      TREE_SIDE_EFFECTS (field) = 1;
       new_type = build_qualified_type (TREE_TYPE (field), TYPE_QUAL_VOLATILE);
       TREE_TYPE (field) = new_type;
     }
 
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 3f068de..0441db7 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -554,8 +554,9 @@  gfc_finish_var_decl (tree decl, gfc_symbol * sym)
 
   if (sym->attr.volatile_)
     {
       TREE_THIS_VOLATILE (decl) = 1;
+      TREE_SIDE_EFFECTS (decl) = 1;
       new_type = build_qualified_type (TREE_TYPE (decl), TYPE_QUAL_VOLATILE);
       TREE_TYPE (decl) = new_type;
     } 
 
@@ -1943,12 +1944,21 @@  create_function_arglist (gfc_symbol * sym)
 
       if (f->sym->attr.proc_pointer)
         type = build_pointer_type (type);
 
+      if (f->sym->attr.volatile_)
+	type = build_qualified_type (type, TYPE_QUAL_VOLATILE);
+
       /* Build the argument declaration.  */
       parm = build_decl (input_location,
 			 PARM_DECL, gfc_sym_identifier (f->sym), type);
 
+      if (f->sym->attr.volatile_)
+	{
+	  TREE_THIS_VOLATILE (parm) = 1;
+	  TREE_SIDE_EFFECTS (parm) = 1;
+	}
+
       /* Fill in arg stuff.  */
       DECL_CONTEXT (parm) = fndecl;
       DECL_ARG_TYPE (parm) = TREE_VALUE (typelist);
       /* All implementation args are read-only.  */
diff --git a/gcc/testsuite/gfortran.dg/volatile12.f90 b/gcc/testsuite/gfortran.dg/volatile12.f90
new file mode 100644
index 0000000..8de143d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/volatile12.f90
@@ -0,0 +1,16 @@ 
+! { dg-do compile }
+! { dg-options "-fdump-tree-optimized -O3" }
+!
+! PR fortran/45742
+!
+
+subroutine sub(arg)
+  integer, volatile :: arg
+  if (arg /= arg) call I_dont_exist()
+end
+
+! { dg-final { scan-tree-dump "integer.kind=.. . volatile arg" "optimized" } }
+! { dg-final { scan-tree-dump-times " =.v. arg;" 2 "optimized" } }
+! { dg-final { scan-tree-dump "i_dont_exist" "optimized" } }
+! { dg-final { cleanup-tree-dump "original" } }
+