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]

[gomp4] Prohibit C++ reference types in OpenACC regions


Hi!

On Wed, 29 Apr 2015 09:27:49 -0700, Cesar Philippidis <cesar_philippidis@mentor.com> wrote:
> This patch teaches the c++ front end to error when reference typed
> variables are used in openacc parallel and kernels regions. The c++
> front end changes are pretty straightforward. I did, however, have to
> make omp_mappable_type langhook aware of openacc. That's because openmp
> apparently supports reference types, whereas openacc does not. I guess
> aliased mapping isn't a problem for non-openmp target regions.

Committed to gomp-4_0-branch in r223179:

commit ee20456534e0fd80333e50bab0821a0e20f065e5
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed May 13 20:56:31 2015 +0000

    Prohibit C++ reference types in OpenACC regions
    
    	gcc/
    	* langhooks-def.h (lhd_omp_mappable_type): Add bool argument.
    	* langhooks.c (lhd_omp_mappable_type): Likewise, for the
    	parameter.
    	* langhooks.h (struct lang_hooks_for_types): Add bool oacc
    	argument.
    	* gimplify.c (omp_notice_variable): Use it when calling the
    	omp_mappable_type langhook.
    	gcc/c/
    	* c-decl.c (c_decl_attributes): Update call to omp_mappable_type.
    	* c-typeck.c (c_finish_omp_clauses): Likewise.
    	gcc/cp/
    	* cp-tree.h (cp_omp_mappable_type): Add bool parameter.
    	* decl2.c (cp_check_const_attributes): Likewise. Use it.
    	(cp_omp_mappable_type): Update call to cp_omp_mappable_type.
    	(cplus_decl_attributes): Likewise.
    	* semantics.c (finish_omp_clauses): Likewise.
    	gcc/testsuite/
    	* g++.dg/goacc/reference.C: New test.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@223179 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.gomp                     | 10 ++++++++
 gcc/c/ChangeLog.gomp                   |  5 ++++
 gcc/c/c-decl.c                         |  3 ++-
 gcc/c/c-typeck.c                       |  6 +++--
 gcc/cp/ChangeLog.gomp                  |  8 +++++++
 gcc/cp/cp-tree.h                       |  2 +-
 gcc/cp/decl2.c                         |  8 ++++---
 gcc/cp/semantics.c                     | 11 ++++++---
 gcc/gimplify.c                         |  4 +++-
 gcc/langhooks-def.h                    |  2 +-
 gcc/langhooks.c                        |  2 +-
 gcc/langhooks.h                        |  2 +-
 gcc/testsuite/ChangeLog.gomp           |  4 ++++
 gcc/testsuite/g++.dg/goacc/reference.C | 42 ++++++++++++++++++++++++++++++++++
 14 files changed, 95 insertions(+), 14 deletions(-)

diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp
index 4901bf9..9e72962 100644
--- gcc/ChangeLog.gomp
+++ gcc/ChangeLog.gomp
@@ -1,3 +1,13 @@
+2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
+
+	* langhooks-def.h (lhd_omp_mappable_type): Add bool argument.
+	* langhooks.c (lhd_omp_mappable_type): Likewise, for the
+	parameter.
+	* langhooks.h (struct lang_hooks_for_types): Add bool oacc
+	argument.
+	* gimplify.c (omp_notice_variable): Use it when calling the
+	omp_mappable_type langhook.
+
 2015-05-13  Thomas Schwinge  <thomas@codesourcery.com>
 	    Bernd Schmidt  <bernds@codesourcery.com>
 	    Cesar Philippidis  <cesar@codesourcery.com>
diff --git gcc/c/ChangeLog.gomp gcc/c/ChangeLog.gomp
index 2e3cd13..08c8ed0 100644
--- gcc/c/ChangeLog.gomp
+++ gcc/c/ChangeLog.gomp
@@ -1,3 +1,8 @@
+2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
+
+	* c-decl.c (c_decl_attributes): Update call to omp_mappable_type.
+	* c-typeck.c (c_finish_omp_clauses): Likewise.
+
 2015-05-13  Thomas Schwinge  <thomas@codesourcery.com>
 	    Bernd Schmidt  <bernds@codesourcery.com>
 	    Cesar Philippidis  <cesar@codesourcery.com>
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 4f6761d..bf99a45 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -4414,7 +4414,8 @@ c_decl_attributes (tree *node, tree attributes, int flags)
 	error ("%q+D in block scope inside of declare target directive",
 	       *node);
       else if (TREE_CODE (*node) == VAR_DECL
-	       && !lang_hooks.types.omp_mappable_type (TREE_TYPE (*node)))
+	       && !lang_hooks.types.omp_mappable_type (TREE_TYPE (*node),
+						       false))
 	error ("%q+D in declare target directive does not have mappable type",
 	       *node);
       else
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 5ec04cc..974a3fc 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -12445,7 +12445,8 @@ c_finish_omp_clauses (tree clauses, bool oacc)
 	      else
 		{
 		  t = OMP_CLAUSE_DECL (c);
-		  if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (t)))
+		  if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (t),
+							   oacc))
 		    {
 		      error_at (OMP_CLAUSE_LOCATION (c),
 				"array section does not have mappable type "
@@ -12478,7 +12479,8 @@ c_finish_omp_clauses (tree clauses, bool oacc)
 		     && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
 			 || (OMP_CLAUSE_MAP_KIND (c)
 			     == GOMP_MAP_FORCE_DEVICEPTR)))
