From patchwork Fri May 6 20:30:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1627765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=iUL5GCMD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kw2JZ1y3vz9sFw for ; Sat, 7 May 2022 06:30:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0D67384B07B for ; Fri, 6 May 2022 20:30:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0D67384B07B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1651869051; bh=CklwXCUmEcgU7RAH5i1zbyUNejsgxr91i+qO/wDRrCw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=iUL5GCMDjnZdckgJmoVbIzd2djRqEkRDe73SPd6cRkFbpMt2IO2/2/RQ0zXlILD8b CsKyrRYvDL+nGHH4RPMzSmyovdFGYtN9JvsezwY/y6oJ4w18UtkWRbXAVNoE7/Ih4v ZTp2y9jlHpwwXj86z063gCCL7iKXd7OKrCLFz7FU= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 3A10A3857369 for ; Fri, 6 May 2022 20:30:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3A10A3857369 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-101-LYAAXPvPOGOkcBH4Kt2n-w-1; Fri, 06 May 2022 16:30:29 -0400 X-MC-Unique: LYAAXPvPOGOkcBH4Kt2n-w-1 Received: by mail-qt1-f198.google.com with SMTP id x10-20020ac8700a000000b002c3ef8fc44cso6950728qtm.8 for ; Fri, 06 May 2022 13:30:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=CklwXCUmEcgU7RAH5i1zbyUNejsgxr91i+qO/wDRrCw=; b=gkkK6GcYxYVfURlMCSeiH8BnBWDomideRo3T3Uv3noEBwMg0zbfFm5cBfBjmDMKbkB /qKts3XjTZBLlnPZ2aihgX9Str0q9CNRPEdM9wYzY9loJROwnzSI6G434AlEb1nPrvuI TwlsoJeRSUSUZ6NPJsYxt6egfcbd43vLCG1em7/F2fEC5huI63fniU7tWv79U2t3Er4T jAK+QbOY01WxKGEdtJAEv4n3JYu3KMdfy3iWDd6TlggB53ISxOu/SxcgORqaH13Jrg9o Yxxn4UdxiHj70FHC2rnMzHotX1zc6exhH8DaGylT9VRpoGDuOGuz71HLLfDv0SqGRCLe 89Rg== X-Gm-Message-State: AOAM532vDA7TG44hVyxq0BqK/eOnL5daGRfksdMA8+NEEFFky2PV7j73 6vNFs2th+X8UiGYL0Pv+VEVVkiF2pfxUw/xuLZEKfhJYaUjg8Ale9wBIxGH0eEuBjFTkIFWu9I3 UTwHVFsdlZKX00+PrDnoOkaONdywzXlKBaevR5MlgsvMl+wmJJHYFPPBriF8oboeHSA== X-Received: by 2002:ad4:5de1:0:b0:45a:81f5:b888 with SMTP id jn1-20020ad45de1000000b0045a81f5b888mr4013851qvb.110.1651869028561; Fri, 06 May 2022 13:30:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj9Rz0lVjUo7vKeFfT1zwbZtwJ48AqCFQc16YRHk26cJNqGxi26o2XoBjJ5P/yaiZc+KUdUw== X-Received: by 2002:ad4:5de1:0:b0:45a:81f5:b888 with SMTP id jn1-20020ad45de1000000b0045a81f5b888mr4013829qvb.110.1651869028119; Fri, 06 May 2022 13:30:28 -0700 (PDT) Received: from barrymore.redhat.com (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 d14-20020ac8544e000000b002f39b99f68fsm3217156qtq.41.2022.05.06.13.30.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 13:30:27 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: empty base constexpr adjustment [PR105245] Date: Fri, 6 May 2022 16:30:25 -0400 Message-Id: <20220506203025.2943558-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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" While looking at PR105245 in stage 4, I wanted to reorganize the code a bit, but it seemed prudent to defer that to stage 1. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/105245 PR c++/100111 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_store_expression): Reorganize empty base handling. --- gcc/cp/constexpr.cc | 69 +++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 34 deletions(-) base-commit: 469c76f0d94d03e29467a9d1e77cd3613f46ac2f diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 9b1e71857fc..6c204ab2265 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -5718,6 +5718,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, releasing_vec ctors, indexes; auto_vec index_pos_hints; bool activated_union_member_p = false; + bool empty_base = false; while (!refs->is_empty ()) { if (*valp == NULL_TREE) @@ -5759,7 +5760,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, no_zero_init = CONSTRUCTOR_NO_CLEARING (*valp); enum tree_code code = TREE_CODE (type); - type = refs->pop(); + tree reftype = refs->pop(); tree index = refs->pop(); if (code == RECORD_TYPE && is_empty_field (index)) @@ -5768,7 +5769,12 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, fields, which confuses the middle-end. The code below will notice that we don't have a CONSTRUCTOR for our inner target and just return init. */ - break; + { + empty_base = true; + break; + } + + type = reftype; if (code == UNION_TYPE && CONSTRUCTOR_NELTS (*valp) && CONSTRUCTOR_ELT (*valp, 0)->index != index) @@ -5902,44 +5908,41 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, } } + if (*non_constant_p) + return t; + /* Don't share a CONSTRUCTOR that might be changed later. */ init = unshare_constructor (init); - if (*valp && TREE_CODE (*valp) == CONSTRUCTOR - && TREE_CODE (init) == CONSTRUCTOR) + gcc_checking_assert (!*valp || (same_type_ignoring_top_level_qualifiers_p + (TREE_TYPE (*valp), type))); + if (empty_base || !(same_type_ignoring_top_level_qualifiers_p + (TREE_TYPE (init), type))) { - /* An outer ctx->ctor might be pointing to *valp, so replace - its contents. */ - if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (init), - TREE_TYPE (*valp))) - { - /* For initialization of an empty base, the original target will be - *(base*)this, evaluation of which resolves to the object - argument, which has the derived type rather than the base type. In - this situation, just evaluate the initializer and return, since - there's no actual data to store. */ - gcc_assert (is_empty_class (TREE_TYPE (init))); - return lval ? target : init; - } - CONSTRUCTOR_ELTS (*valp) = CONSTRUCTOR_ELTS (init); - TREE_CONSTANT (*valp) = TREE_CONSTANT (init); - TREE_SIDE_EFFECTS (*valp) = TREE_SIDE_EFFECTS (init); - CONSTRUCTOR_NO_CLEARING (*valp) - = CONSTRUCTOR_NO_CLEARING (init); - } - else if (TREE_CODE (init) == CONSTRUCTOR - && !same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (init), - type)) - { - /* See above on initialization of empty bases. */ - gcc_assert (is_empty_class (TREE_TYPE (init)) && !lval); + /* For initialization of an empty base, the original target will be + *(base*)this, evaluation of which resolves to the object + argument, which has the derived type rather than the base type. In + this situation, just evaluate the initializer and return, since + there's no actual data to store, and we didn't build a CONSTRUCTOR. */ + empty_base = true; + gcc_assert (is_empty_class (TREE_TYPE (init))); if (!*valp) { /* But do make sure we have something in *valp. */ *valp = build_constructor (type, nullptr); CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init; } - return init; + } + else if (*valp && TREE_CODE (*valp) == CONSTRUCTOR + && TREE_CODE (init) == CONSTRUCTOR) + { + /* An outer ctx->ctor might be pointing to *valp, so replace + its contents. */ + CONSTRUCTOR_ELTS (*valp) = CONSTRUCTOR_ELTS (init); + TREE_CONSTANT (*valp) = TREE_CONSTANT (init); + TREE_SIDE_EFFECTS (*valp) = TREE_SIDE_EFFECTS (init); + CONSTRUCTOR_NO_CLEARING (*valp) + = CONSTRUCTOR_NO_CLEARING (init); } else *valp = init; @@ -5958,7 +5961,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, constructor of a delegating constructor). Leave it up to the caller that set 'this' to set TREE_READONLY appropriately. */ gcc_checking_assert (same_type_ignoring_top_level_qualifiers_p - (TREE_TYPE (target), type)); + (TREE_TYPE (target), type) || empty_base); else TREE_READONLY (*valp) = true; } @@ -5980,9 +5983,7 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, CONSTRUCTOR_NO_CLEARING (elt) = false; } - if (*non_constant_p) - return t; - else if (lval) + if (lval) return target; else return init;