From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id C822938582B0 for ; Tue, 18 Jul 2023 11:31:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C822938582B0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2b703a0453fso90336311fa.3 for ; Tue, 18 Jul 2023 04:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689679907; x=1692271907; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BUne8tnOgCTDFd76iK2Qr+C6sGK2ySxCmat8SIMqGkI=; b=H5WJeXDPqHYLcQWU+iKrCBdTaA6AzePWmbOfBC+PTkTMJZbSwydC38hriZsntGVEwj 90QdUHnhdsZUhk82YXcNzv4pH86BUaJfQzUPlHm6hFnRXJq5yPt4+Djy6WkqwuEkSLnl IoP0Jg7scF3bowshNHwHNcB5YvpJ3xsVCeHuEeIyUgnkHVHp/L1fpf3r733n0bOfvp9q ZNNSkR5HMUTVOEge3nwlRcFB2Se235MItr00bT5KN/ZlfKdkiq4kzBpNOPlK727qbVwu c+bk3vETZz0HjbxL19ro6Ft27lRLc+kbFnePzisi538Ym/v+Hd+R41tONilf6DltO8HL Yibg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689679907; x=1692271907; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BUne8tnOgCTDFd76iK2Qr+C6sGK2ySxCmat8SIMqGkI=; b=Hn1Ge4Cs94Ei8QygGuATU0uEoSA/kCYmGxcKJ+KkFiZNFImGTKGnmBTzLOZmnSoKMc Uozi6s8kHfVkmPlr+ikcxDHrL/2v8XQvlJwEUh94vyC1PIwBQdafs49hQpy6mkojSIS+ RX81r50hYvuLW01EaqZ+spAif3PFxyNndyXWlRcXumteQs7VQliR1HAlIYf5jCMe9czY 78jyFk/Omdk7cAxw68gdpIKdZty6YAS7Nu2m5yE0DO/WdMdqZUsVgCe9m3DvRY7hRTYp Gy3oa1WiR8HgVq3wFlil2Qw51whXJLzP2ZB/H1MJ/zohroujlEAQvcsio7DssX6SWZSt dQMQ== X-Gm-Message-State: ABy/qLaOZZgRjwlWtz6oqctLJ2raGH9g65uPHLxgjmUNIZYpkSKVrkw0 2IJzAqOFjvqObpEc5Q+yP1OEmNoobeysEnA6aYl8Rwd/ X-Google-Smtp-Source: APBJJlFFjioTbcmrgplst3y8bLsAAp/H/z1LWoa984MQvRJw7gV9s8kjMuFR6llzJSs2i8jnumiSC4u4+g5zgqfO1oY= X-Received: by 2002:a2e:b04b:0:b0:2b8:3ff3:cd93 with SMTP id d11-20020a2eb04b000000b002b83ff3cd93mr10340119ljl.7.1689679906542; Tue, 18 Jul 2023 04:31:46 -0700 (PDT) MIME-Version: 1.0 References: <20230717211905.946580-1-jason@redhat.com> In-Reply-To: <20230717211905.946580-1-jason@redhat.com> From: Richard Biener Date: Tue, 18 Jul 2023 13:31:34 +0200 Message-ID: Subject: Re: [PATCH RFA (fold)] c++: constexpr bit_cast with empty field To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 Mon, Jul 17, 2023 at 11:20=E2=80=AFPM 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 t= o > avoid confusing output_constructor. > > This patch proposes to skip such fields in native_interpret_aggregate, si= nce > 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= * =3D 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, tr= ee, tree, > bool * =3D 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 =3D cxx_eval_bare_aggregate (ctx, r, vc_prvalue, > + non_constant_p, overflow_= p); > + gcc_checking_assert (e =3D=3D r); > + r =3D 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 unsign= ed char *ptr, int off, > return NULL_TREE; > for (tree field =3D TYPE_FIELDS (type); field; field =3D DECL_CHAIN (f= ield)) > { > - if (TREE_CODE (field) !=3D FIELD_DECL || DECL_PADDING_P (field)) > + if (TREE_CODE (field) !=3D FIELD_DECL || DECL_PADDING_P (field) > + || integer_zerop (DECL_SIZE (field))) The gimplifier uses is_empty_type (TREE_TYPE (field)), wouldn't that be be= tter for consistency reasons at least? 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 =3D field; > HOST_WIDE_INT bitoff =3D 0, pos =3D 0, sz =3D 0; > > base-commit: caabf0973a4e9a26421c94d540e3e20051e93e77 > -- > 2.39.3 >