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 80A9F385697B for ; Tue, 18 Jul 2023 16:26:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80A9F385697B 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=1689697605; 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=VFA5vGH9hXEyo8IlJJC9wfGfMtMsLWWd1e1SQmZflW0=; b=IFFzG5osBv16PbUUnbNWiaGMS8UTO0ER9nOcZFkIeM0E48XEv+PtYHTryMIV/mk4q+o9ql i0R9wLJA2+7AFJncyaVoYdmHRM6o47IEb1BRCW2IOfp0jR+cXQRA6L1Gi2Q2bzeA8SDS9T XewHxYjsDAGGkNiGM5NXaNZifYmDvuY= 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_256_GCM_SHA384) id us-mta-511-yjYDAqyDP4uB2hTmx9Js7A-1; Tue, 18 Jul 2023 12:26:44 -0400 X-MC-Unique: yjYDAqyDP4uB2hTmx9Js7A-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-765a632f342so681329885a.0 for ; Tue, 18 Jul 2023 09:26:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689697604; x=1692289604; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VFA5vGH9hXEyo8IlJJC9wfGfMtMsLWWd1e1SQmZflW0=; b=SNZaWSW+55N0Uq74ng7II0mFnBiqhDadxB4L/lz3L2gmCPqJOxeN5hfav7ITEZBe7G 00a+iKLE7dHq45D7JuH6JS/zyJnr/8SCnqBulcE54yh/uE37aQMuBeYHO3DOKJR9lm73 fVc7/iyJmdm+tVVQKSn5NI8PzrBIkVJt+fXGmKtUncrLko/ikcKGf5SGMSX3Ct5bnVYC edXuPM/zPQk2WRv2UbJDK/ZAkHlRsrqBi6HTzNhCkcmvkglMsqycXwPmTp14GVvNArRi AcfbyCMMwJOFXBPgm89TbFmfVdAzE/dm6tT1A/KDpyC+ljiJfIB5BsC6/sH8/2aWdGaX a4nQ== X-Gm-Message-State: ABy/qLYYNEJZrl0SFAa4E46rZZ7UBU7dryDQFYL013J6hlAm+i9sO3TJ M1q8MiFpUUkoCOmw+53akSGMt35b4TKslZeVpEqeFss4PkjoGBuYEkVGqJG6M5h2MYDbGXuRNE2 yQTVivKeD+NCDh0iXeQ== X-Received: by 2002:a05:620a:6848:b0:765:8986:a3bd with SMTP id ru8-20020a05620a684800b007658986a3bdmr2589595qkn.69.1689697604366; Tue, 18 Jul 2023 09:26:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlFAEBOGHB/JmKbfvAt6VW7xZnWrh44Zm+MDpNhslOHGcFZSPD8lg3Tv0pEog2ttEi+hBTO8Fw== X-Received: by 2002:a05:620a:6848:b0:765:8986:a3bd with SMTP id ru8-20020a05620a684800b007658986a3bdmr2589583qkn.69.1689697604084; Tue, 18 Jul 2023 09:26:44 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id i7-20020a05620a144700b00767d47eb29bsm682700qkl.119.2023.07.18.09.26.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Jul 2023 09:26:43 -0700 (PDT) Message-ID: <847b17a4-b157-c667-d6f8-ed35beac4b1b@redhat.com> Date: Tue, 18 Jul 2023 12:26:42 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH RFA (fold)] c++: constexpr bit_cast with empty field To: Richard Biener Cc: gcc-patches@gcc.gnu.org References: <20230717211905.946580-1-jason@redhat.com> 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: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham 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 7/18/23 07:31, Richard Biener wrote: > On Mon, Jul 17, 2023 at 11:20 PM Jason Merrill via Gcc-patches > wrote: >> >> Tested x86_64-pc-linux-gnu, OK for trunk? >> >> -- 8< -- >> >> The change to only cache constexpr calls that are >> reduced_constant_expression_p tripped on bit-cast3.C, which failed that >> predicate due to the presence of an empty field in the result of >> native_interpret_aggregate, which reduced_constant_expression_p rejects to >> avoid confusing output_constructor. >> >> This patch proposes to skip such fields in native_interpret_aggregate, since >> they aren't actually involved in the value representation. >> >> gcc/ChangeLog: >> >> * fold-const.cc (native_interpret_aggregate): Skip empty fields. >> >> gcc/cp/ChangeLog: >> >> * constexpr.cc (cxx_eval_bit_cast): Check that the result of >> native_interpret_aggregate doesn't need more evaluation. >> --- >> gcc/cp/constexpr.cc | 9 +++++++++ >> gcc/fold-const.cc | 3 ++- >> 2 files changed, 11 insertions(+), 1 deletion(-) >> >> diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc >> index 9d85c3be5cc..6e8f1c2b61e 100644 >> --- a/gcc/cp/constexpr.cc >> +++ b/gcc/cp/constexpr.cc >> @@ -1440,6 +1440,8 @@ enum value_cat { >> >> static tree cxx_eval_constant_expression (const constexpr_ctx *, tree, >> value_cat, bool *, bool *, tree * = NULL); >> +static tree cxx_eval_bare_aggregate (const constexpr_ctx *, tree, >> + value_cat, bool *, bool *); >> static tree cxx_fold_indirect_ref (const constexpr_ctx *, location_t, tree, tree, >> bool * = NULL); >> static tree find_heap_var_refs (tree *, int *, void *); >> @@ -4803,6 +4805,13 @@ cxx_eval_bit_cast (const constexpr_ctx *ctx, tree t, bool *non_constant_p, >> { >> clear_type_padding_in_mask (TREE_TYPE (t), mask); >> clear_uchar_or_std_byte_in_mask (loc, r, mask); >> + if (CHECKING_P) >> + { >> + tree e = cxx_eval_bare_aggregate (ctx, r, vc_prvalue, >> + non_constant_p, overflow_p); >> + gcc_checking_assert (e == r); >> + r = e; >> + } >> } >> } >> >> diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc >> index a02ede79fed..db8f7de5680 100644 >> --- a/gcc/fold-const.cc >> +++ b/gcc/fold-const.cc >> @@ -8935,7 +8935,8 @@ native_interpret_aggregate (tree type, const unsigned char *ptr, int off, >> return NULL_TREE; >> for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) >> { >> - if (TREE_CODE (field) != FIELD_DECL || DECL_PADDING_P (field)) >> + if (TREE_CODE (field) != FIELD_DECL || DECL_PADDING_P (field) >> + || integer_zerop (DECL_SIZE (field))) > > The gimplifier uses is_empty_type (TREE_TYPE (field)), wouldn't that be better > for consistency reasons at least? Good point, thanks. Pushed with that change. > OK with that change or with integer_zerop if there is a reason to not > use is_empty_type > here. > > Thanks, > Richard. > >> continue; >> tree fld = field; >> HOST_WIDE_INT bitoff = 0, pos = 0, sz = 0; >> >> base-commit: caabf0973a4e9a26421c94d540e3e20051e93e77 >> -- >> 2.39.3 >> >