-		   && !lang_hooks.types.omp_mappable_type (TREE_TYPE (t)))
+		   && !lang_hooks.types.omp_mappable_type (TREE_TYPE (t),
+							   oacc))
 	    {
 	      error_at (OMP_CLAUSE_LOCATION (c),
 			"%qD does not have a mappable type in %qs clause", t,
diff --git gcc/cp/ChangeLog.gomp gcc/cp/ChangeLog.gomp
index 33bd97c..529206a 100644
--- gcc/cp/ChangeLog.gomp
+++ gcc/cp/ChangeLog.gomp
@@ -1,3 +1,11 @@
+2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
+
+	* cp-tree.h (cp_omp_mappable_type): Add bool parameter.
+	* decl2.c (cp_check_const_attributes): Likewise. Use it.
+	(cp_omp_mappable_type): Update call to cp_omp_mappable_type.
+	(cplus_decl_attributes): Likewise.
+	* semantics.c (finish_omp_clauses): Likewise.
+
 2015-05-13  Thomas Schwinge  <thomas@codesourcery.com>
 	    Bernd Schmidt  <bernds@codesourcery.com>
 	    Cesar Philippidis  <cesar@codesourcery.com>
diff --git gcc/cp/cp-tree.h gcc/cp/cp-tree.h
index 302dfe2..0b52e8f 100644
--- gcc/cp/cp-tree.h
+++ gcc/cp/cp-tree.h
@@ -5501,7 +5501,7 @@ extern bool possibly_inlined_p			(tree);
 extern int parm_index                           (tree);
 extern tree vtv_start_verification_constructor_init_function (void);
 extern tree vtv_finish_verification_constructor_init_function (tree);
-extern bool cp_omp_mappable_type		(tree);
+extern bool cp_omp_mappable_type		(tree, bool);
 
 /* in error.c */
 extern void init_error				(void);
diff --git gcc/cp/decl2.c gcc/cp/decl2.c
index 0d47847..ff9d409 100644
--- gcc/cp/decl2.c
+++ gcc/cp/decl2.c
@@ -1403,7 +1403,7 @@ cp_check_const_attributes (tree attributes)
 
 /* Return true if TYPE is an OpenMP mappable type.  */
 bool
-cp_omp_mappable_type (tree type)
+cp_omp_mappable_type (tree type, bool oacc)
 {
   /* Mappable type has to be complete.  */
   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
@@ -1423,9 +1423,11 @@ cp_omp_mappable_type (tree type)
 	  return false;
 	/* All fields must have mappable types.  */
 	else if (TREE_CODE (field) == FIELD_DECL
-		 && !cp_omp_mappable_type (TREE_TYPE (field)))
+		 && !cp_omp_mappable_type (TREE_TYPE (field), oacc))
 	  return false;
     }
+  if (oacc && TREE_CODE (type) == REFERENCE_TYPE)
+    return false;
   return true;
 }
 
@@ -1455,7 +1457,7 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags)
 	       *decl);
       else if (!processing_template_decl
 	       && TREE_CODE (*decl) == VAR_DECL
-	       && !cp_omp_mappable_type (TREE_TYPE (*decl)))
+	       && !cp_omp_mappable_type (TREE_TYPE (*decl), false))
 	error ("%q+D in declare target directive does not have mappable type",
 	       *decl);
       else
diff --git gcc/cp/semantics.c gcc/cp/semantics.c
index 896bae5..19b8d0b 100644
--- gcc/cp/semantics.c
+++ gcc/cp/semantics.c
@@ -5866,7 +5866,7 @@ finish_omp_clauses (tree clauses, bool oacc)
 		  t = OMP_CLAUSE_DECL (c);
 		  if (TREE_CODE (t) != TREE_LIST
 		      && !type_dependent_expression_p (t)
-		      && !cp_omp_mappable_type (TREE_TYPE (t)))
+		      && !cp_omp_mappable_type (TREE_TYPE (t), oacc))
 		    {
 		      error_at (OMP_CLAUSE_LOCATION (c),
 				"array section does not have mappable type "
@@ -5877,6 +5877,11 @@ finish_omp_clauses (tree clauses, bool oacc)
 		}
 	      break;
 	    }
+	  if (oacc && TREE_CODE (TREE_TYPE (t)) == REFERENCE_TYPE)
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"reference types are not supported in OpenACC");
+	    }
 	  if (t == error_mark_node)
 	    remove = true;
 	  else if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
