public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <Tobias_Burnus@mentor.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
	fortran <fortran@gcc.gnu.org>, Jakub Jelinek <jakub@redhat.com>
Subject: [Patch] Fortran/OpenMP: Accept implicit-save DATA vars for threadprivate [PR99514]
Date: Wed, 10 Mar 2021 15:20:51 +0100	[thread overview]
Message-ID: <6de1fb7c-eeb7-e361-5494-a0bac24b65a7@mentor.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 795 bytes --]

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

[-- Attachment #2: omp-threadprivate.diff --]
[-- Type: text/x-patch, Size: 1892 bytes --]

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	other threads:[~2021-03-10 14:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10 14:20 Tobias Burnus [this message]
2021-03-12 12:07 ` Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6de1fb7c-eeb7-e361-5494-a0bac24b65a7@mentor.com \
    --to=tobias_burnus@mentor.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).