Fortran/OpenMP: Accept implicit-save DATA vars for threadprivate [PR99514]
authorTobias Burnus <tobias@codesourcery.com>
Fri, 12 Mar 2021 15:34:10 +0000 (16:34 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 12 Mar 2021 15:34:10 +0000 (16:34 +0100)
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
gcc/testsuite/gfortran.dg/gomp/threadprivate-1.f90 [new file with mode: 0644]

index 2a91ae7..32015c2 100644 (file)
@@ -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 (file)
index 0000000..59656c2
--- /dev/null
@@ -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