Previously, name-list properties specified as identifiers were stored
in the TREE_PURPOSE/OMP_TP_NAME slot, while those specified as strings
were stored in the TREE_VALUE/OMP_TP_VALUE slot.  This patch puts both
representations in OMP_TP_VALUE with a magic cookie in OMP_TP_NAME.

gcc/ChangeLog
        * omp-general.h (OMP_TP_NAMELIST_NODE): New.
        * omp-general.cc (omp_context_name_list_prop): Move earlier
        in the file, and adjust for new representation.
        (omp_check_context_selector): Adjust this too.
        (omp_context_selector_props_compare): Likewise.

gcc/c/ChangeLog
        * c-parser.cc (c_parser_omp_context_selector): Adjust for new
        namelist property representation.

gcc/cp/ChangeLog
        * parser.cc (cp_parser_omp_context_selector): Adjust for new
        namelist property representation.
        * pt.cc (tsubst_attribute): Likewise.

gcc/fortran/ChangeLog
        * trans-openmp.cc (gfc_trans_omp_declare_varaint): Adjust for
        new namelist property representation.
---
 gcc/c/c-parser.cc           |  5 ++-
 gcc/cp/parser.cc            |  5 ++-
 gcc/cp/pt.cc                |  4 +-
 gcc/fortran/trans-openmp.cc |  5 ++-
 gcc/omp-general.cc          | 84 +++++++++++++++++++++----------------
 gcc/omp-general.h           |  1 +
 6 files changed, 61 insertions(+), 43 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 9a17a8c5760..7fe449dc54a 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -24538,11 +24538,12 @@ c_parser_omp_context_selector (c_parser *parser, tree 
set, tree parms)
            case CTX_PROPERTY_NAME_LIST:
              do
                {
-                 tree prop = NULL_TREE, value = NULL_TREE;
+                 tree prop = OMP_TP_NAMELIST_NODE;
+                 tree value = NULL_TREE;
                  if (c_parser_next_token_is (parser, CPP_KEYWORD)
                      || c_parser_next_token_is (parser, CPP_NAME))
                    {
-                     prop = c_parser_peek_token (parser)->value;
+                     value = c_parser_peek_token (parser)->value;
                      c_parser_consume_token (parser);
                    }
                  else if (c_parser_next_token_is (parser, CPP_STRING))
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 9d4ae9726e5..eb1b0f26003 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -47539,11 +47539,12 @@ cp_parser_omp_context_selector (cp_parser *parser, 
tree set, bool has_parms_p)
            case CTX_PROPERTY_NAME_LIST:
              do
                {
-                 tree prop = NULL_TREE, value = NULL_TREE;
+                 tree prop = OMP_TP_NAMELIST_NODE;
+                 tree value = NULL_TREE;
                  if (cp_lexer_next_token_is (parser->lexer, CPP_KEYWORD)
                      || cp_lexer_next_token_is (parser->lexer, CPP_NAME))
                    {
-                     prop = cp_lexer_peek_token (parser->lexer)->u.value;
+                     value = cp_lexer_peek_token (parser->lexer)->u.value;
                      cp_lexer_consume_token (parser->lexer);
                    }
                  else if (cp_lexer_next_token_is (parser->lexer, CPP_STRING))
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 2541ad95cc1..ca4975dcd6f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -11869,7 +11869,9 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
                    }
                  properties = copy_list (OMP_TS_PROPERTIES (ts));
                  for (tree p = properties; p; p = TREE_CHAIN (p))
-                   if (OMP_TP_VALUE (p))
+                   if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE)
+                     continue;
+                   else if (OMP_TP_VALUE (p))
                      {
                        bool allow_string
                          = (OMP_TS_ID (ts) != condition || set[0] != 'u');
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index fe8044a57cd..60154ff3751 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -8235,9 +8235,10 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns)
                      break;
                    case CTX_PROPERTY_NAME_LIST:
                      {
-                       tree prop = NULL_TREE, value = NULL_TREE;
+                       tree prop = OMP_TP_NAMELIST_NODE;
+                       tree value = NULL_TREE;
                        if (otp->is_name)
-                         prop = get_identifier (otp->name);
+                         value = get_identifier (otp->name);
                        else
                          value = gfc_conv_constant_to_tree (otp->expr);
 
diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index 75980fcf4da..156508eabb5 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1114,6 +1114,30 @@ omp_maybe_offloaded (void)
   return false;
 }
 
+/* Return a name from PROP, a property in selectors accepting
+   name lists.  */
+
+static const char *
+omp_context_name_list_prop (tree prop)
+{
+  gcc_assert (OMP_TP_NAME (prop) == OMP_TP_NAMELIST_NODE);
+  tree val = OMP_TP_VALUE (prop);
+  switch (TREE_CODE (val))
+    {
+    case IDENTIFIER_NODE:
+      return IDENTIFIER_POINTER (val);
+    case STRING_CST:
+      {
+       const char *ret = TREE_STRING_POINTER (val);
+       if ((size_t) TREE_STRING_LENGTH (val)
+           == strlen (ret) + (lang_GNU_Fortran () ? 0 : 1))
+         return ret;
+       return NULL;
+      }
+    default:
+      return NULL;
+    }
+}
 
 /* Diagnose errors in an OpenMP context selector, return CTX if
    it is correct or error_mark_node otherwise.  */
