From patchwork Tue Mar 14 07:58:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 69350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1621717wrd; Tue, 14 Mar 2023 00:58:48 -0700 (PDT) X-Google-Smtp-Source: AK7set+5xmPKj4uFJRml8DxwtdEPCNSd31lOWNM5k20ZFwb+wAZoadE/fCBcinbkPWtBUEZTk6m9 X-Received: by 2002:a05:6402:155:b0:4fe:92a2:889c with SMTP id s21-20020a056402015500b004fe92a2889cmr181460edu.7.1678780728733; Tue, 14 Mar 2023 00:58:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678780728; cv=none; d=google.com; s=arc-20160816; b=RsUUcYW/SNTWIK17Qufr0p3WIKHwV1JWWUcu4yAhf3axo5uEZ6sVehvqe1XCL/Cbp+ UeYUxXyL+ELnWPQPQPp0/IT6c2MfNuEjEbIq1I0it3XxXaBR+kSHmRqbU25FMPKqrMSQ V/lKF3eMyWyF3F0ysqvgqVKvrEvYt9XcxsVNN1z80+KDfOF8LSArVC955dapI6C2c+s0 OTTGKIUDtSGxiGrVa48Fxdl0PDUUySt/mC42H7w/MxRFH2lBgB4qcZrQ5whsYbRNTCq4 twG+u00eS3jlfpMYj5K1Jhr+fFyG6Y5R4hZr8Z6A3Nm3xMnP1tNpKVT8ZiAe0h8KjSHj CSYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=RiQ9J8ZHXic6f+d+GTRw7ubDmrtlVZah5xeVl6gxa+Q=; b=JnR5nlB5AEYe85objoSC89RPbt9LqFLM79bEiEEloalDveYTlXJB0zEnztHAGcY/Dg OAlPRc1NYNOCywXK8br05IwPRgYpvKq8YNZKNLlDheftEhFCoVUK1Ip5aauafZIrOtuq vLsP+1geksHIkQp7KJUN5EHqKVdXhY5FEooy9ZQlvJkmG9BVbT9MnsP6JJPwF2q4Ez8e Yajc6TQSDJCskdnRk3o75rgdez3J6kG4haIs/btC/8JqjuAJmj4E/MgFcJ5xwSjQjO4v XCpvz7VDtxRKDIVp2Y2ohJ6MguIaj3J1btdyjqNNga7AmjchfFp4MfoOQwWJyAASYq2+ 6ASw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=flQmMqgr; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g15-20020aa7c58f000000b004ad7b14e125si1913563edq.265.2023.03.14.00.58.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 00:58:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=flQmMqgr; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B40EC3858D32 for ; Tue, 14 Mar 2023 07:58:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B40EC3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678780727; bh=RiQ9J8ZHXic6f+d+GTRw7ubDmrtlVZah5xeVl6gxa+Q=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=flQmMqgrhyz/YUcxjBb7GwahTXXjVRRsAI6kndrg6e0541VEZTWn5j4ylMIIKdbe7 TEVHvFLe7CqC9b+nvmsKTLpgymDOZ+U7e86mT9BZbstF5uayxFiGXY8bxsjfm/ivv8 Nk50mURXfgGJ2JJwIP/7vp68lkX44s6hvLxtrFy0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id CB11C3858D32 for ; Tue, 14 Mar 2023 07:58:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB11C3858D32 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-70-ZlmS4gpXNfin-X0O6mHKTw-1; Tue, 14 Mar 2023 03:58:03 -0400 X-MC-Unique: ZlmS4gpXNfin-X0O6mHKTw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B9D0101A55E for ; Tue, 14 Mar 2023 07:58:03 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E072C140EBF4; Tue, 14 Mar 2023 07:58:02 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32E7w0Vq606992 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 14 Mar 2023 08:58:01 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32E7w0EB606989; Tue, 14 Mar 2023 08:58:00 +0100 Date: Tue, 14 Mar 2023 08:58:00 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Treat unnamed bitfields as padding for __has_unique_object_representations [PR109096] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760329181381989822?= X-GMAIL-MSGID: =?utf-8?q?1760329181381989822?= Hi! As reported in the PR, for __has_unique_object_representations we were treating unnamed bitfields as named ones, which is wrong, they are actually padding. THe following patch fixes that. Ok for trunk (and what about release branches later?)? 2023-03-14 Jakub Jelinek PR c++/109096 * tree.cc (record_has_unique_obj_representations): Ignore unnamed bitfields. * g++.dg/cpp1z/has-unique-obj-representations3.C: New test. Jakub --- gcc/cp/tree.cc.jj 2023-03-10 10:06:40.247560614 +0100 +++ gcc/cp/tree.cc 2023-03-13 10:38:03.394836926 +0100 @@ -4851,7 +4851,7 @@ record_has_unique_obj_representations (c DECL_SIZE (field))) return false; } - else if (DECL_C_BIT_FIELD (field)) + else if (DECL_C_BIT_FIELD (field) && !DECL_UNNAMED_BIT_FIELD (field)) { tree btype = DECL_BIT_FIELD_TYPE (field); if (!type_has_unique_obj_representations (btype)) @@ -4862,7 +4862,7 @@ record_has_unique_obj_representations (c offset_int cur = 0; for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) - if (TREE_CODE (field) == FIELD_DECL) + if (TREE_CODE (field) == FIELD_DECL && !DECL_UNNAMED_BIT_FIELD (field)) { offset_int fld = wi::to_offset (DECL_FIELD_OFFSET (field)); offset_int bitpos = wi::to_offset (DECL_FIELD_BIT_OFFSET (field)); --- gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations3.C.jj 2023-03-13 10:50:21.705127719 +0100 +++ gcc/testsuite/g++.dg/cpp1z/has-unique-obj-representations3.C 2023-03-13 10:50:17.751185067 +0100 @@ -0,0 +1,10 @@ +// PR c++/109096 +// { dg-do compile { target c++11 } } + +#define INTB (__SIZEOF_INT__ * __CHAR_BIT__) +struct U { int i : INTB * 3 / 4; int : INTB / 4; }; +struct V { int : INTB * 3 / 4; int j : INTB / 4; }; +struct W { int i; int : 0; int j; }; +static_assert (__has_unique_object_representations (U) == false, ""); +static_assert (__has_unique_object_representations (V) == false, ""); +static_assert (sizeof (W) != 2 * sizeof (int) || __has_unique_object_representations (W) == true, "");