Add 'gcc/tree.cc:user_omp_clause_code_name' [PR65095]

Message ID 874k43mqfb.fsf@euler.schwinge.homeip.net
State New
Headers
Series Add 'gcc/tree.cc:user_omp_clause_code_name' [PR65095] |

Commit Message

Thomas Schwinge March 12, 2022, 10:11 a.m. UTC
  Hi!

On 2022-02-17T13:33:45+0100, I wrote:
> On 2019-10-18T14:28:18+0200, I wrote:
>> On 2019-10-06T15:32:34-0700, Julian Brown <julian@codesourcery.com> wrote:
>>> This patch adds a function to pretty-print OpenACC clause names from
>>> OMP_CLAUSE_MAP_KINDs, for error output.
>>
>> Indeed talking about (OpenMP) 'map' clauses in an OpenACC context is not
>> quite ideal -- that's what PR65095 is about
>
>>> Previously approved as part of:
>>>
>>>   https://gcc.gnu.org/ml/gcc-patches/2018-12/msg01292.html
>
>
>> A few more comments, for later:
>>
>>>  gcc/c-family/c-common.h |  1 +
>>>  gcc/c-family/c-omp.c    | 33 +++++++++++++++++++++++++++++++++
>>
>> As I'd mentioned before: 'Eventually (that is, later), this should move
>> into generic code, next to the other "clause printing".
>
> As part of an ICE bug fix that I'm working on, I now need to use
> this in GCC middle end code.

Pushed to master branch commit 828335beb77676acffb5911e575672cb55beb2e9
"Add 'gcc/tree.cc:user_omp_clause_code_name' [PR65095]", see attached.


Grüße
 Thomas


-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Patch

From 828335beb77676acffb5911e575672cb55beb2e9 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Thu, 17 Feb 2022 12:46:57 +0100
Subject: [PATCH] Add 'gcc/tree.cc:user_omp_clause_code_name' [PR65095]

Re PR65095 "Adapt OpenMP diagnostic messages for OpenACC", move C/C++
front end 'gcc/c-family/c-omp.cc:c_omp_map_clause_name' to generic
'gcc/tree.cc:user_omp_clause_code_name' .  No functional change.

	PR other/65095
	gcc/
	* tree-core.h (user_omp_claus_code_name): Declare function.
	* tree.cc (user_omp_clause_code_name): New function.
	gcc/c/
	* c-typeck.cc (handle_omp_array_sections_1)
	(c_oacc_check_attachments): Call 'user_omp_clause_code_name'
	instead of 'c_omp_map_clause_name'.
	gcc/cp/
	* semantics.cc (handle_omp_array_sections_1)
	(cp_oacc_check_attachments): Call 'user_omp_clause_code_name'
	instead of 'c_omp_map_clause_name'.
	gcc/c-family/
	* c-common.h (c_omp_map_clause_name): Remove.
	* c-omp.cc (c_omp_map_clause_name): Remove.
---
 gcc/c-family/c-common.h |  1 -
 gcc/c-family/c-omp.cc   | 33 ---------------------------------
 gcc/c/c-typeck.cc       |  4 ++--
 gcc/cp/semantics.cc     |  4 ++--
 gcc/tree-core.h         |  1 +
 gcc/tree.cc             | 36 ++++++++++++++++++++++++++++++++++++
 6 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index a8d6f82bb2c..5f0b5d99d07 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1250,7 +1250,6 @@  extern enum omp_clause_default_kind c_omp_predetermined_sharing (tree);
 extern enum omp_clause_defaultmap_kind c_omp_predetermined_mapping (tree);
 extern tree c_omp_check_context_selector (location_t, tree);
 extern void c_omp_mark_declare_variant (location_t, tree, tree);
-extern const char *c_omp_map_clause_name (tree, bool);
 extern void c_omp_adjust_map_clauses (tree, bool);
 
 enum c_omp_directive_kind {
diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc
index cd9d86641e1..777cdc65572 100644
--- a/gcc/c-family/c-omp.cc
+++ b/gcc/c-family/c-omp.cc
@@ -2996,39 +2996,6 @@  c_omp_predetermined_mapping (tree decl)
 }
 
 
