From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id A22763857BAB; Tue, 24 May 2022 19:52:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A22763857BAB MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-749] c++: *this folding in constexpr call X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: 0aee03cb638c262846f55477b40828f694c846a0 X-Git-Newrev: 1189c03859cefef4fc4fd44d57eb3d4d3348b562 Message-Id: <20220524195227.A22763857BAB@sourceware.org> Date: Tue, 24 May 2022 19:52:27 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 May 2022 19:52:27 -0000 https://gcc.gnu.org/g:1189c03859cefef4fc4fd44d57eb3d4d3348b562 commit r13-749-g1189c03859cefef4fc4fd44d57eb3d4d3348b562 Author: Jason Merrill Date: Fri May 20 13:32:10 2022 -0400 c++: *this folding in constexpr call 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. 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. Diff: --- gcc/cp/constexpr.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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;