On 09/12/2017 12:48 PM, Joseph Myers wrote:
I'd be concerned about the possibility of a qsort implementation that calls the comparison function with two pointers to the same object (as far as I can tell, it's valid for qsort to do that). That is, I think you need to check for the two DECLs being the same DECL, before asserting their names are different.
I suppose we can drop the assert. That does leave it returning +1 in the case you're concerned about, but I don't really see the need to tell such a stupid qsort that the things are unordered.
nathan -- Nathan Sidwell
2017-09-15 Nathan Sidwell <nat...@acm.org> * c-decl.c (field_decl_cmp): No need to handle NULL or TYPE_DECLs. Index: c-decl.c =================================================================== --- c-decl.c (revision 252833) +++ c-decl.c (working copy) @@ -7845,19 +7845,10 @@ 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; + return DECL_NAME (x) < DECL_NAME (y) ? -1 : +1; } /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.