* RFA: PATCH to add id_strcmp helper function
@ 2017-05-19 2:32 Jason Merrill
2017-05-19 3:13 ` Martin Sebor
0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2017-05-19 2:32 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 307 bytes --]
I got tired of writing strcmp (IDENTIFIER_POINTER and decided to wrap
it in an inline function. I decided to use "id_strcmp" instead of
just overloading strcmp, but I don't feel strongly about that choice.
The second patch changes all existing uses of that pattern to use the
new function.
OK for trunk?
[-- Attachment #2: id-strcmp.diff --]
[-- Type: text/plain, Size: 766 bytes --]
commit c909315aa35130b84df9304b4799801af05a4e35
Author: Jason Merrill <jason@redhat.com>
Date: Thu May 18 15:23:27 2017 -0400
* tree.h (id_strcmp): New.
diff --git a/gcc/tree.h b/gcc/tree.h
index c6e883c..0f01149 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3618,6 +3618,20 @@ tree_operand_check_code (const_tree __t, enum tree_code __code, int __i,
#endif
+/* strcmp of an identifier and a C string. */
+
+inline int
+id_strcmp (const_tree id, const char *str)
+{
+ return strcmp (IDENTIFIER_POINTER (id), str);
+}
+
+inline int
+id_strcmp (const char *str, const_tree id)
+{
+ return strcmp (str, IDENTIFIER_POINTER (id));
+}
+
#define error_mark_node global_trees[TI_ERROR_MARK]
#define intQI_type_node global_trees[TI_INTQI_TYPE]
[-- Attachment #3: use-id-strcmp.diff --]
[-- Type: text/plain, Size: 13253 bytes --]
commit 7811924e4048b36b3273bcd606eef78a25b52d53
Author: Jason Merrill <jason@redhat.com>
Date: Thu May 18 16:15:51 2017 -0400
use-id-strcmp
diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c
index 18c5ccf..939cbe3 100644
--- a/gcc/c-family/c-ada-spec.c
+++ b/gcc/c-family/c-ada-spec.c
@@ -1799,7 +1799,7 @@ is_char_array (tree t)
tmp = TREE_TYPE (tmp);
return num_dim == 1 && TREE_CODE (tmp) == INTEGER_TYPE
- && !strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (tmp))), "char");
+ && !id_strcmp (DECL_NAME (TYPE_NAME (tmp)), "char");
}
/* Dump in BUFFER an array type T in Ada syntax. Assume that the "type"
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index bc36626..e9fbdcd 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -514,7 +514,7 @@ handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
name = targetm.strip_name_encoding (name);
- if (strcmp (name, IDENTIFIER_POINTER (newname)))
+ if (id_strcmp (newname, name))
warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
"conflict with previous rename");
}
@@ -587,7 +587,7 @@ maybe_apply_renaming_pragma (tree decl, tree asmname)
if (DECL_NAME (decl) == p->oldname)
{
/* Only warn if there is a conflict. */
- if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
+ if (id_strcmp (p->newname, oldname))
warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
"conflict with previous rename");
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 011b389..7af6d8b 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2938,7 +2938,7 @@ struct GTY(()) lang_decl {
template function. */
#define DECL_PRETTY_FUNCTION_P(NODE) \
(DECL_NAME (NODE) \
- && !strcmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__PRETTY_FUNCTION__"))
+ && !id_strcmp (DECL_NAME (NODE), "__PRETTY_FUNCTION__"))
/* Nonzero if the variable was declared to be thread-local.
We need a special C++ version of this test because the middle-end
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 48a91cb..2bc0993 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -824,7 +824,7 @@ grokfield (const cp_declarator *declarator,
}
if (IDENTIFIER_POINTER (name)[0] == '_'
- && ! strcmp (IDENTIFIER_POINTER (name), "_vptr"))
+ && ! id_strcmp (name, "_vptr"))
error ("member %qD conflicts with virtual function table field name",
value);
}
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index e8136d3..312890a 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2151,7 +2151,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
pp_cxx_dot (pp);
}
else if (TREE_CODE (ob) != PARM_DECL
- || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
+ || id_strcmp (DECL_NAME (ob), "this"))
{
dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
pp_cxx_arrow (pp);
@@ -2234,7 +2234,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
ob = TREE_OPERAND (ob, 0);
if (TREE_CODE (ob) != PARM_DECL
|| (DECL_NAME (ob)
- && strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this")))
+ && id_strcmp (DECL_NAME (ob), "this")))
{
dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
if (TREE_CODE (TREE_TYPE (ob)) == REFERENCE_TYPE)
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 42290fe..4b4c6d8 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -2900,7 +2900,7 @@ write_expression (tree expr)
write_template_arg_literal (expr);
else if (code == PARM_DECL && DECL_ARTIFICIAL (expr))
{
- gcc_assert (!strcmp ("this", IDENTIFIER_POINTER (DECL_NAME (expr))));
+ gcc_assert (!id_strcmp (DECL_NAME (expr), "this"));
write_string ("fpT");
}
else if (code == PARM_DECL)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index c0e6254..0e05016 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -3201,7 +3201,7 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id,
"-std=c++11 or -std=gnu++11");
else if (cxx_dialect < cxx11
&& TREE_CODE (id) == IDENTIFIER_NODE
- && !strcmp (IDENTIFIER_POINTER (id), "thread_local"))
+ && !id_strcmp (id, "thread_local"))
inform (location, "C++11 %<thread_local%> only available with "
"-std=c++11 or -std=gnu++11");
else if (!flag_concepts && id == ridpointers[(int)RID_CONCEPT])
@@ -7823,7 +7823,7 @@ cp_parser_unary_expression (cp_parser *parser, cp_id_kind * pidk,
/* ISO C++ defines alignof only with types, not with
expressions. So pedwarn if alignof is used with a non-
type expression. However, __alignof__ is ok. */
- if (!strcmp (IDENTIFIER_POINTER (token->u.value), "alignof"))
+ if (!id_strcmp (token->u.value, "alignof"))
pedwarn (token->location, OPT_Wpedantic,
"ISO C++ does not allow %<alignof%> "
"with a non-type");
@@ -20389,17 +20389,17 @@ cp_parser_virt_specifier_seq_opt (cp_parser* parser)
/* See if it's a virt-specifier-qualifier. */
if (token->type != CPP_NAME)
break;
- if (!strcmp (IDENTIFIER_POINTER(token->u.value), "override"))
+ if (!id_strcmp (token->u.value, "override"))
{
maybe_warn_cpp0x (CPP0X_OVERRIDE_CONTROLS);
virt_specifier = VIRT_SPEC_OVERRIDE;
}
- else if (!strcmp (IDENTIFIER_POINTER(token->u.value), "final"))
+ else if (!id_strcmp (token->u.value, "final"))
{
maybe_warn_cpp0x (CPP0X_OVERRIDE_CONTROLS);
virt_specifier = VIRT_SPEC_FINAL;
}
- else if (!strcmp (IDENTIFIER_POINTER(token->u.value), "__final"))
+ else if (!id_strcmp (token->u.value, "__final"))
{
virt_specifier = VIRT_SPEC_FINAL;
}
@@ -27636,7 +27636,7 @@ static bool
token_is__thread (cp_token *token)
{
gcc_assert (token->keyword == RID_THREAD);
- return !strcmp (IDENTIFIER_POINTER (token->u.value), "__thread");
+ return !id_strcmp (token->u.value, "__thread");
}
/* Set the location for a declarator specifier and check if it is
@@ -31246,7 +31246,7 @@ cp_parser_oacc_shape_clause (cp_parser *parser, omp_clause_code kind,
}
/* Worker num: argument and vector length: arguments. */
else if (cp_lexer_next_token_is (lexer, CPP_NAME)
- && strcmp (id, IDENTIFIER_POINTER (next->u.value)) == 0
+ && id_strcmp (next->u.value, id) == 0
&& cp_lexer_nth_token_is (lexer, 2, CPP_COLON))
{
cp_lexer_consume_token (lexer); /* id */
@@ -37107,9 +37107,9 @@ cp_parser_omp_declare_reduction (cp_parser *parser, cp_token *pragma_tok,
else if (ARITHMETIC_TYPE_P (type)
&& (orig_reduc_id == NULL_TREE
|| (TREE_CODE (type) != COMPLEX_TYPE
- && (strcmp (IDENTIFIER_POINTER (orig_reduc_id),
+ && (id_strcmp (orig_reduc_id,
"min") == 0
- || strcmp (IDENTIFIER_POINTER (orig_reduc_id),
+ || id_strcmp (orig_reduc_id,
"max") == 0))))
error_at (loc, "predeclared arithmetic type %qT in "
"%<#pragma omp declare reduction%>", type);
@@ -38647,15 +38647,15 @@ cp_parser_cilk_simd_clause_name (cp_parser *parser)
clause_type = PRAGMA_CILK_CLAUSE_PRIVATE;
else if (!token->u.value || token->type != CPP_NAME)
return PRAGMA_CILK_CLAUSE_NONE;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "vectorlength"))
+ else if (!id_strcmp (token->u.value, "vectorlength"))
clause_type = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "linear"))
+ else if (!id_strcmp (token->u.value, "linear"))
clause_type = PRAGMA_CILK_CLAUSE_LINEAR;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "firstprivate"))
+ else if (!id_strcmp (token->u.value, "firstprivate"))
clause_type = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "lastprivate"))
+ else if (!id_strcmp (token->u.value, "lastprivate"))
clause_type = PRAGMA_CILK_CLAUSE_LASTPRIVATE;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "reduction"))
+ else if (!id_strcmp (token->u.value, "reduction"))
clause_type = PRAGMA_CILK_CLAUSE_REDUCTION;
else
return PRAGMA_CILK_CLAUSE_NONE;
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index fa02b27..1f742ec 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2887,7 +2887,7 @@ begin_class_definition (tree t)
if (ns && TREE_CODE (ns) == NAMESPACE_DECL
&& DECL_CONTEXT (ns) == std_node
&& DECL_NAME (ns)
- && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns)), "decimal"))
+ && !id_strcmp (DECL_NAME (ns), "decimal"))
{
const char *n = TYPE_NAME_STRING (t);
if ((strcmp (n, "decimal32") == 0)
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 5ff45eb..d342175 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -20621,7 +20621,7 @@ add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
targetm.dwarf_calling_convention (TREE_TYPE (decl)));
if (is_fortran ()
- && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
+ && !id_strcmp (DECL_ASSEMBLER_NAME (decl), "MAIN__"))
{
/* DWARF 2 doesn't provide a way to identify a program's source-level
entry point. DW_AT_calling_convention attributes are only meant
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index c5d8a6e..96382ef 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -3924,7 +3924,7 @@ get_hsa_kernel_dispatch_offset (const char *field_name)
for (tree chain = TYPE_FIELDS (*hsa_kernel_dispatch_type);
chain != NULL_TREE; chain = TREE_CHAIN (chain))
- if (strcmp (field_name, IDENTIFIER_POINTER (DECL_NAME (chain))) == 0)
+ if (id_strcmp (DECL_NAME (chain), field_name) == 0)
return int_byte_position (chain);
gcc_unreachable ();
diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index aa3a236..5bce835 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -2359,7 +2359,7 @@ is_cxa_pure_virtual_p (tree target)
{
return target && TREE_CODE (TREE_TYPE (target)) != METHOD_TYPE
&& DECL_NAME (target)
- && !strcmp (IDENTIFIER_POINTER (DECL_NAME (target)),
+ && !id_strcmp (DECL_NAME (target),
"__cxa_pure_virtual");
}
diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index 7a7c747..5dad9f3 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -4366,9 +4366,9 @@ expand_cilk_for (struct omp_region *region, struct omp_for_data *fd)
tree t, low_val = NULL_TREE, high_val = NULL_TREE;
for (t = DECL_ARGUMENTS (child_fndecl); t; t = TREE_CHAIN (t))
{
- if (!strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__high"))
+ if (!id_strcmp (DECL_NAME (t), "__high"))
high_val = t;
- else if (!strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__low"))
+ else if (!id_strcmp (DECL_NAME (t), "__low"))
low_val = t;
}
gcc_assert (low_val && high_val);
diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c
index 99589d4..137596b 100644
--- a/gcc/omp-simd-clone.c
+++ b/gcc/omp-simd-clone.c
@@ -417,7 +417,7 @@ simd_clone_mangle (struct cgraph_node *node,
if the simdlen is assumed to be 8 for the first one, etc. */
for (struct cgraph_node *clone = node->simd_clones; clone;
clone = clone->simdclone->next_clone)
- if (strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (clone->decl)),
+ if (id_strcmp (DECL_ASSEMBLER_NAME (clone->decl),
str) == 0)
return NULL_TREE;
diff --git a/gcc/read-rtl-function.c b/gcc/read-rtl-function.c
index c5027971..8b92817 100644
--- a/gcc/read-rtl-function.c
+++ b/gcc/read-rtl-function.c
@@ -536,7 +536,7 @@ static tree
find_param_by_name (tree fndecl, const char *name)
{
for (tree arg = DECL_ARGUMENTS (fndecl); arg; arg = TREE_CHAIN (arg))
- if (strcmp (name, IDENTIFIER_POINTER (DECL_NAME (arg))) == 0)
+ if (id_strcmp (DECL_NAME (arg), name) == 0)
return arg;
return NULL_TREE;
}
@@ -1324,7 +1324,7 @@ function_reader::parse_mem_expr (const char *desc)
int i;
tree t;
FOR_EACH_VEC_ELT (m_fake_scope, i, t)
- if (strcmp (desc, IDENTIFIER_POINTER (DECL_NAME (t))) == 0)
+ if (id_strcmp (DECL_NAME (t), desc) == 0)
return t;
/* Not found? Create it.
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 2300e98..0ba6625 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -2379,7 +2379,7 @@ chkp_get_bound_for_parm (tree parm)
to use zero bounds for input arguments of main
function. */
else if (flag_chkp_zero_input_bounds_for_main
- && strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (orig_decl)),
+ && id_strcmp (DECL_ASSEMBLER_NAME (orig_decl),
"main") == 0)
bounds = chkp_get_zero_bounds ();
else if (BOUNDED_P (parm))
diff --git a/gcc/tree.c b/gcc/tree.c
index 327332b..042fa4a 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -6053,7 +6053,7 @@ private_is_attribute_p (const char *attr_name, size_t attr_len, const_tree ident
if (ident_len == attr_len)
{
- if (strcmp (attr_name, IDENTIFIER_POINTER (ident)) == 0)
+ if (id_strcmp (ident, attr_name) == 0)
return true;
}
else if (ident_len == attr_len + 4)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RFA: PATCH to add id_strcmp helper function
2017-05-19 2:32 RFA: PATCH to add id_strcmp helper function Jason Merrill
@ 2017-05-19 3:13 ` Martin Sebor
2017-05-24 1:45 ` Jason Merrill
0 siblings, 1 reply; 5+ messages in thread
From: Martin Sebor @ 2017-05-19 3:13 UTC (permalink / raw)
To: Jason Merrill, gcc-patches List
On 05/18/2017 08:30 PM, Jason Merrill wrote:
> I got tired of writing strcmp (IDENTIFIER_POINTER and decided to wrap
> it in an inline function. I decided to use "id_strcmp" instead of
> just overloading strcmp, but I don't feel strongly about that choice.
>
> The second patch changes all existing uses of that pattern to use the
> new function.
>
> OK for trunk?
Since all the uses are of the form !id_strcmp(), would taking
a step further and introducing a bool id_equal() be going too
far?
Besides being (arguably) easier to read, it would get around
the question of whether it should be !id_strcmp() or
id_strcmp == 0, or perhaps even 0 == id_strcmp().
Martin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RFA: PATCH to add id_strcmp helper function
2017-05-19 3:13 ` Martin Sebor
@ 2017-05-24 1:45 ` Jason Merrill
2017-06-09 20:07 ` Jason Merrill
0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2017-05-24 1:45 UTC (permalink / raw)
To: Martin Sebor; +Cc: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 792 bytes --]
On Thu, May 18, 2017 at 11:03 PM, Martin Sebor <msebor@gmail.com> wrote:
> On 05/18/2017 08:30 PM, Jason Merrill wrote:
>>
>> I got tired of writing strcmp (IDENTIFIER_POINTER and decided to wrap
>> it in an inline function. I decided to use "id_strcmp" instead of
>> just overloading strcmp, but I don't feel strongly about that choice.
>>
>> The second patch changes all existing uses of that pattern to use the
>> new function.
>>
>> OK for trunk?
>
>
> Since all the uses are of the form !id_strcmp(), would taking
> a step further and introducing a bool id_equal() be going too
> far?
>
> Besides being (arguably) easier to read, it would get around
> the question of whether it should be !id_strcmp() or
> id_strcmp == 0, or perhaps even 0 == id_strcmp().
Makes sense.
OK for trunk?
[-- Attachment #2: id-equal.diff --]
[-- Type: text/plain, Size: 15114 bytes --]
commit ca96d8533f808e8b8ebcd35ee699a90dcc2bf8cf
Author: Jason Merrill <jason@redhat.com>
Date: Thu May 18 15:23:27 2017 -0400
* tree.h (id_equal): New.
* dwarf2out.c, hsa-gen.c, ipa-devirt.c, omp-expand.c,
omp-simd-clone.c, read-rtl-function.c, tree-chkp.c, tree.c: Use it
instead of strcmp of IDENTIFIER_POINTER.
c-family/
* c-ada-spec.c, c-pragma.c: Use it.
cp/
* cp-tree.h, decl2.c, mangle.c, parser.c, pt.c, semantics.c: Use it.
* error.c: Use is_this_parameter.
diff --git a/gcc/c-family/c-ada-spec.c b/gcc/c-family/c-ada-spec.c
index 18c5ccf..6cf298a 100644
--- a/gcc/c-family/c-ada-spec.c
+++ b/gcc/c-family/c-ada-spec.c
@@ -1799,7 +1799,7 @@ is_char_array (tree t)
tmp = TREE_TYPE (tmp);
return num_dim == 1 && TREE_CODE (tmp) == INTEGER_TYPE
- && !strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (tmp))), "char");
+ && id_equal (DECL_NAME (TYPE_NAME (tmp)), "char");
}
/* Dump in BUFFER an array type T in Ada syntax. Assume that the "type"
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index bc36626..48b02b8 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -514,7 +514,7 @@ handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
name = targetm.strip_name_encoding (name);
- if (strcmp (name, IDENTIFIER_POINTER (newname)))
+ if (!id_equal (newname, name))
warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
"conflict with previous rename");
}
@@ -587,7 +587,7 @@ maybe_apply_renaming_pragma (tree decl, tree asmname)
if (DECL_NAME (decl) == p->oldname)
{
/* Only warn if there is a conflict. */
- if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
+ if (!id_equal (p->newname, oldname))
warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
"conflict with previous rename");
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 98ef023..7c46cad 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2960,7 +2960,7 @@ struct GTY(()) lang_decl {
template function. */
#define DECL_PRETTY_FUNCTION_P(NODE) \
(DECL_NAME (NODE) \
- && !strcmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__PRETTY_FUNCTION__"))
+ && id_equal (DECL_NAME (NODE), "__PRETTY_FUNCTION__"))
/* Nonzero if the variable was declared to be thread-local.
We need a special C++ version of this test because the middle-end
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 85310e0..29883da 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -827,7 +827,7 @@ grokfield (const cp_declarator *declarator,
}
if (IDENTIFIER_POINTER (name)[0] == '_'
- && ! strcmp (IDENTIFIER_POINTER (name), "_vptr"))
+ && id_equal (name, "_vptr"))
error ("member %qD conflicts with virtual function table field name",
value);
}
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 1ae25bb..b65cee4 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2149,8 +2149,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
flags | TFF_EXPR_IN_PARENS);
pp_cxx_dot (pp);
}
- else if (TREE_CODE (ob) != PARM_DECL
- || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this"))
+ else if (!is_this_parameter (ob))
{
dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
pp_cxx_arrow (pp);
@@ -2231,9 +2230,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
if (INDIRECT_REF_P (ob))
{
ob = TREE_OPERAND (ob, 0);
- if (TREE_CODE (ob) != PARM_DECL
- || (DECL_NAME (ob)
- && strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this")))
+ if (!is_this_parameter (ob))
{
dump_expr (pp, ob, flags | TFF_EXPR_IN_PARENS);
if (TREE_CODE (TREE_TYPE (ob)) == REFERENCE_TYPE)
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 42290fe..e866675 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -2900,7 +2900,7 @@ write_expression (tree expr)
write_template_arg_literal (expr);
else if (code == PARM_DECL && DECL_ARTIFICIAL (expr))
{
- gcc_assert (!strcmp ("this", IDENTIFIER_POINTER (DECL_NAME (expr))));
+ gcc_assert (id_equal (DECL_NAME (expr), "this"));
write_string ("fpT");
}
else if (code == PARM_DECL)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 4f2c2d5..a1ada02 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -3201,7 +3201,7 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id,
"-std=c++11 or -std=gnu++11");
else if (cxx_dialect < cxx11
&& TREE_CODE (id) == IDENTIFIER_NODE
- && !strcmp (IDENTIFIER_POINTER (id), "thread_local"))
+ && id_equal (id, "thread_local"))
inform (location, "C++11 %<thread_local%> only available with "
"-std=c++11 or -std=gnu++11");
else if (!flag_concepts && id == ridpointers[(int)RID_CONCEPT])
@@ -7823,7 +7823,7 @@ cp_parser_unary_expression (cp_parser *parser, cp_id_kind * pidk,
/* ISO C++ defines alignof only with types, not with
expressions. So pedwarn if alignof is used with a non-
type expression. However, __alignof__ is ok. */
- if (!strcmp (IDENTIFIER_POINTER (token->u.value), "alignof"))
+ if (id_equal (token->u.value, "alignof"))
pedwarn (token->location, OPT_Wpedantic,
"ISO C++ does not allow %<alignof%> "
"with a non-type");
@@ -20397,17 +20397,17 @@ cp_parser_virt_specifier_seq_opt (cp_parser* parser)
/* See if it's a virt-specifier-qualifier. */
if (token->type != CPP_NAME)
break;
- if (!strcmp (IDENTIFIER_POINTER(token->u.value), "override"))
+ if (id_equal (token->u.value, "override"))
{
maybe_warn_cpp0x (CPP0X_OVERRIDE_CONTROLS);
virt_specifier = VIRT_SPEC_OVERRIDE;
}
- else if (!strcmp (IDENTIFIER_POINTER(token->u.value), "final"))
+ else if (id_equal (token->u.value, "final"))
{
maybe_warn_cpp0x (CPP0X_OVERRIDE_CONTROLS);
virt_specifier = VIRT_SPEC_FINAL;
}
- else if (!strcmp (IDENTIFIER_POINTER(token->u.value), "__final"))
+ else if (id_equal (token->u.value, "__final"))
{
virt_specifier = VIRT_SPEC_FINAL;
}
@@ -27644,7 +27644,7 @@ static bool
token_is__thread (cp_token *token)
{
gcc_assert (token->keyword == RID_THREAD);
- return !strcmp (IDENTIFIER_POINTER (token->u.value), "__thread");
+ return id_equal (token->u.value, "__thread");
}
/* Set the location for a declarator specifier and check if it is
@@ -31254,7 +31254,7 @@ cp_parser_oacc_shape_clause (cp_parser *parser, omp_clause_code kind,
}
/* Worker num: argument and vector length: arguments. */
else if (cp_lexer_next_token_is (lexer, CPP_NAME)
- && strcmp (id, IDENTIFIER_POINTER (next->u.value)) == 0
+ && id_equal (next->u.value, id)
&& cp_lexer_nth_token_is (lexer, 2, CPP_COLON))
{
cp_lexer_consume_token (lexer); /* id */
@@ -37125,10 +37125,8 @@ cp_parser_omp_declare_reduction (cp_parser *parser, cp_token *pragma_tok,
else if (ARITHMETIC_TYPE_P (type)
&& (orig_reduc_id == NULL_TREE
|| (TREE_CODE (type) != COMPLEX_TYPE
- && (strcmp (IDENTIFIER_POINTER (orig_reduc_id),
- "min") == 0
- || strcmp (IDENTIFIER_POINTER (orig_reduc_id),
- "max") == 0))))
+ && (id_equal (orig_reduc_id, "min")
+ || id_equal (orig_reduc_id, "max")))))
error_at (loc, "predeclared arithmetic type %qT in "
"%<#pragma omp declare reduction%>", type);
else if (TREE_CODE (type) == FUNCTION_TYPE
@@ -38665,15 +38663,15 @@ cp_parser_cilk_simd_clause_name (cp_parser *parser)
clause_type = PRAGMA_CILK_CLAUSE_PRIVATE;
else if (!token->u.value || token->type != CPP_NAME)
return PRAGMA_CILK_CLAUSE_NONE;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "vectorlength"))
+ else if (id_equal (token->u.value, "vectorlength"))
clause_type = PRAGMA_CILK_CLAUSE_VECTORLENGTH;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "linear"))
+ else if (id_equal (token->u.value, "linear"))
clause_type = PRAGMA_CILK_CLAUSE_LINEAR;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "firstprivate"))
+ else if (id_equal (token->u.value, "firstprivate"))
clause_type = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "lastprivate"))
+ else if (id_equal (token->u.value, "lastprivate"))
clause_type = PRAGMA_CILK_CLAUSE_LASTPRIVATE;
- else if (!strcmp (IDENTIFIER_POINTER (token->u.value), "reduction"))
+ else if (id_equal (token->u.value, "reduction"))
clause_type = PRAGMA_CILK_CLAUSE_REDUCTION;
else
return PRAGMA_CILK_CLAUSE_NONE;
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 54de34b..49957f9 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -3426,7 +3426,7 @@ builtin_pack_fn_p (tree fn)
|| !DECL_IS_BUILTIN (fn))
return false;
- if (strcmp (IDENTIFIER_POINTER (DECL_NAME (fn)), "__integer_pack") == 0)
+ if (id_equal (DECL_NAME (fn), "__integer_pack"))
return true;
return false;
@@ -3504,7 +3504,7 @@ expand_builtin_pack_call (tree call, tree args, tsubst_flags_t complain,
tree fn = CALL_EXPR_FN (call);
- if (strcmp (IDENTIFIER_POINTER (DECL_NAME (fn)), "__integer_pack") == 0)
+ if (id_equal (DECL_NAME (fn), "__integer_pack"))
return expand_integer_pack (call, args, complain, in_decl);
return NULL_TREE;
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 1ba961e..0e9e348 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2882,7 +2882,7 @@ begin_class_definition (tree t)
if (ns && TREE_CODE (ns) == NAMESPACE_DECL
&& DECL_CONTEXT (ns) == std_node
&& DECL_NAME (ns)
- && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns)), "decimal"))
+ && id_equal (DECL_NAME (ns), "decimal"))
{
const char *n = TYPE_NAME_STRING (t);
if ((strcmp (n, "decimal32") == 0)
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 5ff45eb..7a42f8f 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -20621,7 +20621,7 @@ add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
targetm.dwarf_calling_convention (TREE_TYPE (decl)));
if (is_fortran ()
- && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
+ && id_equal (DECL_ASSEMBLER_NAME (decl), "MAIN__"))
{
/* DWARF 2 doesn't provide a way to identify a program's source-level
entry point. DW_AT_calling_convention attributes are only meant
diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c
index c5d8a6e..3aa65f3 100644
--- a/gcc/hsa-gen.c
+++ b/gcc/hsa-gen.c
@@ -3924,7 +3924,7 @@ get_hsa_kernel_dispatch_offset (const char *field_name)
for (tree chain = TYPE_FIELDS (*hsa_kernel_dispatch_type);
chain != NULL_TREE; chain = TREE_CHAIN (chain))
- if (strcmp (field_name, IDENTIFIER_POINTER (DECL_NAME (chain))) == 0)
+ if (id_equal (DECL_NAME (chain), field_name))
return int_byte_position (chain);
gcc_unreachable ();
diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index c7460ca..dc9232c 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -2359,7 +2359,7 @@ is_cxa_pure_virtual_p (tree target)
{
return target && TREE_CODE (TREE_TYPE (target)) != METHOD_TYPE
&& DECL_NAME (target)
- && !strcmp (IDENTIFIER_POINTER (DECL_NAME (target)),
+ && id_equal (DECL_NAME (target),
"__cxa_pure_virtual");
}
diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index 7a7c747..53d3d3f 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -4366,9 +4366,9 @@ expand_cilk_for (struct omp_region *region, struct omp_for_data *fd)
tree t, low_val = NULL_TREE, high_val = NULL_TREE;
for (t = DECL_ARGUMENTS (child_fndecl); t; t = TREE_CHAIN (t))
{
- if (!strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__high"))
+ if (id_equal (DECL_NAME (t), "__high"))
high_val = t;
- else if (!strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__low"))
+ else if (id_equal (DECL_NAME (t), "__low"))
low_val = t;
}
gcc_assert (low_val && high_val);
diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c
index 99589d4..3aa8b13 100644
--- a/gcc/omp-simd-clone.c
+++ b/gcc/omp-simd-clone.c
@@ -417,8 +417,7 @@ simd_clone_mangle (struct cgraph_node *node,
if the simdlen is assumed to be 8 for the first one, etc. */
for (struct cgraph_node *clone = node->simd_clones; clone;
clone = clone->simdclone->next_clone)
- if (strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (clone->decl)),
- str) == 0)
+ if (id_equal (DECL_ASSEMBLER_NAME (clone->decl), str))
return NULL_TREE;
return get_identifier (str);
diff --git a/gcc/read-rtl-function.c b/gcc/read-rtl-function.c
index c5027971..ec25051 100644
--- a/gcc/read-rtl-function.c
+++ b/gcc/read-rtl-function.c
@@ -536,7 +536,7 @@ static tree
find_param_by_name (tree fndecl, const char *name)
{
for (tree arg = DECL_ARGUMENTS (fndecl); arg; arg = TREE_CHAIN (arg))
- if (strcmp (name, IDENTIFIER_POINTER (DECL_NAME (arg))) == 0)
+ if (id_equal (DECL_NAME (arg), name))
return arg;
return NULL_TREE;
}
@@ -1324,7 +1324,7 @@ function_reader::parse_mem_expr (const char *desc)
int i;
tree t;
FOR_EACH_VEC_ELT (m_fake_scope, i, t)
- if (strcmp (desc, IDENTIFIER_POINTER (DECL_NAME (t))) == 0)
+ if (id_equal (DECL_NAME (t), desc))
return t;
/* Not found? Create it.
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 2300e98..172c28e 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -2379,8 +2379,7 @@ chkp_get_bound_for_parm (tree parm)
to use zero bounds for input arguments of main
function. */
else if (flag_chkp_zero_input_bounds_for_main
- && strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (orig_decl)),
- "main") == 0)
+ && id_equal (DECL_ASSEMBLER_NAME (orig_decl), "main"))
bounds = chkp_get_zero_bounds ();
else if (BOUNDED_P (parm))
{
diff --git a/gcc/tree.c b/gcc/tree.c
index db31620..d87d585 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -6050,7 +6050,7 @@ private_is_attribute_p (const char *attr_name, size_t attr_len, const_tree ident
if (ident_len == attr_len)
{
- if (strcmp (attr_name, IDENTIFIER_POINTER (ident)) == 0)
+ if (id_equal (ident, attr_name))
return true;
}
else if (ident_len == attr_len + 4)
diff --git a/gcc/tree.h b/gcc/tree.h
index c6e883c..c23a370 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3618,6 +3618,20 @@ tree_operand_check_code (const_tree __t, enum tree_code __code, int __i,
#endif
+/* True iff an identifier matches a C string. */
+
+inline bool
+id_equal (const_tree id, const char *str)
+{
+ return !strcmp (IDENTIFIER_POINTER (id), str);
+}
+
+inline bool
+id_equal (const char *str, const_tree id)
+{
+ return !strcmp (str, IDENTIFIER_POINTER (id));
+}
+
#define error_mark_node global_trees[TI_ERROR_MARK]
#define intQI_type_node global_trees[TI_INTQI_TYPE]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RFA: PATCH to add id_strcmp helper function
2017-05-24 1:45 ` Jason Merrill
@ 2017-06-09 20:07 ` Jason Merrill
2017-06-10 5:54 ` Richard Biener
0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2017-06-09 20:07 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches List
On Tue, May 23, 2017 at 5:52 PM, Jason Merrill <jason@redhat.com> wrote:
> On Thu, May 18, 2017 at 11:03 PM, Martin Sebor <msebor@gmail.com> wrote:
>> On 05/18/2017 08:30 PM, Jason Merrill wrote:
>>>
>>> I got tired of writing strcmp (IDENTIFIER_POINTER and decided to wrap
>>> it in an inline function. I decided to use "id_strcmp" instead of
>>> just overloading strcmp, but I don't feel strongly about that choice.
>>>
>>> The second patch changes all existing uses of that pattern to use the
>>> new function.
>>>
>>> OK for trunk?
>>
>>
>> Since all the uses are of the form !id_strcmp(), would taking
>> a step further and introducing a bool id_equal() be going too
>> far?
>>
>> Besides being (arguably) easier to read, it would get around
>> the question of whether it should be !id_strcmp() or
>> id_strcmp == 0, or perhaps even 0 == id_strcmp().
>
> Makes sense.
>
> OK for trunk?
Ping?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: RFA: PATCH to add id_strcmp helper function
2017-06-09 20:07 ` Jason Merrill
@ 2017-06-10 5:54 ` Richard Biener
0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2017-06-10 5:54 UTC (permalink / raw)
To: gcc-patches, Jason Merrill, Jakub Jelinek; +Cc: gcc-patches List
On June 9, 2017 10:07:36 PM GMT+02:00, Jason Merrill <jason@redhat.com> wrote:
>On Tue, May 23, 2017 at 5:52 PM, Jason Merrill <jason@redhat.com>
>wrote:
>> On Thu, May 18, 2017 at 11:03 PM, Martin Sebor <msebor@gmail.com>
>wrote:
>>> On 05/18/2017 08:30 PM, Jason Merrill wrote:
>>>>
>>>> I got tired of writing strcmp (IDENTIFIER_POINTER and decided to
>wrap
>>>> it in an inline function. I decided to use "id_strcmp" instead of
>>>> just overloading strcmp, but I don't feel strongly about that
>choice.
>>>>
>>>> The second patch changes all existing uses of that pattern to use
>the
>>>> new function.
>>>>
>>>> OK for trunk?
>>>
>>>
>>> Since all the uses are of the form !id_strcmp(), would taking
>>> a step further and introducing a bool id_equal() be going too
>>> far?
>>>
>>> Besides being (arguably) easier to read, it would get around
>>> the question of whether it should be !id_strcmp() or
>>> id_strcmp == 0, or perhaps even 0 == id_strcmp().
>>
>> Makes sense.
>>
>> OK for trunk?
>
>Ping?
OK.
Richard.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-06-10 5:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-19 2:32 RFA: PATCH to add id_strcmp helper function Jason Merrill
2017-05-19 3:13 ` Martin Sebor
2017-05-24 1:45 ` Jason Merrill
2017-06-09 20:07 ` Jason Merrill
2017-06-10 5:54 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).