From patchwork Thu Jan 25 21:04:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 866024 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-472062-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="Y4BIDFVi"; 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 3zSF3q1Wxhz9s9Y for ; Fri, 26 Jan 2018 08:07:33 +1100 (AEDT) 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=c9UVS4pryinNPs4Kz3/2n7NXQhbxwSEotgcS9SukDZrnu9NZ8d Km6hDfOCeOAaehLB6mQXgdwJMAJ2nyzaaCjrUdzNMIHdSMcfiETrD09JKvBnles6 jfuy1IAZ+8uAVvdryLBo+qqJXwv+XHcD4dMwUUcUOtWUI0AwIxSlnZT1g= 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=w/4naBqg95vm7mZvbKcZY66u/yw=; b=Y4BIDFVi0TA1vgHYxfIK gEnCMUZLoKz9YPoFZnbBlckQDmYooF3W7DK5YiZh5aSlqhzFb2Ezj5uTzi81hs9W ceOHKNUq5Yv87gUUvC1rtoGYYsesxpagKksLPqiLpKjfLXyUvuu7A7taZaKedNk2 X8DJ5Y9kI88t/XAxKcWA57I= Received: (qmail 79360 invoked by alias); 25 Jan 2018 21:07:25 -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 78954 invoked by uid 89); 25 Jan 2018 21:07:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 Jan 2018 21:07:22 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0PL1spn101261; Thu, 25 Jan 2018 21:07:19 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2fqpsa818m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Jan 2018 21:07:19 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w0PL7HB0003790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 25 Jan 2018 21:07:18 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0PL7GkO005214; Thu, 25 Jan 2018 21:07:16 GMT Received: from [192.168.1.4] (/79.33.231.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Jan 2018 13:04:48 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Add DECL_UNNAMED_BIT_FIELD and use it Message-ID: <16a5879e-ddba-7506-b86c-c7e5745b0f3f@oracle.com> Date: Thu, 25 Jan 2018 22:04:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8785 signatures=668655 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801250279 X-IsSubscribed: yes Hi, this is the complete patch, tested x86_64-linux. Thanks, Paolo. //////////////////////// /c-family 2018-01-25 Paolo Carlini * c-common.h (DECL_UNNAMED_BIT_FIELD): New. /c 2018-01-25 Paolo Carlini * c-typeck.c (really_start_incremental_init, push_init_level, set_nonincremental_init, output_init_element, process_init_element): Use DECL_UNNAMED_BIT_FIELD. /cp 2018-01-25 Paolo Carlini * class.c (is_really_empty_class): Use DECL_UNNAMED_BIT_FIELD. * constexpr.c (cx_check_missing_mem_inits): Likewise. * decl.c (next_initializable_field, find_decomp_class_base, cp_finish_decomp): Likewise. * typeck2.c (process_init_constructor_record): Likewise. Index: c/c-typeck.c =================================================================== --- c/c-typeck.c (revision 257063) +++ c/c-typeck.c (working copy) @@ -7955,8 +7955,7 @@ really_start_incremental_init (tree type) constructor_fields = TYPE_FIELDS (constructor_type); /* Skip any nameless bit fields at the beginning. */ while (constructor_fields != NULL_TREE - && DECL_C_BIT_FIELD (constructor_fields) - && DECL_NAME (constructor_fields) == NULL_TREE) + && DECL_UNNAMED_BIT_FIELD (constructor_fields)) constructor_fields = DECL_CHAIN (constructor_fields); constructor_unfilled_fields = constructor_fields; @@ -8161,8 +8160,7 @@ push_init_level (location_t loc, int implicit, constructor_fields = TYPE_FIELDS (constructor_type); /* Skip any nameless bit fields at the beginning. */ while (constructor_fields != NULL_TREE - && DECL_C_BIT_FIELD (constructor_fields) - && DECL_NAME (constructor_fields) == NULL_TREE) + && DECL_UNNAMED_BIT_FIELD (constructor_fields)) constructor_fields = DECL_CHAIN (constructor_fields); constructor_unfilled_fields = constructor_fields; @@ -8930,8 +8928,7 @@ set_nonincremental_init (struct obstack * braced_i constructor_unfilled_fields = TYPE_FIELDS (constructor_type); /* Skip any nameless bit fields at the beginning. */ while (constructor_unfilled_fields != NULL_TREE - && DECL_C_BIT_FIELD (constructor_unfilled_fields) - && DECL_NAME (constructor_unfilled_fields) == NULL_TREE) + && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields)) constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields); } @@ -9300,8 +9297,7 @@ output_init_element (location_t loc, tree value, t /* Skip any nameless bit fields. */ while (constructor_unfilled_fields != NULL_TREE - && DECL_C_BIT_FIELD (constructor_unfilled_fields) - && DECL_NAME (constructor_unfilled_fields) == NULL_TREE) + && DECL_UNNAMED_BIT_FIELD (constructor_unfilled_fields)) constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields); } @@ -9665,8 +9661,8 @@ process_init_element (location_t loc, struct c_exp constructor_unfilled_fields = DECL_CHAIN (constructor_fields); /* Skip any nameless bit fields. */ while (constructor_unfilled_fields != 0 - && DECL_C_BIT_FIELD (constructor_unfilled_fields) - && DECL_NAME (constructor_unfilled_fields) == 0) + && (DECL_UNNAMED_BIT_FIELD + (constructor_unfilled_fields))) constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields); } @@ -9675,8 +9671,7 @@ process_init_element (location_t loc, struct c_exp constructor_fields = DECL_CHAIN (constructor_fields); /* Skip any nameless bit fields at the beginning. */ while (constructor_fields != NULL_TREE - && DECL_C_BIT_FIELD (constructor_fields) - && DECL_NAME (constructor_fields) == NULL_TREE) + && DECL_UNNAMED_BIT_FIELD (constructor_fields)) constructor_fields = DECL_CHAIN (constructor_fields); } else if (TREE_CODE (constructor_type) == UNION_TYPE) Index: c-family/c-common.h =================================================================== --- c-family/c-common.h (revision 257063) +++ c-family/c-common.h (working copy) @@ -939,6 +939,10 @@ extern void c_parse_final_cleanups (void); #define CLEAR_DECL_C_BIT_FIELD(NODE) \ (DECL_LANG_FLAG_4 (FIELD_DECL_CHECK (NODE)) = 0) +/* True if the decl was an unnamed bitfield. */ +#define DECL_UNNAMED_BIT_FIELD(NODE) \ + (DECL_C_BIT_FIELD (NODE) && !DECL_NAME (NODE)) + extern tree do_case (location_t, tree, tree); extern tree build_stmt (location_t, enum tree_code, ...); extern tree build_real_imag_expr (location_t, enum tree_code, tree); Index: cp/class.c =================================================================== --- cp/class.c (revision 257063) +++ cp/class.c (working copy) @@ -8202,7 +8202,7 @@ is_really_empty_class (tree type) if (TREE_CODE (field) == FIELD_DECL && !DECL_ARTIFICIAL (field) /* An unnamed bit-field is not a data member. */ - && (DECL_NAME (field) || !DECL_C_BIT_FIELD (field)) + && !DECL_UNNAMED_BIT_FIELD (field) && !is_really_empty_class (TREE_TYPE (field))) return false; return true; Index: cp/constexpr.c =================================================================== --- cp/constexpr.c (revision 257063) +++ cp/constexpr.c (working copy) @@ -783,7 +783,7 @@ cx_check_missing_mem_inits (tree ctype, tree body, tree ftype; if (TREE_CODE (field) != FIELD_DECL) continue; - if (DECL_C_BIT_FIELD (field) && !DECL_NAME (field)) + if (DECL_UNNAMED_BIT_FIELD (field)) continue; if (DECL_ARTIFICIAL (field)) continue; Index: cp/decl.c =================================================================== --- cp/decl.c (revision 257063) +++ cp/decl.c (working copy) @@ -5634,7 +5634,7 @@ next_initializable_field (tree field) { while (field && (TREE_CODE (field) != FIELD_DECL - || (DECL_C_BIT_FIELD (field) && !DECL_NAME (field)) + || DECL_UNNAMED_BIT_FIELD (field) || (DECL_ARTIFICIAL (field) && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field))))) field = DECL_CHAIN (field); @@ -7208,7 +7208,7 @@ find_decomp_class_base (location_t loc, tree type, for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field) - || (DECL_C_BIT_FIELD (field) && !DECL_NAME (field))) + || DECL_UNNAMED_BIT_FIELD (field)) continue; else if (ret) return type; @@ -7646,7 +7646,7 @@ cp_finish_decomp (tree decl, tree first, unsigned for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field)) if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field) - || (DECL_C_BIT_FIELD (field) && !DECL_NAME (field))) + || DECL_UNNAMED_BIT_FIELD (field)) continue; else eltscnt++; @@ -7663,7 +7663,7 @@ cp_finish_decomp (tree decl, tree first, unsigned for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field)) if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field) - || (DECL_C_BIT_FIELD (field) && !DECL_NAME (field))) + || DECL_UNNAMED_BIT_FIELD (field)) continue; else { Index: cp/typeck2.c =================================================================== --- cp/typeck2.c (revision 257063) +++ cp/typeck2.c (working copy) @@ -1395,14 +1395,14 @@ process_init_constructor_record (tree type, tree i tree next; tree type; - if (!DECL_NAME (field) && DECL_C_BIT_FIELD (field)) - continue; - if (TREE_CODE (field) != FIELD_DECL || (DECL_ARTIFICIAL (field) && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))) continue; + if (DECL_UNNAMED_BIT_FIELD (field)) + continue; + /* If this is a bitfield, first convert to the declared type. */ type = TREE_TYPE (field); if (DECL_BIT_FIELD_TYPE (field)) @@ -1547,8 +1547,6 @@ process_init_constructor_record (tree type, tree i for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { - if (!DECL_NAME (field) && DECL_C_BIT_FIELD (field)) - continue; if (TREE_CODE (field) != FIELD_DECL || (DECL_ARTIFICIAL (field) && !(cxx_dialect >= cxx17 @@ -1555,6 +1553,9 @@ process_init_constructor_record (tree type, tree i && DECL_FIELD_IS_BASE (field)))) continue; + if (DECL_UNNAMED_BIT_FIELD (field)) + continue; + if (ce->index == field || ce->index == DECL_NAME (field)) break; if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))