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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 816683954425 for ; Thu, 29 Apr 2021 18:33:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 816683954425 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-479-aJeJHKpcO3-Js5CRagPQQQ-1; Thu, 29 Apr 2021 14:33:06 -0400 X-MC-Unique: aJeJHKpcO3-Js5CRagPQQQ-1 Received: by mail-qt1-f200.google.com with SMTP id r20-20020ac85c940000b02901bac34fa2eeso5882426qta.11 for ; Thu, 29 Apr 2021 11:33:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=FrvNdH1Gp/ye1MjvcLEhdnc47NVWPufEhcdhBzYwkcA=; b=A4gjyrReqHqR3vPyb1db7I5GNlHENeUDn97eLQ0q46etsfwx0gLiNxXyf2/PAT7twc wmG7JsWMMMKrbeQfXSY+VXqkdbJNDHxzKU3dkX/PmKajWJftioKXN0JD4k3r9LO5FT0d VyajJUWNBNH2y1zPQURPqwzagiac70DdLwc6zN8IF0oQtKR9aU5xgvU33xy8XLn6zMuP 6nKkk8hDPHJB8cUIm75tAaXlDyNLbWQ/7ETTzf71u2AycJDTQoUmQhI0gITpD+tA9J04 V39DeAiR7RxNS29tSKDTVl4GJMpxHUfEfZgH4qa6QIxoqX7ifLr8OdmPhleYUn1A6lz6 +M2g== X-Gm-Message-State: AOAM532wSbrVkh3dvkynVKQQIHEFEsvQ9yjEbsUV1i1w1Z4vHnSHuC7a p+zWpe+/hQFx0PPIYC2WAhokqtXapwx2GBgWrA3/2qcIsHWuXJTH1htQf49NO5lxxJ871/9cV5Z CH+K6Jh1lKDpaDW8KXZ6FnBO7mEmVEeKJH/fAn/e+mUM3Y81KRQp+PJ011dKPQixQNw== X-Received: by 2002:a05:622a:350:: with SMTP id r16mr722848qtw.27.1619721185758; Thu, 29 Apr 2021 11:33:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxshmj5wUvi2yUqkqq6nPuF6Pq94sfXGgJUNZxJJoc7xYJkEZDGVAWxAvIkHpD59GK1NJegHQ== X-Received: by 2002:a05:622a:350:: with SMTP id r16mr722820qtw.27.1619721185441; Thu, 29 Apr 2021 11:33:05 -0700 (PDT) Received: from barrymore.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id 7sm628664qtu.38.2021.04.29.11.33.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Apr 2021 11:33:04 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: Use empty field in constexpr eval. Date: Thu, 29 Apr 2021 14:33:03 -0400 Message-Id: <20210429183303.2921134-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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_LOTSOFHASH, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Thu, 29 Apr 2021 18:33:09 -0000 In discussion of PR98463, Jakub noted that cxx_fold_indirect_ref_1 was bailing out early for empty bases even when we do have fields for them (in C++17 mode or later). This corrects that. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * constexpr.c (cxx_fold_indirect_ref_1): Only set *empty_base if we don't find a field. --- gcc/cp/constexpr.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index fa7eaed945a..9481a5bfd3c 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -4734,28 +4734,17 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, { tree optype = TREE_TYPE (op); unsigned HOST_WIDE_INT const_nunits; - if (off == 0) - { - if (similar_type_p (optype, type)) - return op; - /* Also handle conversion to an empty base class, which - is represented with a NOP_EXPR. */ - /* *(foo *)&complexfoo => __real__ complexfoo */ - else if (TREE_CODE (optype) == COMPLEX_TYPE - && similar_type_p (type, TREE_TYPE (optype))) - return build1_loc (loc, REALPART_EXPR, type, op); - } - /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */ + if (off == 0 && similar_type_p (optype, type)) + return op; else if (TREE_CODE (optype) == COMPLEX_TYPE - && similar_type_p (type, TREE_TYPE (optype)) - && tree_to_uhwi (TYPE_SIZE_UNIT (type)) == off) - return build1_loc (loc, IMAGPART_EXPR, type, op); - if (is_empty_class (type) - && CLASS_TYPE_P (optype) - && DERIVED_FROM_P (type, optype)) + && similar_type_p (type, TREE_TYPE (optype))) { - *empty_base = true; - return op; + /* *(foo *)&complexfoo => __real__ complexfoo */ + if (off == 0) + return build1_loc (loc, REALPART_EXPR, type, op); + /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */ + else if (tree_to_uhwi (TYPE_SIZE_UNIT (type)) == off) + return build1_loc (loc, IMAGPART_EXPR, type, op); } /* ((foo*)&vectorfoo)[x] => BIT_FIELD_REF */ else if (VECTOR_TYPE_P (optype) @@ -4834,6 +4823,15 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, return ret; } } + /* Also handle conversion to an empty base class, which + is represented with a NOP_EXPR. */ + if (is_empty_class (type) + && CLASS_TYPE_P (optype) + && DERIVED_FROM_P (type, optype)) + { + *empty_base = true; + return op; + } } return NULL_TREE; base-commit: 449d7b40f6f6be8d7f9aa7232c73b0371f0963bf prerequisite-patch-id: 39f358d55a4ba496b673d13e00215152266caa54 prerequisite-patch-id: f0d6c56fe2c9e16572f0760fb223f6d4df3e859e prerequisite-patch-id: 8188da37013371fd5864b80fb0cc5ad4596a1ff6 prerequisite-patch-id: f9c0d88147525dd47cab54ddfdde9341b7b10a4c -- 2.27.0