From patchwork Mon Jul 17 21:19:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1808910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=LVPlmnHR; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R4ZjM29Gxz20FV for ; Tue, 18 Jul 2023 07:19:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F050A385C301 for ; Mon, 17 Jul 2023 21:19:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F050A385C301 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689628789; bh=PRj66zsoYwmSW8T89PUqvxByqUhlayihYqV3unZaf3Y=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LVPlmnHRQ2WcojImtYOFzTz8Uptj4vnwfgA7Nc6RoqVZVpPVZJQ6TdmfC01opSo1g jx9Wn8UwVDB4ygxnfwzTgoqE7+Y/77KE0XEAdHe5/wQxqlwQrd06XSm+yCVbShj3VF Jrc7FMGT2Ver+2wOeO8oVbeyo+PS16F6sp8tJKog= 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 B71C63857731 for ; Mon, 17 Jul 2023 21:19:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B71C63857731 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-28-VQdfDBoCOuqtvwS9ABaOvQ-1; Mon, 17 Jul 2023 17:19:09 -0400 X-MC-Unique: VQdfDBoCOuqtvwS9ABaOvQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4039e119f40so60250301cf.0 for ; Mon, 17 Jul 2023 14:19:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689628749; x=1692220749; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PRj66zsoYwmSW8T89PUqvxByqUhlayihYqV3unZaf3Y=; b=lKTqgn865NIsodZaSd964vGlTFkHnbOjU2hrPPEGJyCJ9MdgbS73BiinnUbupXFWOr ZFMcadtTpByDGREsTz2mtR0l7NEIvuXjyNYjghCNX2fbvyFHcCoZhucYdQh8kE6o5YAa 3bavrj9cxw0T4DRrjIdFjA414mGO3pRdJC6/b27UMBqjh8JWP5ElvXX7gNUYUCvoQ4x1 JJRs4Yrtcu0ag9np74wG5ETGWA3X9sGjb+R+vVrmp/mA9xlAknAXpBhyvUCFkrOqOc4t jghxni/Tr56AlTOhZPA7k5n+IkZwyDmW92X1uHMSEBSqXc7N2fpxNMhOBgFmZYr8mmQa Uunw== X-Gm-Message-State: ABy/qLZuNe01CzeIHQNECK8hSL87aey7xGRxLBDnvZEvOnT5bdbO57UY MgbVgrJb8f40P7NRjJzCjWBZ2LL6x57VszO3XdnNwt5ZN3fs/Q5fGgi0j9gUn0ghycPMPSh4swS Bi/XSutV9GTMplnbURn4IUMg8XnNNELoTQACT2A4aJ1kzrpcvQooWP9TFc90NbMJVqexxJz6sUg == X-Received: by 2002:a05:622a:1750:b0:402:d96c:c840 with SMTP id l16-20020a05622a175000b00402d96cc840mr18940867qtk.18.1689628749144; Mon, 17 Jul 2023 14:19:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlHY+mIi1hfo/5nSSbXhgGC/lKu1xR4U+rLPTiOKkzV8+H5ffmxygeELsy6MmY6EySWPxDcOFQ== X-Received: by 2002:a05:622a:1750:b0:402:d96c:c840 with SMTP id l16-20020a05622a175000b00402d96cc840mr18940851qtk.18.1689628748822; Mon, 17 Jul 2023 14:19:08 -0700 (PDT) Received: from jason.com (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 t15-20020ac865cf000000b004035b79860dsm135718qto.81.2023.07.17.14.19.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 14:19:08 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH RFA (fold)] c++: constexpr bit_cast with empty field Date: Mon, 17 Jul 2023 17:19:05 -0400 Message-Id: <20230717211905.946580-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, 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 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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(-) base-commit: caabf0973a4e9a26421c94d540e3e20051e93e77 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))) continue; tree fld = field; HOST_WIDE_INT bitoff = 0, pos = 0, sz = 0;