From patchwork Tue May 24 19:51:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1635157 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=VMCbZKKT; 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 4L74dp4Wh2z9sGH for ; Wed, 25 May 2022 05:54:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E4DD3857BA3 for ; Tue, 24 May 2022 19:53:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E4DD3857BA3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1653422038; bh=d5VPoTjpeLTWdLIAAtgikbFKp6kGFoq5r10a5B6+e/c=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VMCbZKKTZ4x/bkq4kkC9S7J3leWF3FU1IHEHI/r+4tdXJ2OoQ7UUQr72VncdhNN9G LhMH7hhL4Ek4jh/atlB4RJm2WS0dbHqHh3Z6n+0GQzaoQ31dV+BM6HiAT+/Suzf30P uFO29bImZD5+qESFuF1HyMp42Cy/2Zk4t54syrRc= 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 B94F43857BA3 for ; Tue, 24 May 2022 19:51:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B94F43857BA3 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-119-uT5y2ZpLNQSPmVvGLCzB9w-1; Tue, 24 May 2022 15:51:45 -0400 X-MC-Unique: uT5y2ZpLNQSPmVvGLCzB9w-1 Received: by mail-qk1-f197.google.com with SMTP id m26-20020a05620a13ba00b006a32a7adb78so12632052qki.10 for ; Tue, 24 May 2022 12:51:45 -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=d5VPoTjpeLTWdLIAAtgikbFKp6kGFoq5r10a5B6+e/c=; b=4yThbpyBvekTMs4migEM55lrwwl9SGon+Y7/ZDXabuwtVS/nTcvzc8MXAMbzEuvzwb auXthPWT1tPXQPW2rQPVs3eD76M8Qvn//i3fuXWZFJPKHsAtcX9Qi98N2eAwI+XqMQuX zXm9s0WvyUqFeBZYgJE9LTFAkNPgORFhWyTqToNfOn8zG/Hs7xIoHAIA9UiLdV3PTFxq IPjHv3S3waMd/YekIabqZg1aBcLcdTtojS54JrSvUtCUrhEeeJy7q0RHNGPRpFUcdCfg nDCyEA5daM1ITaR69f5D+1L9TZL2J/33bQ4QM7PN7ICg4/h1USe4wYjGTJYbHp14kxMz nAoQ== X-Gm-Message-State: AOAM530yEAnwodkrDFLxehlp7gbOIszjRzxHdylMHP9VL+c6GQJhud5Z H3y5M57VrcfnvAAn1D5MvCYsSiAayiE2kJhZT5ntaGyCdEDUJB9eLEpTOO3SrSYGRsp6CdMlc4/ N9cKozsBLrcWz6qBHKqhJL/x44ngWyYUCjurvtu9b9ZvirE5Xhh0+J5uk70m3nS322Q== X-Received: by 2002:ac8:59c5:0:b0:2f9:1f88:3450 with SMTP id f5-20020ac859c5000000b002f91f883450mr15376717qtf.28.1653421904168; Tue, 24 May 2022 12:51:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyvieULbjRjRjTl13wgBlxszHuggrAI2h9ACCrnBkMLmIEFgiZ8GyLZcrHwRB61hjevUfXDg== X-Received: by 2002:ac8:59c5:0:b0:2f9:1f88:3450 with SMTP id f5-20020ac859c5000000b002f91f883450mr15376683qtf.28.1653421903690; Tue, 24 May 2022 12:51:43 -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 c10-20020a05620a200a00b006a33f89bb00sm68810qka.81.2022.05.24.12.51.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 12:51:42 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: *this folding in constexpr call Date: Tue, 24 May 2022 15:51:40 -0400 Message-Id: <20220524195140.992137-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.5 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.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" The code in cxx_eval_call_expression to fold *this was doing the wrong thing for array decay; we can use cxx_fold_indirect_ref instead. This didn't end up being necessary to fix anything, but still seems like an improvement. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * constexpr.cc (cxx_fold_indirect_ref): Add default arg. (cxx_eval_call_expression): Call it. (cxx_fold_indirect_ref_1): Handle null empty_base. --- gcc/cp/constexpr.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) base-commit: 72f76540ad0e7185d4f516e781e8bead13ebc170 diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index a015bc7c818..388239ea8a8 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -1354,6 +1354,8 @@ enum value_cat { static tree cxx_eval_constant_expression (const constexpr_ctx *, tree, value_cat, bool *, bool *, tree * = NULL); +static tree cxx_fold_indirect_ref (const constexpr_ctx *, location_t, tree, tree, + bool * = NULL); /* Attempt to evaluate T which represents a call to a builtin function. We assume here that all builtin functions evaluate to scalar types @@ -2720,9 +2722,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, At this point it has already been evaluated in the call to cxx_bind_parameters_in_call. */ new_obj = TREE_VEC_ELT (new_call.bindings, 0); - STRIP_NOPS (new_obj); - if (TREE_CODE (new_obj) == ADDR_EXPR) - new_obj = TREE_OPERAND (new_obj, 0); + new_obj = cxx_fold_indirect_ref (ctx, loc, DECL_CONTEXT (fun), new_obj); if (ctx->call && ctx->call->fundef && DECL_CONSTRUCTOR_P (ctx->call->fundef->decl)) @@ -5197,7 +5197,8 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, && CLASS_TYPE_P (optype) && DERIVED_FROM_P (type, optype)) { - *empty_base = true; + if (empty_base) + *empty_base = true; return op; } } @@ -5216,7 +5217,7 @@ cxx_fold_indirect_ref_1 (const constexpr_ctx *ctx, location_t loc, tree type, static tree cxx_fold_indirect_ref (const constexpr_ctx *ctx, location_t loc, tree type, - tree op0, bool *empty_base) + tree op0, bool *empty_base /* = NULL*/) { tree sub = op0; tree subtype;