public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Fortran/OpenMP: Handle implicit SAVE for variables in main
@ 2021-05-14 16:13 Tobias Burnus
  2021-05-14 16:46 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2021-05-14 16:13 UTC (permalink / raw)
  To: gcc-patches, Jakub Jelinek, fortran

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

Found when working on another patch. Variables in the specification
part of a module – but also in a main program are implicitly SAVE.

Likewise for variables with initialization - but that was already
handled.

OK for mainline and GCC 11?

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: main-save.diff --]
[-- Type: text/x-patch, Size: 1793 bytes --]

Fortran/OpenMP: Handle implicit SAVE for variables in main

gcc/fortran/ChangeLog:

	* resolve.c (resolve_symbol): Handle implicit SAVE of main-program
	for vars in 'omp threadprivate' and 'omp declare target'.

gcc/testsuite/ChangeLog:

	* gfortran.dg/gomp/implicit-save.f90: New test.

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 5a81387e277..c02bbed8739 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -16039,7 +16039,8 @@ resolve_symbol (gfc_symbol *sym)
       && !(sym->ns->save_all && !sym->attr.automatic)
       && sym->module == NULL
       && (sym->ns->proc_name == NULL
-	  || sym->ns->proc_name->attr.flavor != FL_MODULE))
+	  || (sym->ns->proc_name->attr.flavor != FL_MODULE
+	      && !sym->ns->proc_name->attr.is_main_program)))
     gfc_error ("Threadprivate at %L isn't SAVEd", &sym->declared_at);
 
   /* Check omp declare target restrictions.  */
@@ -16050,7 +16051,8 @@ resolve_symbol (gfc_symbol *sym)
       && (!sym->attr.in_common
 	  && sym->module == NULL
 	  && (sym->ns->proc_name == NULL
-	      || sym->ns->proc_name->attr.flavor != FL_MODULE)))
+	      || (sym->ns->proc_name->attr.flavor != FL_MODULE
+		  && !sym->ns->proc_name->attr.is_main_program))))
     gfc_error ("!$OMP DECLARE TARGET variable %qs at %L isn't SAVEd",
 	       sym->name, &sym->declared_at);
 
diff --git a/gcc/testsuite/gfortran.dg/gomp/implicit-save.f90 b/gcc/testsuite/gfortran.dg/gomp/implicit-save.f90
new file mode 100644
index 00000000000..2af9647490e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/implicit-save.f90
@@ -0,0 +1,11 @@
+subroutine foo
+  integer :: n = 5, m = 7
+  !$omp declare target to(n)
+  !$omp threadprivate (m)
+end
+
+program main
+  integer :: i, j
+  !$omp declare target to(i)
+  !$omp threadprivate (j)
+end

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch] Fortran/OpenMP: Handle implicit SAVE for variables in main
  2021-05-14 16:13 [Patch] Fortran/OpenMP: Handle implicit SAVE for variables in main Tobias Burnus
@ 2021-05-14 16:46 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2021-05-14 16:46 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, fortran

On Fri, May 14, 2021 at 06:13:55PM +0200, Tobias Burnus wrote:
> Found when working on another patch. Variables in the specification
> part of a module – but also in a main program are implicitly SAVE.
> 
> Likewise for variables with initialization - but that was already
> handled.
> 
> OK for mainline and GCC 11?

Ok, thanks.

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-14 16:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 16:13 [Patch] Fortran/OpenMP: Handle implicit SAVE for variables in main Tobias Burnus
2021-05-14 16:46 ` Jakub Jelinek

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).