From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D3A85395A05A for ; Wed, 16 Nov 2022 13:09:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3A85395A05A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668604164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BvCfIkpUBS1a/7PmF/q+TDfjpadZaAfnfxv8E+QCqZg=; b=HAuUM/8hXF/z16F+Tf2wODEA+W55z9F5qqAaClmRfDDo8U4O7ZLg353Fphiv4fod0sAPwJ R83LG4ex5JhEXLfTiifpUBxKMhvi4XZTbKEN5WYC39CwjTMoxIyHoUytcFvXTYsyjYZs9l kb2deWtadpB/hFShUyDwWRoLtncJsX0= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-517-Td1OGmxwMYKtXe_Dn4oM-w-1; Wed, 16 Nov 2022 08:09:23 -0500 X-MC-Unique: Td1OGmxwMYKtXe_Dn4oM-w-1 Received: by mail-qk1-f197.google.com with SMTP id w4-20020a05620a444400b006fa24b2f394so17087229qkp.15 for ; Wed, 16 Nov 2022 05:09:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BvCfIkpUBS1a/7PmF/q+TDfjpadZaAfnfxv8E+QCqZg=; b=sv4CMoe80ylux2huSPPIgj00/YrAsY00JfuJijr7c3QYnHKIL33YU6NyeyX4g11VJP Vx2tLC6yL80T6Mi+r+aUCp/uvK86PnXhMWheDGPCmfzi4l/hUrkDhl18dYo5GoduLmdK F867FJS5YdsVu0RJdPSte88336gd+pVqpuxHnd4QVanQYF8UARlIOJyVA+MXsZ5g+/tq QGLju0l9wSuUZS6AKRfJ+RwuOsj8WDIHYmGqoGPre/gwXO24zQW6GDxk9hGH6TKOmVTT E2J3nqlucDMBVt1sFQq2n5by9tn8QOr/HaltKbQGeXk9jPzjAdBlSCPzhvrcLotxZd0O 37aQ== X-Gm-Message-State: ANoB5pkqZSQJSuQBuiepJ9HYjgf5L3y3LRJvJFIxbuSAiETx4JSvuPBq jFoU7y5YnwXhMrX95FgDFDc1tmt4LkNpIhDKuWOHw6CsBn1eYRv8mS2Jl8htl/rUC8o+mbyK1i4 hpJBIEYM5D2y3zNhSFg== X-Received: by 2002:a37:9a97:0:b0:6fa:feb:e811 with SMTP id c145-20020a379a97000000b006fa0febe811mr19205859qke.679.1668604162832; Wed, 16 Nov 2022 05:09:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf4XmqqnOlumYOZngJbt0QMeCscRB/7YWYmOgds7o72j94TlgKrD3qYowFH3dKdOg4RcmD/pIA== X-Received: by 2002:a37:9a97:0:b0:6fa:feb:e811 with SMTP id c145-20020a379a97000000b006fa0febe811mr19205832qke.679.1668604162508; Wed, 16 Nov 2022 05:09:22 -0800 (PST) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id bl12-20020a05620a1a8c00b006faa2c0100bsm9981711qkb.110.2022.11.16.05.09.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Nov 2022 05:09:21 -0800 (PST) Message-ID: <0c585f94-3c30-166e-2bc0-6188e4c4bc75@redhat.com> Date: Wed, 16 Nov 2022 08:09:21 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] c++, v2: Alignment changes to layout compatibility/common initial sequence - DR2583 To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_NUMSUBJECT,NICE_REPLY_A,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 List-Id: On 11/16/22 05:35, Jakub Jelinek wrote: > On Tue, Nov 15, 2022 at 05:57:26PM -0500, Jason Merrill wrote: >>> 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. >> >> Agreed. >> >>> +#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), ""); >> >> Maybe >> >> std_is_corresponding_member (&A::c, &B::c) == (alignof (char) == 8) >> >> ? >> >> Could also use an alignas(alignof(type)) case to verify that it matches a >> member with no alignas. > > So like this? > The previous patch successfully bootstrapped/regtested on x86_64-linux and > i686-linux, only the new testcase changed and that one passes make check, ok > for trunk? OK. > 2022-11-16 Jakub Jelinek > > * typeck.cc (next_common_initial_sequence): 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. > > --- 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_sequence (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-16 11:28:03.200831332 +0100 > +++ gcc/testsuite/g++.dg/DRs/dr2583.C 2022-11-16 11:31:34.421978999 +0100 > @@ -0,0 +1,45 @@ > +// 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 C { > + int i; > + alignas(alignof(char)) char c; > +}; > + > +struct D { > + alignas(alignof(int)) int i; > + 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 (std::is_corresponding_member (&A::c, &B::c) == (alignof (char) == 8), ""); > +static_assert (std::is_corresponding_member (&A::i, &C::i), ""); > +static_assert (std::is_corresponding_member (&A::c, &C::c), ""); > +static_assert (std::is_corresponding_member (&A::i, &D::i), ""); > +static_assert (std::is_corresponding_member (&A::c, &D::c), ""); > +static_assert (std::is_corresponding_member (&S0::x, &S1::x) == (alignof (char) == 16), ""); > +static_assert (std::is_corresponding_member (&S0::i, &S1::i) == (alignof (char) == 16), ""); > +#endif > > > Jakub >