diff mbox

Fix use of declare'd vars by routine procedures.

Message ID 569C1D44.8080404@codesourcery.com
State New
Headers show

Commit Message

James Norris Jan. 17, 2016, 11:01 p.m. UTC
Hi!

The attached patch addresses the failure of declare-4 in the libgomp testsuite.
The primary failure was the use a variable with a link clause for an OpenACC
routine function. The patch changes the test to use a create clause. The patch
also adds checking of those globals used within an OpenACC routine function.
Additional gcc testing is also included in the patch.

Regtested and bootstrapped on x86_64.

OK for trunk?

Thanks!

Jim

Comments

Jakub Jelinek Jan. 22, 2016, 10:39 a.m. UTC | #1
On Sun, Jan 17, 2016 at 05:01:24PM -0600, James Norris wrote:
> The attached patch addresses the failure of declare-4 in the libgomp testsuite.
> The primary failure was the use a variable with a link clause for an OpenACC
> routine function. The patch changes the test to use a create clause. The patch
> also adds checking of those globals used within an OpenACC routine function.
> Additional gcc testing is also included in the patch.
> 
> Regtested and bootstrapped on x86_64.

The testcase change is obviously fine, please install it separately.

As for the extra error, I think it would be better to diagnose this during
gimplification, that way you do it for all FEs, plus you have the omp
context in there, etc.  The error wording is weird, the diagnostic
should make it clear use of what is invalid in what and why.

	Jakub
diff mbox

Patch

Index: gcc/c/ChangeLog
===================================================================
--- gcc/c/ChangeLog	(revision 232340)
+++ gcc/c/ChangeLog	(working copy)
@@ -1,3 +1,7 @@ 
+2016-01-XX  James Norris  <jnorris@codesourcery.com>
+
+	* c-parser.c (build_external_ref): Add usage check.
+
 2016-01-06  David Malcolm  <dmalcolm@redhat.com>
 
 	* c-parser.c (c_parser_unary_expression): For dereferences, build
Index: gcc/c/c-typeck.c
===================================================================
--- gcc/c/c-typeck.c	(revision 232340)
+++ gcc/c/c-typeck.c	(working copy)
@@ -2677,6 +2677,26 @@ 
   tree ref;
   tree decl = lookup_name (id);
 
+  if (decl
+      && decl != error_mark_node
+      && current_function_decl
+      && TREE_CODE (decl) == VAR_DECL
+      && is_global_var (decl)
+      && get_oacc_fn_attrib (current_function_decl))
+    {
+      /* Validate data type for use with routine directive.  */
+      if (lookup_attribute ("omp declare target link",
+			    DECL_ATTRIBUTES (decl))
+	  || ((!lookup_attribute ("omp declare target",
+				  DECL_ATTRIBUTES (decl))
+	       && ((TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
+		   || (!TREE_STATIC (decl) && DECL_EXTERNAL (decl))))))
+	{
+	  error_at (loc, "invalid use in %<routine%> function");
+	  return error_mark_node;
+	}
+    }
+
   /* In Objective-C, an instance variable (ivar) may be preferred to
      whatever lookup_name() found.  */
   decl = objc_lookup_ivar (decl, id);
Index: gcc/cp/ChangeLog
===================================================================
--- gcc/cp/ChangeLog	(revision 232340)
+++ gcc/cp/ChangeLog	(working copy)
@@ -1,3 +1,7 @@ 
+2016-01-XX  James Norris  <jnorris@codesourcery.com>
+
+	* semantics.c (finish_id_expression): Add usage check.
+
 2016-01-12  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/68979
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 232340)
+++ gcc/cp/semantics.c	(working copy)
@@ -3712,6 +3712,25 @@ 
 
 	  decl = convert_from_reference (decl);
 	}
+
+      if (decl != error_mark_node
+	  && current_function_decl
+	  && TREE_CODE (decl) == VAR_DECL
+	  && is_global_var (decl)
+	  && get_oacc_fn_attrib (current_function_decl))
+	{
+	  /* Validate data type for use with routine directive.  */
+	  if (lookup_attribute ("omp declare target link",
+				DECL_ATTRIBUTES (decl))
+	      || ((!lookup_attribute ("omp declare target",
+				  DECL_ATTRIBUTES (decl))
+		   && ((TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
+			|| (!TREE_STATIC (decl) && DECL_EXTERNAL (decl))))))
+	    {
+	      *error_msg = "invalid use in %<routine%> function";
+	      return error_mark_node;
+	    }
+	}
     }
 
   return cp_expr (decl, location);
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 232340)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,7 @@ 
+2016-01-XX  James Norris  <jnorris@codesourcery.com>
+
+	* c-c++-common/goacc/routine-5.c: Additional tests.
+
 2016-01-13  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* gcc.target/i386/pr69225-7.c: New test.
Index: gcc/testsuite/c-c++-common/goacc/routine-5.c
===================================================================
--- gcc/testsuite/c-c++-common/goacc/routine-5.c	(revision 232340)
+++ gcc/testsuite/c-c++-common/goacc/routine-5.c	(working copy)
@@ -45,3 +45,49 @@ 
 #pragma acc routine (a) /* { dg-error "does not refer to" } */
   
 #pragma acc routine (c) /* { dg-error "does not refer to" } */
+
+float vb1;
+
+#pragma acc routine
+int
+func1 (int a)
+{
+  vb1 = a + 1; /* { dg-error "invalid use in" } */
+
+  return vb1; /* { dg-error "invalid use in" } */
+}
+
+#pragma acc routine
+int
+func2 (int a)
+{
+  static int vb2;
+
+  vb2 = a + 1; /* { dg-error "invalid use in" } */
+
+  return vb2; /* { dg-error "invalid use in" } */
+}
+
+float vb3;
+#pragma acc declare link (vb3)
+
+#pragma acc routine
+int
+func3 (int a)
+{
+  vb3 = a + 1; /* { dg-error "invalid use in" } */
+
+  return vb3; /* { dg-error "invalid use in" } */
+}
+
+float vb4;
+#pragma acc declare create (vb4)
+
+#pragma acc routine
+int
+func4 (int a)
+{
+  vb4 = a + 1;
+
+  return vb4;
+}
Index: libgomp/ChangeLog
===================================================================
--- libgomp/ChangeLog	(revision 232341)
+++ libgomp/ChangeLog	(working copy)
@@ -1,3 +1,7 @@ 
+2016-01-XX  James Norris  <jnorris@codesourcery.com>
+
+	* testsuite/libgomp.oacc-c-c++-common/declare-4.c: Fix test.
+
 2016-01-12  James Norris  <jnorris@codesourcery.com>
 
 	* libgomp.texi: Updates for OpenACC.
Index: libgomp/testsuite/libgomp.oacc-c-c++-common/declare-4.c
===================================================================
--- libgomp/testsuite/libgomp.oacc-c-c++-common/declare-4.c	(revision 232340)
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/declare-4.c	(working copy)
@@ -4,7 +4,7 @@ 
 #include <openacc.h>
 
 float b;
-#pragma acc declare link (b)
+#pragma acc declare create (b)
 
 #pragma acc routine
 int