-/* For OpenACC, the OMP_CLAUSE_MAP_KIND of an OMP_CLAUSE_MAP is used internally
-   to distinguish clauses as seen by the user.  Return the "friendly" clause
-   name for error messages etc., where possible.  See also
-   c/c-parser.cc:c_parser_oacc_data_clause and
-   cp/parser.cc:cp_parser_oacc_data_clause.  */
-
-const char *
-c_omp_map_clause_name (tree clause, bool oacc)
-{
-  if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
-    switch (OMP_CLAUSE_MAP_KIND (clause))
-    {
-    case GOMP_MAP_FORCE_ALLOC:
-    case GOMP_MAP_ALLOC: return "create";
-    case GOMP_MAP_FORCE_TO:
-    case GOMP_MAP_TO: return "copyin";
-    case GOMP_MAP_FORCE_FROM:
-    case GOMP_MAP_FROM: return "copyout";
-    case GOMP_MAP_FORCE_TOFROM:
-    case GOMP_MAP_TOFROM: return "copy";
-    case GOMP_MAP_RELEASE: return "delete";
-    case GOMP_MAP_FORCE_PRESENT: return "present";
-    case GOMP_MAP_ATTACH: return "attach";
-    case GOMP_MAP_FORCE_DETACH:
-    case GOMP_MAP_DETACH: return "detach";
-    case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
-    case GOMP_MAP_LINK: return "link";
-    case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
-    default: break;
-    }
-  return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
-}
-
 /* Used to merge map clause information in c_omp_adjust_map_clauses.  */
 struct map_clause
 {
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 54b0b0d369b..c0812de84b4 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -13373,7 +13373,7 @@  handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
 	{
 	  error_at (OMP_CLAUSE_LOCATION (c),
 		    "expected single pointer in %qs clause",
-		    c_omp_map_clause_name (c, ort == C_ORT_ACC));
+		    user_omp_clause_code_name (c, ort == C_ORT_ACC));
 	  return error_mark_node;
 	}
     }
@@ -14096,7 +14096,7 @@  c_oacc_check_attachments (tree c)
       if (TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE)
 	{
 	  error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
-		    c_omp_map_clause_name (c, true));
+		    user_omp_clause_code_name (c, true));
 	  return true;
 	}
     }
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 21740064d3d..da270e8f05c 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -5195,7 +5195,7 @@  handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
 	{
 	  error_at (OMP_CLAUSE_LOCATION (c),
 		    "expected single pointer in %qs clause",
-		    c_omp_map_clause_name (c, ort == C_ORT_ACC));
+		    user_omp_clause_code_name (c, ort == C_ORT_ACC));
 	  return error_mark_node;
 	}
     }
@@ -6653,7 +6653,7 @@  cp_oacc_check_attachments (tree c)
       if (TREE_CODE (type) != POINTER_TYPE)
 	{
 	  error_at (OMP_CLAUSE_LOCATION (c), "expected pointer in %qs clause",
-		    c_omp_map_clause_name (c, true));
+		    user_omp_clause_code_name (c, true));
 	  return true;
 	}
     }
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index 4530bd8c2c7..f1c2b6413a3 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -2283,6 +2283,7 @@  extern const char * built_in_names[(int) END_BUILTINS];
 /* Number of operands and names for each OMP_CLAUSE node.  */
 extern unsigned const char omp_clause_num_ops[];
 extern const char * const omp_clause_code_name[];
+extern const char *user_omp_clause_code_name (tree, bool);
 
 /* A vector of all translation-units.  */
 extern GTY (()) vec<tree, va_gc> *all_translation_units;
diff --git a/gcc/tree.cc b/gcc/tree.cc
index d6f900c53b4..b8017af6cfc 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -69,6 +69,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "gimple-fold.h"
 #include "escaped_string.h"
 #include "gimple-range.h"
+#include "gomp-constants.h"
 
 /* Tree code classes.  */
 
@@ -439,6 +440,41 @@  const char * const omp_clause_code_name[] =
   "nohost",
 };
 
+/* Unless specific to OpenACC, we tend to internally maintain OpenMP-centric
+   clause names, but for use in diagnostics etc. would like to use the "user"
+   clause names.  */
+
+const char *
+user_omp_clause_code_name (tree clause, bool oacc)
+{
+  /* For OpenACC, the 'OMP_CLAUSE_MAP_KIND' of an 'OMP_CLAUSE_MAP' is used to
+     distinguish clauses as seen by the user.  See also where front ends do
+     'build_omp_clause' with 'OMP_CLAUSE_MAP'.  */
+  if (oacc && OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP)
+    switch (OMP_CLAUSE_MAP_KIND (clause))
+      {
+      case GOMP_MAP_FORCE_ALLOC:
+      case GOMP_MAP_ALLOC: return "create";
+      case GOMP_MAP_FORCE_TO:
+      case GOMP_MAP_TO: return "copyin";
+      case GOMP_MAP_FORCE_FROM:
+      case GOMP_MAP_FROM: return "copyout";
+      case GOMP_MAP_FORCE_TOFROM:
+      case GOMP_MAP_TOFROM: return "copy";
+      case GOMP_MAP_RELEASE: return "delete";
+      case GOMP_MAP_FORCE_PRESENT: return "present";
+      case GOMP_MAP_ATTACH: return "attach";
+      case GOMP_MAP_FORCE_DETACH:
+      case GOMP_MAP_DETACH: return "detach";
+      case GOMP_MAP_DEVICE_RESIDENT: return "device_resident";
+      case GOMP_MAP_LINK: return "link";
+      case GOMP_MAP_FORCE_DEVICEPTR: return "deviceptr";
+      default: break;
+      }
+
+  return omp_clause_code_name[OMP_CLAUSE_CODE (clause)];
+}
+
 
 /* Return the tree node structure used by tree code CODE.  */
 
-- 
2.34.1