This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, Fortran] PR32359 OpenMP threadprivate: SAVE is implied by explicit initialization


Daniel Franke schrieb:
> On Saturday 16 June 2007 16:36:33 Tobias Burnus wrote:
>   
>> How about something like the attached patch?
>>     
> Looks good to me :)
>
> gfortran.dg/module_md5_1.f90; after glancing at module.c I still don't
>   
> That's the implicit SAVE of
>   module foo
>     integer(kind=4), parameter :: pi = 3_4
>   end module foo
> propagated to foo.mod:
>   3 'pi' 'foo' 1 ((PARAMETER UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN SAVE) (
> The SAVE at the end of the line was set to UNKNOWN before.
>   
As also with the old version a "static" variable was produced 
(-fdump-tree-original), I think the new behaviour for .MOD is
consistent, even though I have problems imaging a parameter with a SAVE
attribute.

Regression tested (check-gfortran and libgomp) on
x86_64-unknown-linux-gnu with -m64 and -m32 and no failures.
Ok for the trunk?

Tobias
2007-06-16  Daniel Franke  <franke.daniel@gmail.com>
	    Tobias Burnus  <burnus@net-b.de>

	PR fortran/32359
	* gfortran.h (symbol_attribute): Change save attribute into an enum.
	* decl.c (add_init_expr_to_sym): Set it to SAVE_IMPLICIT.
	* symbol.c (gfc_add_save): Check for SAVE_EXPLICIT.
	* resolve.c (resolve_fl_variable): Check for SAVE_EXPLICIT.
	(resolve_symbol): Allow OMP threadprivate with
	initialization SAVEd and save_all variable.
	* trans-decl.c (gfc_finish_var_decl): Remove obsolete sym->value check.

2007-06-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/32359
	* testsuite/libgomp.fortran/pr32359.f90: New.
	* gfortran.dg/module_md5_1.f90: Update MD5 number.

Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c	(Revision 125789)
+++ gcc/fortran/symbol.c	(Arbeitskopie)
@@ -885,7 +885,7 @@ gfc_add_save (symbol_attribute *attr, co
       return FAILURE;
     }
 
-  if (attr->save)
+  if (attr->save == SAVE_EXPLICIT)
     {
 	if (gfc_notify_std (GFC_STD_LEGACY, 
 			    "Duplicate SAVE attribute specified at %L",
@@ -894,7 +894,7 @@ gfc_add_save (symbol_attribute *attr, co
 	  return FAILURE;
     }
 
-  attr->save = 1;
+  attr->save = SAVE_EXPLICIT;
   return check_conflict (attr, name, where);
 }
 
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(Revision 125789)
+++ gcc/fortran/decl.c	(Arbeitskopie)
@@ -1021,6 +1021,7 @@ add_init_expr_to_sym (const char *name, 
 	}
 
       sym->value = init;
+      sym->attr.save = SAVE_IMPLICIT;
       *initp = NULL;
     }
 
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(Revision 125789)
+++ gcc/fortran/gfortran.h	(Arbeitskopie)
@@ -291,6 +291,12 @@ typedef enum ifsrc
 }
 ifsrc;
 
+/* Whether a SAVE attribute was set explicitly or implictly.  */
+typedef enum save_state
+{ SAVE_NONE = 0, SAVE_EXPLICIT, SAVE_IMPLICIT
+}
+save_state;
+
 /* Strings for all symbol attributes.  We use these for dumping the
    parse tree, in error messages, and also when reading and writing
    modules.  In symbol.c.  */
@@ -558,10 +564,12 @@ typedef struct
 {
   /* Variable attributes.  */
   unsigned allocatable:1, dimension:1, external:1, intrinsic:1,
-    optional:1, pointer:1, save:1, target:1, value:1, volatile_:1,
+    optional:1, pointer:1, target:1, value:1, volatile_:1,
     dummy:1, result:1, assign:1, threadprivate:1, not_always_present:1,
     implied_index:1;
 
+  ENUM_BITFIELD (save_state) save:2;
+
   unsigned data:1,		/* Symbol is named in a DATA statement.  */
     protected:1,		/* Symbol has been marked as protected.  */
     use_assoc:1,		/* Symbol has been use-associated.  */
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 125789)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -5780,8 +5780,9 @@ resolve_fl_variable (gfc_symbol *sym, in
 	    }
 	}
 
-      /* Also, they must not have the SAVE attribute.  */
-      if (flag && sym->attr.save)
+      /* Also, they must not have the SAVE attribute.
+	 SAVE_IMPLICIT is checked below.  */
+      if (flag && sym->attr.save == SAVE_EXPLICIT)
 	{
 	  gfc_error (auto_save_msg, sym->name, &sym->declared_at);
 	  return FAILURE;
@@ -6428,7 +6429,7 @@ resolve_symbol (gfc_symbol *sym)
     gfc_resolve (sym->formal_ns);
 
   /* Check threadprivate restrictions.  */
-  if (sym->attr.threadprivate && !sym->attr.save
+  if (sym->attr.threadprivate && !sym->attr.save && !sym->ns->save_all
       && (!sym->attr.in_common
 	  && sym->module == NULL
 	  && (sym->ns->proc_name == NULL
Index: libgomp/testsuite/libgomp.fortran/pr32359.f90
===================================================================
--- libgomp/testsuite/libgomp.fortran/pr32359.f90	(Revision 0)
+++ libgomp/testsuite/libgomp.fortran/pr32359.f90	(Revision 0)
@@ -0,0 +1,34 @@
+! { dg-do compile }
+!
+! PR fortran/32359
+! Contributed by Bill Long <longb@cray.com>
+
+subroutine test
+      use omp_lib
+      implicit none
+      integer, parameter :: NT = 4
+      integer :: a
+      save
+!$omp threadprivate(a)
+      a = 1
+
+!$    call omp_set_num_threads(NT)
+!$omp parallel
+      print *, omp_get_thread_num(), a
+!$omp end parallel
+
+end subroutine test
+
+! Derived from OpenMP test omp1/F2_6_2_8_5i.f90
+      use omp_lib
+      implicit none
+      integer, parameter :: NT = 4
+      integer :: a = 1
+!$omp threadprivate(a)
+
+!$    call omp_set_num_threads(NT)
+!$omp parallel
+      print *, omp_get_thread_num(), a
+!$omp end parallel
+
+      END
Index: gcc/testsuite/gfortran.dg/module_md5_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/module_md5_1.f90	(Revision 125789)
+++ gcc/testsuite/gfortran.dg/module_md5_1.f90	(Arbeitskopie)
@@ -10,5 +10,5 @@ program test
   use foo
   print *, pi
 end program test
-! { dg-final { scan-module "foo" "MD5:18a257e13c90e3872b7b9400c2fc6e4b" } }
+! { dg-final { scan-module "foo" "MD5:2acedc3d584fad6aae6248078b02aa38" } }
 ! { dg-final { cleanup-modules "foo" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]