From patchwork Mon Nov 14 11:28:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 19719 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2091331wru; Mon, 14 Nov 2022 03:29:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf7MDIeAuVqTGpG2NqlaRTFehEYbTdOLp/AvmgtSWCFbb+u2PSTJQZ1maNpvgwIk+uEs0djn X-Received: by 2002:a17:907:3101:b0:7ad:cda3:93c7 with SMTP id wl1-20020a170907310100b007adcda393c7mr10279994ejb.500.1668425376009; Mon, 14 Nov 2022 03:29:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668425376; cv=none; d=google.com; s=arc-20160816; b=hmiqvWLu622U7ijIVUm+ygpLndWhMj0AgwAuBbao+iFKZPAt0hXAYnTiZNc4AXlC7M nboTT4ylf5NOrCw3mH58Qb+yY0xrUK4QEPcBTrcp4uCuLwN++46jNc7y7YH2LjNPYXkF ZWp0fq+AW2jgk5gspqsuvbZ5KP11kCT2FDTGUzoxazdbv6c+UcuH4VlsJcke5mlAatdN 3rOWWD2atPghjzNajpL8N5NFTcQT/05/w0lz4CzrCpDcfFZJ6ERozWYF+LwAS9cqDcVD J4DzVyuFZ/OhJyRoP4kBFMf848PoO9K5665CcBSGa6Tk27qdIO2FbqyZvSHtfmqMZjg3 0ttA== 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=AeyS6cMLFg10iHayBBaE02qXYE/+zIA+m5W8i+Bp//w=; b=cHH9Y4iqokSYgYDcw0RHiqF7fA0yyGTo2vhiPB6FuTLcINH1BLfrIV93tLTLrGI+ma 2zuYAR0ao7YQCPvwiY+BaM+c/rVWEa/4Y4Pl4EVJmQHleUFKjMtb4P4dbukXchLYg4ZX sri1eYBXd6X8tto5ODzQvYmkYFZm8BEp96AwfygOjzVojdHIf+qBJzB2mUcsGoH4dKfd qtzHj5fEeOXydvFjLWQHUeKjkemm8S08ZRvEGMVEsbJ2qgxaD3QQsnl/RTjkRJat+OkA qiPZz2AI0D54/dQNXplYSb1P0We3dNMVIWl8dbcy0loJd26cIFQ9akQwGgpi/JdevUbT 5sQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=O8UxQ6ci; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f14-20020a0564021e8e00b004674c93ecb8si8854682edf.326.2022.11.14.03.29.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 03:29:36 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=O8UxQ6ci; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 C1EA7385840E for ; Mon, 14 Nov 2022 11:29:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1EA7385840E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668425374; bh=AeyS6cMLFg10iHayBBaE02qXYE/+zIA+m5W8i+Bp//w=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=O8UxQ6ciEZRmNkgRusNf8x4FScNqOKgR2TmmWbsXUU8Nkk1EjkUMQiGUYDIc9x3/t kcCqZpd+ZzyhU0yyqvfSBEUU/aMwaTbfY7swMmv5GdrOU+Wk97ZYlGPLZcycfJb1qS NGF8zeuH9aYeSi4Lr4ZH6/wB0Ywwd7AtftbDiwqA= 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 D4DB33858D20 for ; Mon, 14 Nov 2022 11:28:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D4DB33858D20 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-252-nCpqTIBPNoKPHuB6QicEqQ-1; Mon, 14 Nov 2022 06:28:45 -0500 X-MC-Unique: nCpqTIBPNoKPHuB6QicEqQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F581811E67 for ; Mon, 14 Nov 2022 11:28:45 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0784BC15BA4; Mon, 14 Nov 2022 11:28:44 +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 2AEBSerY2841580 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 14 Nov 2022 12:28:40 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2AEBSdsO2841579; Sun, 13 Nov 2022 23:28:39 -1200 Date: Sun, 13 Nov 2022 23:28:39 -1200 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Alignment changes to layout compatibility/common initial sequence - DR2583 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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?1749470806965372250?= X-GMAIL-MSGID: =?utf-8?q?1749470806965372250?= Hi! Working virtually out of Baker Island. When trying to figure out what to do about alignment, layout_compatible_type_p returns false if TYPE_ALIGN on ENUMERAL_TYPE/CLASS_TYPE_P (but not scalar types?) differ, or if members don't have the same positions. What is in DR2583 doesn't say anything like that though, on the other side it says that if the corresponding entities don't have the same alignment requirements, they aren't part of the common initial sequence. So, my understanding of this is we shouldn't check TYPE_ALIGN in layout_compatible_type_p, but instead DECL_ALIGN in next_common_initial_seqence. Lightly tested (on is-layout*/is-corresponding*/dr2583.C only) so far, ok if it passes full bootstrap/regtest? Or do we need different rules? 2022-11-14 Jakub Jelinek * typeck.cc (next_common_initial_seqence): Return false members have different DECL_ALIGN. (layout_compatible_type_p): Don't test TYPE_ALIGN of ENUMERAL_TYPE or CLASS_TYPE_P. * g++.dg/cpp2a/is-layout-compatible3.C: Expect enums with different alignas to be layout compatible, while classes with different alignas on members layout incompatible. * g++.dg/DRs/dr2583.C: New test. Jakub --- gcc/cp/typeck.cc.jj 2022-11-13 04:53:46.010682269 -1200 +++ gcc/cp/typeck.cc 2022-11-13 23:14:41.355180354 -1200 @@ -1833,6 +1833,8 @@ next_common_initial_seqence (tree &memb1 if ((!lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb1))) != !lookup_attribute ("no_unique_address", DECL_ATTRIBUTES (memb2))) return false; + if (DECL_ALIGN (memb1) != DECL_ALIGN (memb2)) + return false; if (!tree_int_cst_equal (bit_position (memb1), bit_position (memb2))) return false; return true; @@ -1854,15 +1856,13 @@ layout_compatible_type_p (tree type1, tr type2 = cp_build_qualified_type (type2, TYPE_UNQUALIFIED); if (TREE_CODE (type1) == ENUMERAL_TYPE) - return (TYPE_ALIGN (type1) == TYPE_ALIGN (type2) - && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2)) + return (tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2)) && same_type_p (finish_underlying_type (type1), finish_underlying_type (type2))); if (CLASS_TYPE_P (type1) && std_layout_type_p (type1) && std_layout_type_p (type2) - && TYPE_ALIGN (type1) == TYPE_ALIGN (type2) && tree_int_cst_equal (TYPE_SIZE (type1), TYPE_SIZE (type2))) { tree field1 = TYPE_FIELDS (type1); --- gcc/testsuite/g++.dg/cpp2a/is-layout-compatible3.C.jj 2021-08-18 21:42:27.414421719 -1200 +++ gcc/testsuite/g++.dg/cpp2a/is-layout-compatible3.C 2022-11-13 23:20:05.008776825 -1200 @@ -55,10 +55,10 @@ static_assert (!std::is_layout_compatibl static_assert (!std::is_layout_compatible_v); static_assert (!std::is_layout_compatible_v); static_assert (!std::is_layout_compatible_v); -static_assert (!std::is_layout_compatible_v); +static_assert (std::is_layout_compatible_v); static_assert (!std::is_layout_compatible_v); static_assert (!std::is_layout_compatible_v); static_assert (!std::is_layout_compatible_v); -static_assert (std::is_layout_compatible_v); +static_assert (!std::is_layout_compatible_v); static_assert (std::is_layout_compatible_v); static_assert (std::is_layout_compatible_v); --- gcc/testsuite/g++.dg/DRs/dr2583.C.jj 2022-11-13 22:58:11.977640606 -1200 +++ gcc/testsuite/g++.dg/DRs/dr2583.C 2022-11-13 23:18:04.630414835 -1200 @@ -0,0 +1,31 @@ +// DR 2583 - Common initial sequence should consider over-alignment. +// { dg-do compile { target c++11 } } + +#include + +struct A { + int i; + char c; +}; + +struct B { + int i; + alignas(8) char c; +}; + +struct S0 { + alignas(16) char x[128]; + int i; +}; + +struct alignas(16) S1 { + char x[128]; + int i; +}; + +#if __cpp_lib_is_layout_compatible >= 201907L +static_assert (std::is_corresponding_member (&A::i, &B::i), ""); +static_assert (alignof (char) == 8 || !std::is_corresponding_member (&A::c, &B::c), ""); +static_assert (alignof (char) == 16 || !std::is_corresponding_member (&S0::x, &S1::x), ""); +static_assert (alignof (char) == 16 || !std::is_corresponding_member (&S0::i, &S1::i), ""); +#endif