@@ -1198,23 +1222,29 @@ omp_check_context_selector (location_t loc, tree ctx)
                                    "atomic_default_mem_order");
                          return error_mark_node;
                        }
+                     else if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE
+                              && (TREE_CODE (OMP_TP_VALUE (p)) == STRING_CST))
+                       warning_at (loc, 0,
+                                   "unknown property %qE of %qs selector",
+                                   OMP_TP_VALUE (p),
+                                   props[i].selector);
+                     else if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE)
+                       warning_at (loc, 0,
+                                   "unknown property %qs of %qs selector",
+                                   omp_context_name_list_prop (p),
+                                   props[i].selector);
                      else if (OMP_TP_NAME (p))
                        warning_at (loc, OPT_Wopenmp,
                                    "unknown property %qs of %qs selector",
                                    IDENTIFIER_POINTER (OMP_TP_NAME (p)),
                                    props[i].selector);
-                     else
-                       warning_at (loc, OPT_Wopenmp,
-                                   "unknown property %qE of %qs selector",
-                                   OMP_TP_VALUE (p), props[i].selector);
                      break;
                    }
-                 else if (OMP_TP_NAME (p) == NULL_TREE)
+                 else if (OMP_TP_NAME (p) == OMP_TP_NAMELIST_NODE)
+                   /* Property-list traits.  */
                    {
-                     const char *str = TREE_STRING_POINTER (OMP_TP_VALUE (p));
-                     if (!strcmp (str, props[i].props[j])
-                         && ((size_t) TREE_STRING_LENGTH (OMP_TP_VALUE (p))
-                             == strlen (str) + (lang_GNU_Fortran () ? 0 : 1)))
+                     const char *str = omp_context_name_list_prop (p);
+                     if (str && !strcmp (str, props[i].props[j]))
                        break;
                    }
                  else if (!strcmp (IDENTIFIER_POINTER (OMP_TP_NAME (p)),
@@ -1277,24 +1307,6 @@ make_trait_property (tree name, tree value, tree chain)
   return tree_cons (name, value, chain);
 }
 
-/* Return a name from PROP, a property in selectors accepting
-   name lists.  */
-
-static const char *
-omp_context_name_list_prop (tree prop)
-{
-  if (OMP_TP_NAME (prop))
-    return IDENTIFIER_POINTER (OMP_TP_NAME (prop));
-  else
-    {
-      const char *ret = TREE_STRING_POINTER (OMP_TP_VALUE (prop));
-      if ((size_t) TREE_STRING_LENGTH (OMP_TP_VALUE (prop))
-         == strlen (ret) + (lang_GNU_Fortran () ? 0 : 1))
-       return ret;
-      return NULL;
-    }
-}
-
 /* Return 1 if context selector matches the current OpenMP context, 0
    if it does not and -1 if it is unknown and need to be determined later.
    Some properties can be checked right away during parsing (this routine),
@@ -1793,18 +1805,18 @@ omp_context_selector_props_compare (const char *set, 
const char *sel,
                  if (simple_cst_equal (OMP_TP_VALUE (p1), OMP_TP_VALUE (p2)))
                    break;
                }
+             else if (OMP_TP_NAME (p1) == OMP_TP_NAMELIST_NODE)
+               {
+                 /* Handle string constant vs identifier comparison for
+                    name-list properties.  */
+                 const char *n1 = omp_context_name_list_prop (p1);
+                 const char *n2 = omp_context_name_list_prop (p2);
+                 if (n1 && n2 && !strcmp (n1, n2))
+                   break;
+               }
              else
                break;
            }
-         else
-           {
-             /* Handle string constant vs identifier comparison for
-                name-list properties.  */
-             const char *n1 = omp_context_name_list_prop (p1);
-             const char *n2 = omp_context_name_list_prop (p2);
-             if (n1 && n2 && !strcmp (n1, n2))
-               break;
-           }
        if (p2 == NULL_TREE)
          {
            int r = pass ? -1 : 1;
diff --git a/gcc/omp-general.h b/gcc/omp-general.h
index 28a9c0e6e17..dc5e5f6ba1f 100644
--- a/gcc/omp-general.h
+++ b/gcc/omp-general.h
@@ -112,6 +112,7 @@ struct omp_for_data
    OMP_TS_SCORE_NODE.  */
 
 #define OMP_TS_SCORE_NODE integer_minus_one_node
+#define OMP_TP_NAMELIST_NODE integer_one_node
 
 #define OMP_TSS_ID(NODE) \
   TREE_PURPOSE (NODE)
-- 
2.31.1

Reply via email to