If a variable appears in DATA, the following applies:

F2018: 8.6.7  DATA statement
"Except for variables in named common blocks, a named variable has the
 SAVE attribute if any part of it is initialized in a DATA statement,
 and this may be confirmed by explicit specification."

The attached testcase was rejected as the implicit save was not honored.
There is no need to distinguish between SAVE and COMMON as common was/is
already accepted.

The code used only '&&' conditions without a '!' before the '('. Thus,
there is no need to indent half of the conditions ...

OK for mainline?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf
Fortran/OpenMP: Accept implicit-save DATA vars for threadprivate [PR99514]

gcc/fortran/ChangeLog:

	PR fortran/99514
	* resolve.c (resolve_symbol): Accept vars which are in DATA
	and hence (either) implicit SAVE (or in common).

gcc/testsuite/ChangeLog:

	PR fortran/99514
	* gfortran.dg/gomp/threadprivate-1.f90: New test.

 gcc/fortran/resolve.c                              | 10 +++++-----
 gcc/testsuite/gfortran.dg/gomp/threadprivate-1.f90 | 11 +++++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 2a91ae743ea..32015c21efc 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -16024,12 +16024,12 @@ resolve_symbol (gfc_symbol *sym)
     }
 
   /* Check threadprivate restrictions.  */
-  if (sym->attr.threadprivate && !sym->attr.save
+  if (sym->attr.threadprivate
+      && !(sym->attr.save || sym->attr.data || sym->attr.in_common)
       && !(sym->ns->save_all && !sym->attr.automatic)
-      && (!sym->attr.in_common
-	  && sym->module == NULL
-	  && (sym->ns->proc_name == NULL
-	      || sym->ns->proc_name->attr.flavor != FL_MODULE)))
+      && sym->module == NULL
+      && (sym->ns->proc_name == NULL
+	  || sym->ns->proc_name->attr.flavor != FL_MODULE))
     gfc_error ("Threadprivate at %L isn't SAVEd", &sym->declared_at);
 
   /* Check omp declare target restrictions.  */
diff --git a/gcc/testsuite/gfortran.dg/gomp/threadprivate-1.f90 b/gcc/testsuite/gfortran.dg/gomp/threadprivate-1.f90
new file mode 100644
index 00000000000..59656c2b18d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/threadprivate-1.f90
@@ -0,0 +1,11 @@
+! PR fortran/99514
+!
+! NTest in DATA is implicitly SAVE, unless in COMMON
+! Was failing before as the implicit SAVE was not
+! honoured by the threadprivate check.
+!
+
+program main
+  DATA NTest /1/
+  !$omp threadprivate(Ntest)
+end program main

Reply via email to