@@ -5907,10 +5912,10 @@ finish_omp_clauses (tree clauses, bool oacc)
 	  else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
 		     && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER)
 		   && !type_dependent_expression_p (t)
-		   && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t))
+		   && !cp_omp_mappable_type (((TREE_CODE (TREE_TYPE (t))
 					      == REFERENCE_TYPE)
 					     ? TREE_TYPE (TREE_TYPE (t))
-					     : TREE_TYPE (t)))
+					     : TREE_TYPE (t)), oacc))
 	    {
 	      error_at (OMP_CLAUSE_LOCATION (c),
 			"%qD does not have a mappable type in %qs clause", t,
diff --git gcc/gimplify.c gcc/gimplify.c
index b7bc0c4..912b60f 100644
--- gcc/gimplify.c
+++ gcc/gimplify.c
@@ -5910,7 +5910,9 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code)
 		}
 	    }
 
-	  if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (decl)))
+	  if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (decl),
+						   ctx->region_kind
+						   == ORK_OACC))
 	    {
 	      error ("%qD referenced in target region does not have "
 		     "a mappable type", decl);
diff --git gcc/langhooks-def.h gcc/langhooks-def.h
index 303b4b6..15b9896 100644
--- gcc/langhooks-def.h
+++ gcc/langhooks-def.h
@@ -79,7 +79,7 @@ extern void lhd_omp_finish_clause (tree, gimple_seq *);
 struct gimplify_omp_ctx;
 extern void lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *,
 					       tree);
-extern bool lhd_omp_mappable_type (tree);
+extern bool lhd_omp_mappable_type (tree, bool);
 
 #define LANG_HOOKS_NAME			"GNU unknown"
 #define LANG_HOOKS_IDENTIFIER_SIZE	sizeof (struct lang_identifier)
diff --git gcc/langhooks.c gcc/langhooks.c
index 74f8351..031f158 100644
--- gcc/langhooks.c
+++ gcc/langhooks.c
@@ -555,7 +555,7 @@ lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *c ATTRIBUTE_UNUSED,
 /* Return true if TYPE is an OpenMP mappable type.  */
 
 bool
-lhd_omp_mappable_type (tree type)
+lhd_omp_mappable_type (tree type, bool oacc ATTRIBUTE_UNUSED)
 {
   /* Mappable type has to be complete.  */
   if (type == error_mark_node || !COMPLETE_TYPE_P (type))
diff --git gcc/langhooks.h gcc/langhooks.h
index 4039e8f..af02f27 100644
--- gcc/langhooks.h
+++ gcc/langhooks.h
@@ -112,7 +112,7 @@ struct lang_hooks_for_types
   void (*omp_firstprivatize_type_sizes) (struct gimplify_omp_ctx *, tree);
 
   /* Return true if TYPE is a mappable type.  */
-  bool (*omp_mappable_type) (tree type);
+  bool (*omp_mappable_type) (tree type, bool oacc);
 
   /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes.
      Called only after doing all language independent checks.
diff --git gcc/testsuite/ChangeLog.gomp gcc/testsuite/ChangeLog.gomp
index 9e5f114..e987031 100644
--- gcc/testsuite/ChangeLog.gomp
+++ gcc/testsuite/ChangeLog.gomp
@@ -1,3 +1,7 @@
+2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
+
+	* g++.dg/goacc/reference.C: New test.
+
 2015-05-13  Thomas Schwinge  <thomas@codesourcery.com>
 	    Bernd Schmidt  <bernds@codesourcery.com>
 	    Cesar Philippidis  <cesar@codesourcery.com>
diff --git gcc/testsuite/g++.dg/goacc/reference.C gcc/testsuite/g++.dg/goacc/reference.C
new file mode 100644
index 0000000..4a8d74a
--- /dev/null
+++ gcc/testsuite/g++.dg/goacc/reference.C
@@ -0,0 +1,42 @@
+// { dg-do compile }
+// { dg-options "-fopenacc" }
+
+int
+test1 (int &ref)
+{
+#pragma acc kernels copy (ref) // { dg-error "reference types are not supported in OpenACC" }
+  {
+    ref = 10;
+  }
+}
+
+int
+test2 (int &ref)
+{
+  int b;
+#pragma acc kernels copyout (b)
+  {
+    b = ref + 10; // { dg-error "referenced in target region does not have a mappable type" }
+  }
+
+#pragma acc parallel copyout (b)
+  {
+    b = ref + 10; // { dg-error "referenced in target region does not have a mappable type" }
+  }
+
+  ref = b;
+}
+
+int
+main()
+{
+  int a = 0;
+  int &ref_a = a;
+
+  #pragma acc parallel copy (a, ref_a) // { dg-error "reference types are not supported in OpenACC" }
+  {
+    ref_a = 5;
+  }
+
+  return a;
+}


GrÃÃe,
 Thomas

Attachment: pgp981W8Npkvl.pgp
Description: PGP signature


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