From patchwork Wed May 15 17:55:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1935713 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OeVFS46/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vfgrh2Bxhz1ymw for ; Thu, 16 May 2024 03:56:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC23A385828B for ; Wed, 15 May 2024 17:56:16 +0000 (GMT) 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 EE13C385828B for ; Wed, 15 May 2024 17:55:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE13C385828B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EE13C385828B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715795758; cv=none; b=nWTAXBDXBmXciAXBFZMjOY+wt3E8exOnpIxYMvmzfAAWYvlLApqWqwHflyIPQ7jUvlXwm/40jiZ5GXgCE4/AaEIORcrhoQHc01dCOAgI97aH37gGJxcXvTWI5FPZVCS8T7HwBXnH8TvLF8yvJFSrvRywZ4kNEukbq/qZ2z0zRIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715795758; c=relaxed/simple; bh=qaFNa6/6n7qrx2cuM8ISKV16rwAPqH1i2BxCIpOqrms=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=b4uicpdWKC4WuNDdfy3zKCmV3DkPivsVh7afJwFjkWoXmr+Vu46kaWcnFOHGaMfJJyp740oT2bGGW2N/5IJ0QDpqc1knGRvy9B1QcEJfjCFhbQATZvFDNuh5VlJuqIi+QXJBcU5oLn0TvKBqCVZlPBa/dd4pbDhItosAo/JrHbc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715795755; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yxF6s2dSUyMiGnn7evn1p0UlrpDUHGDFwFoScipqUF8=; b=OeVFS46//DLRMFrpn71Yp9fNTeB/JS0XXxZUcnQl5Vk+yGkbi/h6Bs3iyoeJS4yuRRBnzU +r/62cBb0gp4dcJjtnVS30wwv4u/iv7ILy7m3zDNQL1LyrWi2Zw3jPJQZtanJckF7Vb5yw j4ZqWVSyRUwIrEYj6thySfJVOzbEmwg= Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-njjpjMsVMI6HSuiBIJiYzw-1; Wed, 15 May 2024 13:55:53 -0400 X-MC-Unique: njjpjMsVMI6HSuiBIJiYzw-1 Received: by mail-yb1-f198.google.com with SMTP id 3f1490d57ef6-dc6b26845cdso10017941276.3 for ; Wed, 15 May 2024 10:55:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715795753; x=1716400553; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yxF6s2dSUyMiGnn7evn1p0UlrpDUHGDFwFoScipqUF8=; b=K+iGPy6izo/TvxUpCCr5tICXb6YkrqAMXHzJbwtd6yrRjipplJhIVOvUeGw8TVE/aT 5oIYk3fPHvHklBdNqKKy6JQFZOd0kdivBx0Jbt7GnFnz5qJxikBIkpJvl+/cG7CPWscy Xd+oaZycBZUckCCCD/e0DfxSPkSvtp8ev8WrV7KjfmeYTxpHUDL+NiPNVo0edHRJJRrf ERdHUtjue4oq6biEKX8CcVa5caPiajzyMcizQPXvdLUWqBGngEmLm1KmrPvKmUIxHKx5 mVKswyeXfSa1jrlgPeJA2WS4H6bo+vQE8lduA79ED2x/88f1gmgVmZr4XauFIwhcdMDx 2hGQ== X-Gm-Message-State: AOJu0YwJnWTHR0B6gZNZFjWODelduIVl+nOLaCbbOclbbdxnwkdiyRvL qVP/zHfn4sEe+FbhpqxWQ7097g9MvVojzy9dU9RDAWYteeAh5GvL7Qt/upeJuqZ2aPo7r2Poigg rXJ8X51a7J1gTVNyz5GcW8btjc7OiuRGemnnb75U1SZVaiJ9lu7cJVwvc5ajNEccguVsmPUqWAz GWuy6xeztueKs9Uuj2gbMa0th5NcOpXDaYLtzC X-Received: by 2002:a25:7801:0:b0:de5:d2d5:ab3b with SMTP id 3f1490d57ef6-dee4f37ee1emr14600711276.57.1715795751059; Wed, 15 May 2024 10:55:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/bAlQf7TCdtLBvZSHi4GX2sqKBOjHwYs8XmNaDqeF4IAmn7XWVM4rliYqoRbxcwwgBbS0fQ== X-Received: by 2002:a25:7801:0:b0:de5:d2d5:ab3b with SMTP id 3f1490d57ef6-dee4f37ee1emr14600693276.57.1715795750508; Wed, 15 May 2024 10:55:50 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e3935af58sm4282271cf.65.2024.05.15.10.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 10:55:50 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: represent all class non-dep assignments as CALL_EXPR Date: Wed, 15 May 2024 13:55:48 -0400 Message-ID: <20240515175548.591253-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.1.145.g83f1add914 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linu-xgnu, does this look OK for trunk? -- >8 -- Non-dependent compound assignment expressions are currently represented as CALL_EXPR to the selected operator@= overload. Non-dependent simple assignments on the other hand are still represented as MODOP_EXPR, which doesn't hold on to the selected overload. That we need to remember the selected operator@= overload ahead of time is a correctness thing, because they can be declared at namespace scope and we don't want to consider later-declared namespace scope overloads at instantiation time. This doesn't apply to simple operator= because it can only be declared at class scope, so it's fine to repeat the name lookup and overload resolution at instantiation time. But it still seems desirable for sake of QoI to also avoid this repeated name lookup and overload resolution for simple assignments along the lines of r12-6075-g2decd2cabe5a4f. To that end, this patch makes us represent non-dependent simple assignments as CALL_EXPR to the selected operator= overload rather than as MODOP_EXPR. In order for is_assignment_op_expr_p to recognize such CALL_EXPR as an assignment expression, cp_get_fndecl_from_callee needs to look through templated COMPONENT_REF callee corresponding to a member function call, otherwise ahead of time -Wparentheses warnings stop working (e.g. g++.dg/warn/Wparentheses-{32,33}.C). gcc/cp/ChangeLog: * call.cc (build_new_op): Pass 'overload' to cp_build_modify_expr. * cp-tree.h (cp_build_modify_expr): New overload that takes a tree* out-parameter. * pt.cc (tsubst_expr) : Propagate OPT_Wparentheses warning suppression to the result. * cvt.cc (cp_get_fndecl_from_callee): Use maybe_get_fns to extract the FUNCTION_DECL from a callee. * semantics.cc (is_assignment_op_expr_p): Also recognize templated operator expressions represented as a CALL_EXPR to operator=. * typeck.cc (cp_build_modify_expr): Add 'overload' out-parameter and pass it to build_new_op. (build_x_modify_expr): Pass 'overload' to cp_build_modify_expr. --- gcc/cp/call.cc | 2 +- gcc/cp/cp-tree.h | 3 +++ gcc/cp/cvt.cc | 5 +++-- gcc/cp/pt.cc | 2 ++ gcc/cp/typeck.cc | 18 ++++++++++++++---- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index e058da7735f..e3d4cf8949d 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -7473,7 +7473,7 @@ build_new_op (const op_location_t &loc, enum tree_code code, int flags, switch (code) { case MODIFY_EXPR: - return cp_build_modify_expr (loc, arg1, code2, arg2, complain); + return cp_build_modify_expr (loc, arg1, code2, arg2, overload, complain); case INDIRECT_REF: return cp_build_indirect_ref (loc, arg1, RO_UNARY_STAR, complain); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 9a8c8659157..1e565086e80 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8267,6 +8267,9 @@ extern tree cp_build_c_cast (location_t, tree, tree, extern cp_expr build_x_modify_expr (location_t, tree, enum tree_code, tree, tree, tsubst_flags_t); +extern tree cp_build_modify_expr (location_t, tree, + enum tree_code, tree, + tree *, tsubst_flags_t); extern tree cp_build_modify_expr (location_t, tree, enum tree_code, tree, tsubst_flags_t); diff --git a/gcc/cp/cvt.cc b/gcc/cp/cvt.cc index db086c017e8..2f4c0f88694 100644 --- a/gcc/cp/cvt.cc +++ b/gcc/cp/cvt.cc @@ -1015,8 +1015,9 @@ cp_get_fndecl_from_callee (tree fn, bool fold /* = true */) return f; }; - if (TREE_CODE (fn) == FUNCTION_DECL) - return fn_or_local_alias (fn); + if (tree f = maybe_get_fns (fn)) + if (TREE_CODE (f) == FUNCTION_DECL) + return fn_or_local_alias (f); tree type = TREE_TYPE (fn); if (type == NULL_TREE || !INDIRECT_TYPE_P (type)) return NULL_TREE; diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 32640f8e946..d83f530ac8d 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -21093,6 +21093,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (warning_suppressed_p (t, OPT_Wpessimizing_move)) /* This also suppresses -Wredundant-move. */ suppress_warning (ret, OPT_Wpessimizing_move); + if (warning_suppressed_p (t, OPT_Wparentheses)) + suppress_warning (STRIP_REFERENCE_REF (ret), OPT_Wparentheses); } RETURN (ret); diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 5f16994300f..75b696e32e0 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -9421,7 +9421,7 @@ build_modify_expr (location_t location, tree cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, - tree rhs, tsubst_flags_t complain) + tree rhs, tree *overload, tsubst_flags_t complain) { lhs = mark_lvalue_use_nonread (lhs); @@ -9533,7 +9533,8 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, rhs = unshare_expr (rhs); tree op2 = TREE_OPERAND (lhs, 2); if (TREE_CODE (op2) != THROW_EXPR) - op2 = cp_build_modify_expr (loc, op2, modifycode, rhs, complain); + op2 = cp_build_modify_expr (loc, op2, modifycode, rhs, + overload, complain); tree cond = build_conditional_expr (input_location, TREE_OPERAND (lhs, 0), op1, op2, complain); @@ -9620,7 +9621,7 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, result = build_new_op (input_location, MODIFY_EXPR, LOOKUP_NORMAL, lhs, rhs, make_node (NOP_EXPR), NULL_TREE, - /*overload=*/NULL, complain); + overload, complain); if (result == NULL_TREE) return error_mark_node; goto ret; @@ -9828,6 +9829,14 @@ cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, return result; } +tree +cp_build_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, + tree rhs, tsubst_flags_t complain) +{ + return cp_build_modify_expr (loc, lhs, modifycode, rhs, + /*overload=*/nullptr, complain); +} + cp_expr build_x_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, tree rhs, tree lookups, tsubst_flags_t complain) @@ -9856,7 +9865,8 @@ build_x_modify_expr (location_t loc, tree lhs, enum tree_code modifycode, tree rval; if (modifycode == NOP_EXPR) - rval = cp_build_modify_expr (loc, lhs, modifycode, rhs, complain); + rval = cp_build_modify_expr (loc, lhs, modifycode, rhs, + &overload, complain); else rval = build_new_op (loc, MODIFY_EXPR, LOOKUP_NORMAL, lhs, rhs, op, lookups, &overload, complain);