diff mbox series

Reject function and subroutine arguments in OpenACC declare data clauses (PR85701)

Message ID bb9390d2-6a2f-afe2-6260-a77d538a91a0@codesourcery.com
State New
Headers show
Series Reject function and subroutine arguments in OpenACC declare data clauses (PR85701) | expand

Commit Message

Cesar Philippidis June 5, 2018, 1:53 p.m. UTC
OpenACC declare is implemented somewhat special in the Fortran FE in
that it preforms its own data clause error handling. As PR85701
demonstrated, one situation that lacked test coverage was passing in
function and subroutine identifiers as data clause arguments to acc
declare. This patch rectifies that issue by checking for the function
and subroutine symbol attribute and issuing an error when it detects
such a symbol. The Fortran FE also has attributes for other types of
functions, but gfc_match_omp_variable_list already handle those.
However, as GCC gains support for derived-type objects, this may have to
be revisited.

I tested this patch on x86_64 with nvptx offloading. Is it OK for trunk
and the stable branches?

Thanks,
Cesar

Comments

Jakub Jelinek June 5, 2018, 1:55 p.m. UTC | #1
On Tue, Jun 05, 2018 at 06:53:43AM -0700, Cesar Philippidis wrote:
> OpenACC declare is implemented somewhat special in the Fortran FE in
> that it preforms its own data clause error handling. As PR85701
> demonstrated, one situation that lacked test coverage was passing in
> function and subroutine identifiers as data clause arguments to acc
> declare. This patch rectifies that issue by checking for the function
> and subroutine symbol attribute and issuing an error when it detects
> such a symbol. The Fortran FE also has attributes for other types of
> functions, but gfc_match_omp_variable_list already handle those.
> However, as GCC gains support for derived-type objects, this may have to
> be revisited.
> 
> I tested this patch on x86_64 with nvptx offloading. Is it OK for trunk
> and the stable branches?
> 
> Thanks,
> Cesar

> 2018-06-05  Cesar Philippidis  <cesar@codesourcery.com>
> 
> 	PR fortran/85701
> 
> 	gcc/fortran/
> 	* openmp.c (gfc_resolve_oacc_declare): Error on functions and
> 	subroutine data clause arguments.
> 
> 	gcc/testsuite/
> 	* gfortran.dg/goacc/pr85701.f90: New test.

Ok, thanks.

	Jakub
diff mbox series

Patch

2018-06-05  Cesar Philippidis  <cesar@codesourcery.com>

	PR fortran/85701

	gcc/fortran/
	* openmp.c (gfc_resolve_oacc_declare): Error on functions and
	subroutine data clause arguments.

	gcc/testsuite/
	* gfortran.dg/goacc/pr85701.f90: New test.


diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index be80f8dea24..5c13312585a 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -5994,6 +5994,12 @@  gfc_resolve_oacc_declare (gfc_namespace *ns)
 	for (n = oc->clauses->lists[list]; n; n = n->next)
 	  {
 	    n->sym->mark = 0;
+	    if (n->sym->attr.function || n->sym->attr.subroutine)
+	      {
+		gfc_error ("Object %qs is not a variable at %L",
+			   n->sym->name, &oc->loc);
+		continue;
+	      }
 	    if (n->sym->attr.flavor == FL_PARAMETER)
 	      {
 		gfc_error ("PARAMETER object %qs is not allowed at %L",
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr85701.f90 b/gcc/testsuite/gfortran.dg/goacc/pr85701.f90
new file mode 100644
index 00000000000..9c201b865b2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/pr85701.f90
@@ -0,0 +1,23 @@ 
+! PR fortran/85701
+! { dg-do compile }
+
+subroutine s1
+   !$acc declare copy(s1) ! { dg-error "is not a variable" }
+end
+
+subroutine s2
+   !$acc declare present(s2) ! { dg-error "is not a variable" }
+end
+
+function f1 ()
+   !$acc declare copy(f1) ! { dg-error "is not a variable" }
+end
+
+function f2 ()
+   !$acc declare present(f2) ! { dg-error "is not a variable" }
+end
+
+program p
+  !$acc declare copy(p) ! { dg-error "is not a variable" }
+end
+