This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix use of declare'd vars by routine procedures.


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]