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  <nat...@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.

Reply via email to