From patchwork Thu Jul 13 18:49:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 120084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2021415vqm; Thu, 13 Jul 2023 11:50:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlEsECh26fgsux//Gee2w/ooaHgryMOQwdG/w142IRM/iITN08QWbG88fQL1n/acV9oO17sS X-Received: by 2002:adf:e707:0:b0:314:9ef:838c with SMTP id c7-20020adfe707000000b0031409ef838cmr2306045wrm.15.1689274235749; Thu, 13 Jul 2023 11:50:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689274235; cv=none; d=google.com; s=arc-20160816; b=XlkjydJDJqKbDwYiRKI2e7vSps6Daz5R43tT2s+jdBev8TrAHEoxzJR8inSG8W5zoU XlOhhykmmCfO/dCyUGpu1wFfrrU4m4io0Um/oI9KxdlxxElXplfKYPajHftbItfnI43R 0EskGyZqPL5FYkxdWqu2hDnClxrFp7KmBrwjcnjb9NIs02UgKTDFDytB6tBerVdl5YXe cio5dh6iXOQYj+IGUp2EP2PtpgX1yKnt5TXAbak+FHSuVUeIceGEDcxdEfEDt/YBSv/U PPFSV/dV8x+LGKbLOciJFUlK7v1smXcmGmsDQnxWdVO+i46xU9pD4ve//i2coH1pn6UT WLLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=pA3sJyt3B3xJpOH1HTeFP3IOzz1eHzaQMtwvj2pYznU=; fh=M5GO8duY/t9+1sJXvBSRQ4u8k9z8sLFDsSO1kARbltQ=; b=z0tUt46g92QaUj4X1yDzP+icUMDAULgBm9gjiGb9/wPr1M5MT8/dL2k9fsFNREvhby sL5i4xjnv+rxHnBxZ7mvkdq9Li4FVurEc03Nt9g48g23Ak3rQll8fmM0f27E+E51bgu+ dryJAqBvdRe1icV9RTTQsM/4QIKSK+zh8IWc/8Lo0VkP3oU6b449qpMnLy42g9axaRtL nKexHhOtYkhXtTjSQCilZ1uV06+Ea05irBhFO93PZ+6H1MiRY+YvqiD65Dk0Uooe68jy wbgzPLjezEmwmHYawSld8qJ77Rts8ShevUZuHtk8AnXtBXgjrhTg6zsa6plTTNtIgJ9d znvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bW2K+DeD; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f19-20020a056402151300b0051e2549c4a4si7278753edw.217.2023.07.13.11.50.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 11:50:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bW2K+DeD; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2C903858002 for ; Thu, 13 Jul 2023 18:50:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2C903858002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689274230; bh=pA3sJyt3B3xJpOH1HTeFP3IOzz1eHzaQMtwvj2pYznU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=bW2K+DeDxvfGc58EnMxqZe5eUfFfuBv8lcd9IH/JHdhqGtPpDoPcXVKKujaa5oZqk mIPtjyg5+WKWYzW8bXZFq+Eg1hS/KSTPcY8isWpC+uZroL+v+pHONzciGJmDhee9QE AfDue78zlcVQAlOuvt56g3g0OmT1mkUhKLFwjXbA= 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 491793858CDB for ; Thu, 13 Jul 2023 18:49:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 491793858CDB Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378-FTS3zliYPSW3dq39UQkJ1g-1; Thu, 13 Jul 2023 14:49:45 -0400 X-MC-Unique: FTS3zliYPSW3dq39UQkJ1g-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-63788123d11so10011956d6.0 for ; Thu, 13 Jul 2023 11:49:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689274184; x=1691866184; 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=pA3sJyt3B3xJpOH1HTeFP3IOzz1eHzaQMtwvj2pYznU=; b=N/G+e1OEQvThGEjbOAY49G6zJRXurdKT/gO3NX2IeUUK/s1zxBNH6xXCrTJwIs2apE ZCtdaphzPVP2M+NDhuKdoFNdy33GHuq7PV+WNUcoU/v5Dyw74F62I+EffsN7B1aNVtS+ TXaUkK9aLOHiq7wsq+PjIbLxeKfwqMTfw7tvfAlp3eBr2v0eLDLuBuW6GX77BEcUzwXL bUYWomBWecHPzZLMTRU+1IgoIEcKYF/e+9J8DtLkE9pEoqF4MJtYKtx1Out7+mcyiI0+ VeecmUJyCJI6q1mu1nFjtFX/xDBleQgsSEuyM85Ipg7nTE0xJ337qb1v9nFBnZhxtlfp sA0Q== X-Gm-Message-State: ABy/qLb3zyHcEcB+qxdyuS7rvHP4zdG6n3GjL47c5mVUAhQH53FWAnWs YwCNtDgmqT0Bx047dqcJvn++VGCSsFf0u+WJ0K5FBd/y8/aksayk6ZwzlTVQfZoUU/Y/p19II2c hgBK12NEG3nEc7x6PZ8eHIYULcYTzMU98eFy8a2e0bjFiXtEmRW/F2++95rfw0VSXU3e8O/Ik2+ c= X-Received: by 2002:a0c:b2d2:0:b0:630:7a8:f602 with SMTP id d18-20020a0cb2d2000000b0063007a8f602mr2021896qvf.7.1689274184339; Thu, 13 Jul 2023 11:49:44 -0700 (PDT) X-Received: by 2002:a0c:b2d2:0:b0:630:7a8:f602 with SMTP id d18-20020a0cb2d2000000b0063007a8f602mr2021882qvf.7.1689274184009; Thu, 13 Jul 2023 11:49:44 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id c13-20020a0cf2cd000000b0060530c942f4sm3313537qvm.46.2023.07.13.11.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 11:49:43 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: copy elision of object arg in static memfn call [PR110441] Date: Thu, 13 Jul 2023 14:49:23 -0400 Message-ID: <20230713184923.3699777-1-ppalka@redhat.com> X-Mailer: git-send-email 2.41.0.327.gaa9166bcc0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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, 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771332421001382688 X-GMAIL-MSGID: 1771332421001382688 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Here the call A().f() is represented as a COMPOUND_EXPR whose first operand is the otherwise unused object argument A() and second operand is the call result (both are TARGET_EXPRs). Within the return statement, this outermost COMPOUND_EXPR ends up foiling the copy elision check in build_special_member_call, resulting in us introducing a bogus call to the deleted move constructor. (Within the variable initialization, which goes through ocp_convert instead of convert_for_initialization, we've already been eliding the copy despite the outermost COMPOUND_EXPR ever since r10-7410-g72809d6fe8e085 made ocp_convert look through COMPOUND_EXPR). In contrast, I noticed '(A(), A::f())' (which should be equivalent to the above call) is represented with the COMPOUND_EXPR inside the RHS's TARGET_EXPR initializer thanks to a special case in cp_build_compound_expr thus avoiding the issue. So this patch fixes this by making keep_unused_object_arg use cp_build_compound_expr as well. PR c++/110441 gcc/cp/ChangeLog: * call.cc (keep_unused_object_arg): Use cp_build_compound_expr instead of building a COMPOUND_EXPR directly. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/elide8.C: New test. --- gcc/cp/call.cc | 2 +- gcc/testsuite/g++.dg/cpp1z/elide8.C | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/elide8.C diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 119063979fa..b0a69cb46d4 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -5218,7 +5218,7 @@ keep_unused_object_arg (tree result, tree obj, tree fn) if (TREE_THIS_VOLATILE (a)) a = build_this (a); if (TREE_SIDE_EFFECTS (a)) - return build2 (COMPOUND_EXPR, TREE_TYPE (result), a, result); + return cp_build_compound_expr (a, result, tf_warning_or_error); return result; } diff --git a/gcc/testsuite/g++.dg/cpp1z/elide8.C b/gcc/testsuite/g++.dg/cpp1z/elide8.C new file mode 100644 index 00000000000..7d471be8a2a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/elide8.C @@ -0,0 +1,25 @@ +// PR c++/110441 +// { dg-do compile { target c++11 } } + +struct immovable { + immovable(immovable &&) = delete; +}; + +struct A { + static immovable f(); +}; + +immovable f() { + immovable m = A().f(); // { dg-error "deleted" "" { target c++14_down } } + return A().f(); // { dg-error "deleted" "" { target c++14_down } } +} + +struct B { + A* operator->(); +}; + +immovable g() { + B b; + immovable m = b->f(); // { dg-error "deleted" "" { target c++14_down } } + return b->f(); // { dg-error "deleted" "" { target c++14_down } } +}