From patchwork Mon Jan 23 23:34:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1730771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=tLeAQesf; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P160b2JD9z23gY for ; Tue, 24 Jan 2023 10:35:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 568533858C39 for ; Mon, 23 Jan 2023 23:35:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 568533858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674516923; bh=3leuiGrN9l27ttOn0x8Es8IooHEq2eD1bus3aLlaGII=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tLeAQesfIx0ZSZw295WKtHcna3kwBF4BW5yvbev7/QI6KDqjkSUVPRZFGiII2LHb6 Yd9Mw4eyLKN2RC1wiTV3NvigVkD/ll7NkZ61FqogeoHRvmyJHLNuazVLR91n8kZm8F BGny7+NevpWGGa7nwhMSyhQ8up3deB1fLbM4xhvQ= 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 235133858D33 for ; Mon, 23 Jan 2023 23:35:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 235133858D33 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.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-241-9NrbJf6iNgqnF20XHB3k3A-1; Mon, 23 Jan 2023 18:34:59 -0500 X-MC-Unique: 9NrbJf6iNgqnF20XHB3k3A-1 Received: by mail-qk1-f197.google.com with SMTP id q21-20020a05620a0d9500b0070572ccdbf9so9889962qkl.10 for ; Mon, 23 Jan 2023 15:34:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3leuiGrN9l27ttOn0x8Es8IooHEq2eD1bus3aLlaGII=; b=W2i+7cluvaDhdPphWjDLB70znAVgI9jlLiM0Hi2GiwQl4ftOt7hlGdNPAMOdQlRQ0q mAhuD4/tshiL+FIHGNxkd3sQkg4BtJhgWXDG/9ODiM+l0TLi8W1yzJ+jQAWpMEeGHPwP diUSAfxYDI2HL62Bu4UMWXl+K/uu4GqdJOVKIhJWqqZEAmgncc2GSOIVCRWITnSHA/ut 3gCla1KsLaEOvT7/dJttVCwsihUKLdtQZdtfcdmvmKkUB5Wa2tkJ9KpDhlSwqn+dEOpL 1qHYXTQhlabP5NrRgooXuUHSqG62hPRiYwiHkcBqPH4t/4Xf76IakONfjQk+r3HZGIRw mn5Q== X-Gm-Message-State: AFqh2krrX+ihcjuuyRSgUH+FNd6Mr49Sovje/dzyt6bfPGbpR4oidhDC QiYCCfrG9GlhjXMqGjPD5smxM21cGaSCeqw6XTKAW8jZKMJ5DdTs6JEFTko4E2yhGg6JVh6kUkq LyZK+6lo1OzjIPAtUjxbEIeNd1NNkKQNi4xhufjMIpLecUMrCG9z9NrIB01Gp1TdeJw== X-Received: by 2002:a05:622a:1ccd:b0:3b6:3ca2:dde8 with SMTP id bc13-20020a05622a1ccd00b003b63ca2dde8mr34316885qtb.67.1674516898337; Mon, 23 Jan 2023 15:34:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXv+0ipitbmg1z/jA2gOH53haFvw4wRSxNlXie8zzCunrknVpy9KL8Eiki0uSfrqMa11SLAF3A== X-Received: by 2002:a05:622a:1ccd:b0:3b6:3ca2:dde8 with SMTP id bc13-20020a05622a1ccd00b003b63ca2dde8mr34316846qtb.67.1674516897863; Mon, 23 Jan 2023 15:34:57 -0800 (PST) Received: from jason.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 f1-20020ac840c1000000b003a981f7315bsm197273qtm.44.2023.01.23.15.34.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Jan 2023 15:34:57 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: TARGET_EXPR_ELIDING_P and std::move [PR107267] Date: Mon, 23 Jan 2023 18:34:53 -0500 Message-Id: <20230123233453.85393-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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_NONE, RCVD_IN_MSPIKE_H2, 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.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" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- With -ffold-simple-inlines, we turn calls to std::move into the static_cast equivalent. In this testcase, this exposes the FindResult temporary to copy elision which is not specified by the standard, through an optimization in gimplify_modify_expr_rhs. Since the type is not TREE_ADDRESSABLE, this is not detectable by the user, so we just need to soften the assert. PR c++/107267 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_gimplify_init_expr): Allow unexpected elision of trivial types. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/move2.C: New test. --- gcc/cp/cp-gimplify.cc | 5 ++++- gcc/testsuite/g++.dg/cpp0x/move2.C | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/move2.C base-commit: 72e46b3c7ad5e3d2c69868a510c00707c356106a diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 340b4641046..83ba1285bfd 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -250,7 +250,10 @@ cp_gimplify_init_expr (tree *expr_p) if (TREE_CODE (from) == TARGET_EXPR) if (tree init = TARGET_EXPR_INITIAL (from)) { - gcc_checking_assert (TARGET_EXPR_ELIDING_P (from)); + /* Make sure that we expected to elide this temporary. But also allow + gimplify_modify_expr_rhs to elide temporaries of trivial type. */ + gcc_checking_assert (TARGET_EXPR_ELIDING_P (from) + || !TREE_ADDRESSABLE (TREE_TYPE (from))); if (target_expr_needs_replace (from)) { /* If this was changed by cp_genericize_target_expr, we need to diff --git a/gcc/testsuite/g++.dg/cpp0x/move2.C b/gcc/testsuite/g++.dg/cpp0x/move2.C new file mode 100644 index 00000000000..b8c8683c4d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/move2.C @@ -0,0 +1,14 @@ +// PR c++/107267 +// { dg-do compile { target c++11 } } +// { dg-additional-options -ffold-simple-inlines } + +namespace std { + template _Tp &&move(_Tp &&); +} + +struct FindResult { + FindResult(); + int result; +}; + +FindResult pop_ret = std::move(FindResult());