From patchwork Tue Sep 12 14:28:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 812874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461931-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="X6FKcMkf"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xs6bl1HY9z9sNV for ; Wed, 13 Sep 2017 00:28:34 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=L9/QKa/5JZ70jV/T/8Q2LaQq//LCeCG6dgdQTZ1ttHOqbkK8CV 6Di51BLGAxOvqkM4VeJOV0xOIKdVq7WQ9Scma5vij5O4eoXT/S/kk8p3GyNd1YQB QzC/0HoSVPCAfEd4TZyayXJORisrGnJvEufm9KL/id0/y7T7L+zFl4EmE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=6FGG7Ctb+qbWopxz2AwN6frrimA=; b=X6FKcMkf8Kh/FfyihCM+ zh38fltUUp/3lQbNYoimSj5L6opj/h3dv1BVIV+QkmQVeaGszJ4PLMnSuxwq+Nqb 5a+YoE65nvpnCtnk+Yot35DcBhLTh2WlaADjRG863YQycuJUIUAjM5/Z5VWfun9b ndwBeswxKB12kFeBjuyJI2s= Received: (qmail 56128 invoked by alias); 12 Sep 2017 14:28:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 56116 invoked by uid 89); 12 Sep 2017 14:28:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-yw0-f176.google.com Received: from mail-yw0-f176.google.com (HELO mail-yw0-f176.google.com) (209.85.161.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Sep 2017 14:28:24 +0000 Received: by mail-yw0-f176.google.com with SMTP id v72so26465891ywa.3 for ; Tue, 12 Sep 2017 07:28:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version:content-language; bh=uwlcHi0MLT084GVTMKGga4BFIRXTvbV98GpyU51Zu9k=; b=iNFv5f8J89BZj3QZ+XvIvni6hiX6vvJwGdHW+hBWphpJzZcJyveRBo40ZDr9W1qNxO WAsFD+EYEQJRetGkWBhBp0JhJPisIuLzWmNR1t6XkVxR3r9unugXzUVBHT3EvGDf4wAb fYnmywlInoyO8VWRcIDNqzrciHa1ziDGOd+cGRGngXZK2/tzuKY0y6Lg64oODae2kZv6 vIlPtsyHwowFsmPoyT7FmwyxAzHP1LU3IX9DYvqdRcw/4Utcn3AywBSWrrtdoPSpwO67 x4e7HbCR4IFIIIdL/QtLh5rVOg+88iwYI7GY7TBAlEIePniR9ZzkKwu9Fv0Y2MxY7YhG eiow== X-Gm-Message-State: AHPjjUjdzgm7HRw1oxgsW02kcAyFElSFJDFDdtWXSGyamwjDTyxxbupv N6NePn2HJrrwoK7b X-Google-Smtp-Source: ADKCNb7rid/EPxUoQnIZQ7O2dsImSLMdc/uXZ5aQWJszo3XV2CVGW/K5+uTAmqpZDzP+wWjtnyk3lA== X-Received: by 10.13.234.9 with SMTP id t9mr12611364ywe.80.1505226503044; Tue, 12 Sep 2017 07:28:23 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::a68b]) by smtp.googlemail.com with ESMTPSA id k189sm3990956ywc.18.2017.09.12.07.28.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Sep 2017 07:28:22 -0700 (PDT) To: GCC Patches Cc: Joseph Myers From: Nathan Sidwell Subject: [PATCH] move sorted field handling to C FE Message-ID: Date: Tue, 12 Sep 2017 10:28:20 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Now that I've excised sorted fields from the C++ FE (as a distinct concept), we can move some helper functions from c-family/ to c/ this patch does exactly that. Applied to trunk. nathan 2017-09-12 Nathan Sidwell c-family/ * c-common.c (field_decl_cmp, resort_data, resort_field_decl_cmp, resort_sorted_fields): Move to c/c-decl.c. * c-common.h (field_decl_cmp, resort_sorted_fields): Delete. (struct sorted_fields_type): Move to c/c-lang.h. c/ * c-decl.c (field_decl_cmp, resort_data, resort_field_decl_cmp, resort_sorted_fields): Moved from c-family/c-common.c. * c-lang.h (struct sorted_fields_type): Moved from c-family/c-common.h. Index: c/c-decl.c =================================================================== --- c/c-decl.c (revision 252007) +++ c/c-decl.c (working copy) @@ -7840,6 +7840,26 @@ warn_cxx_compat_finish_struct (tree fiel b->in_struct = 0; } +/* Function to help qsort sort FIELD_DECLs by name order. */ + +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; + + 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; +} + /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. LOC is the location of the RECORD_TYPE or UNION_TYPE's definition. FIELDLIST is a chain of FIELD_DECL nodes for the fields. @@ -8165,6 +8185,53 @@ finish_struct (location_t loc, tree t, t return t; } +static struct { + gt_pointer_operator new_value; + void *cookie; +} resort_data; + +/* This routine compares two fields like field_decl_cmp but using the +pointer operator in resort_data. */ + +static int +resort_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; + + 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; + { + tree d1 = DECL_NAME (*x); + tree d2 = DECL_NAME (*y); + resort_data.new_value (&d1, resort_data.cookie); + resort_data.new_value (&d2, resort_data.cookie); + if (d1 < d2) + return -1; + } + return 1; +} + +/* Resort DECL_SORTED_FIELDS because pointers have been reordered. */ + +void +resort_sorted_fields (void *obj, + void * ARG_UNUSED (orig_obj), + gt_pointer_operator new_value, + void *cookie) +{ + struct sorted_fields_type *sf = (struct sorted_fields_type *) obj; + resort_data.new_value = new_value; + resort_data.cookie = cookie; + qsort (&sf->elts[0], sf->len, sizeof (tree), + resort_field_decl_cmp); +} + /* Lay out the type T, and its element type, and so on. */ static void Index: c/c-lang.h =================================================================== --- c/c-lang.h (revision 252007) +++ c/c-lang.h (working copy) @@ -22,6 +22,13 @@ along with GCC; see the file COPYING3. #include "c-family/c-common.h" +/* In a RECORD_TYPE, a sorted array of the fields of the type, not a + tree for size reasons. */ +struct GTY(()) sorted_fields_type { + int len; + tree GTY((length ("%h.len"))) elts[1]; +}; + struct GTY(()) lang_type { /* In a RECORD_TYPE, a sorted array of the fields of the type. */ struct sorted_fields_type * GTY ((reorder ("resort_sorted_fields"))) s; Index: c-family/c-common.c =================================================================== --- c-family/c-common.c (revision 252007) +++ c-family/c-common.c (working copy) @@ -309,7 +309,6 @@ static bool check_case_bounds (location_ static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT); static bool nonnull_check_p (tree, unsigned HOST_WIDE_INT); -static int resort_field_decl_cmp (const void *, const void *); /* Reserved words. The third field is a mask: keywords are disabled if they match the mask. @@ -5871,73 +5870,6 @@ check_builtin_function_arguments (locati } } -/* Function to help qsort sort FIELD_DECLs by name order. */ - -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; - - 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; -} - -static struct { - gt_pointer_operator new_value; - void *cookie; -} resort_data; - -/* This routine compares two fields like field_decl_cmp but using the -pointer operator in resort_data. */ - -static int -resort_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; - - 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; - { - tree d1 = DECL_NAME (*x); - tree d2 = DECL_NAME (*y); - resort_data.new_value (&d1, resort_data.cookie); - resort_data.new_value (&d2, resort_data.cookie); - if (d1 < d2) - return -1; - } - return 1; -} - -/* Resort DECL_SORTED_FIELDS because pointers have been reordered. */ - -void -resort_sorted_fields (void *obj, - void * ARG_UNUSED (orig_obj), - gt_pointer_operator new_value, - void *cookie) -{ - struct sorted_fields_type *sf = (struct sorted_fields_type *) obj; - resort_data.new_value = new_value; - resort_data.cookie = cookie; - qsort (&sf->elts[0], sf->len, sizeof (tree), - resort_field_decl_cmp); -} - /* Subroutine of c_parse_error. Return the result of concatenating LHS and RHS. RHS is really a string literal, its first character is indicated by RHS_START and Index: c-family/c-common.h =================================================================== --- c-family/c-common.h (revision 252007) +++ c-family/c-common.h (working copy) @@ -493,13 +493,6 @@ extern const unsigned int num_c_common_r extern GTY(()) tree c_global_trees[CTI_MAX]; -/* In a RECORD_TYPE, a sorted array of the fields of the type, not a - tree for size reasons. */ -struct GTY(()) sorted_fields_type { - int len; - tree GTY((length ("%h.len"))) elts[1]; -}; - /* Mark which labels are explicitly declared. These may be shadowed, and may be referenced from nested functions. */ #define C_DECLARED_LABEL_FLAG(label) TREE_LANG_FLAG_1 (label) @@ -597,9 +590,6 @@ extern tree build_array_notation_expr (l extern tree build_array_notation_ref (location_t, tree, tree, tree, tree, tree); extern tree build_indirect_ref (location_t, tree, ref_operator); -extern int field_decl_cmp (const void *, const void *); -extern void resort_sorted_fields (void *, void *, gt_pointer_operator, - void *); extern bool has_c_linkage (const_tree decl); extern bool c_decl_implicit (const_tree);