From patchwork Mon Nov 15 07:48:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 47648 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D54E53858403 for ; Mon, 15 Nov 2021 07:49:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D54E53858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636962544; bh=2qU+qGqv893GjcI3b86t1Trx34cCTFiGFHD+9fU06yM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=abOtMMXgzzHab6+Tfx+yYVmGgPpniLcoccI1DL9YVtNYuGL2y9QB1kTBjRAYl0pVJ ASct7w5hQux4CtdXNRAJePjnvSRS7Iro9p22fSexSltgHFFEuQtujmEaYMRgEtVSwF vwQIqqIeKB0GKQyewWeKV66fyCpZK9d7/Mbbg5NI= 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 1964B3858D39 for ; Mon, 15 Nov 2021 07:48:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1964B3858D39 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-456-HajdWf_eO6i5pzdLm4L_yQ-1; Mon, 15 Nov 2021 02:48:32 -0500 X-MC-Unique: HajdWf_eO6i5pzdLm4L_yQ-1 Received: by mail-qv1-f71.google.com with SMTP id r13-20020a0562140c8d00b003bde7a2b8e2so15225168qvr.6 for ; Sun, 14 Nov 2021 23:48:32 -0800 (PST) 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=2qU+qGqv893GjcI3b86t1Trx34cCTFiGFHD+9fU06yM=; b=DgNcLVdqx5gs2wGqKd+gsRxf4DDmzgkMITUqI45Gy8eKKJbD5yvKGg3hi8dZxKpGb0 jqWRnLsqLt7ZJjXYURDAP0Hb1dvhZdUF5uICa1JOIctUM7MGfs7aMokslnfqqvyUAGgk lQtvwTj4ZPV5LU0oQ/I5b6vNF75qllc8H2Uu/Fa1LX8c+I6Jtd5+eIuPersmSXzDP8Hp Toa+Q2BVraWC9ROTFX113mEVbRpT3Oi0XKod0HWj7jiDSqVSEKQlW9KHZL4sP8Kzx+M4 4wmhMTDAKap7Db7oJsO3EdyggdWDyqtIcS/4E666aXOjqof1EoaFEH5fswlNVGy011ve HDoQ== X-Gm-Message-State: AOAM530UVi7lIWLlS1TZgEDIj3neUjOs/ylCMLl/xW+or5BSfHn7yzET gWIfFjlxNEyzsQdGoHmS7ssBgczq212yxY6ckwuy+H1XfAWThBxJqQ65dAGMGewNJlWaDxUTEsF vEgMtpp3k5ManY1xr1dj0Syv1GzXLVHcYnx/QhjpmD6lvgVLy/njC9vEfmy9Yq+Um4w== X-Received: by 2002:a05:620a:113b:: with SMTP id p27mr29189858qkk.33.1636962512026; Sun, 14 Nov 2021 23:48:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTHkjM56ksiyWv5HnalDpj2xFUnRpU+kVlvWZoE9zRBjqvGpYPe2yiIEwDrjagUMdWG0OlbQ== X-Received: by 2002:a05:620a:113b:: with SMTP id p27mr29189835qkk.33.1636962511683; Sun, 14 Nov 2021 23:48:31 -0800 (PST) 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 h68sm6444201qkf.126.2021.11.14.23.48.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Nov 2021 23:48:30 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: don't do constexpr folding in unevaluated context Date: Mon, 15 Nov 2021 02:48:28 -0500 Message-Id: <20211115074828.3353909-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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The implicit constexpr patch revealed that we were doing constant evaluation of arbitrary expressions in unevaluated contexts, leading to failure when we tried to evaluate e.g. a call to declval. This is wrong more generally; only manifestly-constant-evaluated expressions should be evaluated within an unevaluated operand. Making this change revealed a case we were failing to mark as manifestly constant-evaluated. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * constexpr.c (maybe_constant_value): Don't evaluate in an unevaluated operand unless manifestly const-evaluated. (fold_non_dependent_expr_template): Likewise. * decl.c (compute_array_index_type_loc): This context is manifestly constant-evaluated. --- gcc/cp/constexpr.c | 7 +++++++ gcc/cp/decl.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) base-commit: 267318a2857a42922c3ca033dac4690172b17683 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 7c27131f506..82a597d7bad 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -7696,6 +7696,10 @@ maybe_constant_value (tree t, tree decl, bool manifestly_const_eval) return r; } + /* Don't evaluate an unevaluated operand. */ + if (cp_unevaluated_operand) + return t; + uid_sensitive_constexpr_evaluation_checker c; r = cxx_eval_outermost_constant_expr (t, true, true, false, false, decl); gcc_checking_assert (r == t @@ -7759,6 +7763,9 @@ fold_non_dependent_expr_template (tree t, tsubst_flags_t complain, return t; } + if (cp_unevaluated_operand && !manifestly_const_eval) + return t; + tree r = cxx_eval_outermost_constant_expr (t, true, true, manifestly_const_eval, false, object); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 947bbfc6637..eed478199ea 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11000,7 +11000,7 @@ compute_array_index_type_loc (location_t name_loc, tree name, tree size, cp_convert (ssizetype, integer_one_node, complain), complain); - itype = maybe_constant_value (itype); + itype = maybe_constant_value (itype, NULL_TREE, true); } if (!TREE_CONSTANT (itype))