This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] field_decl_cmp
- From: Nathan Sidwell <nathan at acm dot org>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 12 Sep 2017 11:25:18 -0400
- Subject: [C PATCH] field_decl_cmp
- Authentication-results: sourceware.org; auth=none
Joseph,
in moving field_decl_cmp to the C FE, I noticed it checks for NULL
DECL_NAMES. Those don't occur.
This patch removes that checking, and also asserts that when we see
identically named decls, exactly one is a TYPE_DECL.
ok?
nathan
--
Nathan Sidwell
2017-09-12 Nathan Sidwell <nathan@acm.org>
* c-decl.c (field_decl_cmp): Don't handle NULL names. Refactor.
Index: c-decl.c
===================================================================
--- c-decl.c (revision 252023)
+++ c-decl.c (working copy)
@@ -7845,19 +7845,17 @@ warn_cxx_compat_finish_struct (tree fiel
static int
field_decl_cmp (const void *x_p, const void *y_p)
{
- const tree *const x = (const tree *) x_p;
- const tree *const y = (const tree *) y_p;
+ const tree x = *(const tree *) x_p;
+ const tree y = *(const tree *) y_p;
- if (DECL_NAME (*x) == DECL_NAME (*y))
- /* A nontype is "greater" than a type. */
- return (TREE_CODE (*y) == TYPE_DECL) - (TREE_CODE (*x) == TYPE_DECL);
- if (DECL_NAME (*x) == NULL_TREE)
- return -1;
- if (DECL_NAME (*y) == NULL_TREE)
- return 1;
- if (DECL_NAME (*x) < DECL_NAME (*y))
- return -1;
- return 1;
+ if (DECL_NAME (x) != DECL_NAME (y))
+ return DECL_NAME (x) < DECL_NAME (y) ? -1 : +1;
+
+ /* If the names are the same, exactly one must be a TYPE_DECL, and
+ that one is less than (before) the other one. */
+ gcc_checking_assert ((TREE_CODE (x) == TYPE_DECL)
+ != (TREE_CODE (y) == TYPE_DECL));
+ return TREE_CODE (x) == TYPE_DECL ? -1 : +1;
}
/* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.