From patchwork Wed Jun 26 19:00:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Martin X-Patchwork-Id: 1952765 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=nasilyan.com header.i=@nasilyan.com header.a=rsa-sha256 header.s=xce2voaxvxhmx73p47whqmbxwwvd7qkl header.b=PAAfDY7O; dkim=pass (1024-bit key; unprotected) header.d=amazonses.com header.i=@amazonses.com header.a=rsa-sha256 header.s=uku4taia5b5tsbglxyj6zym32efj7xqv header.b=BxB6HaVx; 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 4W8WJK1j4Rz20Xf for ; Thu, 27 Jun 2024 05:01:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1BE903875441 for ; Wed, 26 Jun 2024 19:01:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from a51-218.smtp-out.eu-west-1.amazonses.com (a51-218.smtp-out.eu-west-1.amazonses.com [54.240.51.218]) by sourceware.org (Postfix) with ESMTPS id 161413871016 for ; Wed, 26 Jun 2024 19:00:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 161413871016 Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=nasilyan.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eu-west-1.amazonses.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 161413871016 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.240.51.218 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719428460; cv=none; b=nprwBS2WojypsLKXji9K8hVUQJSsF0Abk+YzM+NOS5uAQKcB+hehxs7N56ocNIPVxbM+RwE24zfBhL4teA9jF/mzwMIeGsW3Nvg5PVXeOOdIIKWb9oOhltzS9De7B1WVs9QnuDbTg3JWZ90VqCMtxcNK6TrRKhuW4lQBV/JFDsg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719428460; c=relaxed/simple; bh=IrekTm44Ne12pEdTQ7g4YAQG2lyVFQlrnib1usiRKuw=; h=DKIM-Signature:DKIM-Signature:Subject:From:To:Date:Mime-Version: Message-ID; b=VyMkQxpGcss7gTKlMv83AfAKx29a3d2YfNEmb3WUlSTDt2HWn3X/+qWSUUN0K5UvmuYrA5kCcH6ZRuyFZjBwxM79yWUIRoMjJV+7GQX1FGEVY+mNwREdEXG8dKI+bAn/xdIdoT4x5xv49HA/xoCLxj4hw8kb3A9JofR+vIzRJ3U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=xce2voaxvxhmx73p47whqmbxwwvd7qkl; d=nasilyan.com; t=1719428457; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id; bh=IrekTm44Ne12pEdTQ7g4YAQG2lyVFQlrnib1usiRKuw=; b=PAAfDY7OOJ32I5zpn3e/5SKJ4Angq3l/N8pWy/26Vtj77xja2JsiNpujUDjWhN/q S9Rw4jfCuQkpvGttS+wvzrG3bL9knUqXAW3IrNLkt1oxJYWL/HifB8DfGcPtpCNlurI PB7pZTMG2vAmBO1vyvFCfPe1EQC+hsSbhj9hXxXo= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1719428457; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id:Feedback-ID; bh=IrekTm44Ne12pEdTQ7g4YAQG2lyVFQlrnib1usiRKuw=; b=BxB6HaVx1iE8TDa86jAPCE4Cq/F6ouKd/SP3VcPeFs2eJgbGjWJS68EMf3Vr8KJ5 noSE2fYN/KEM0kx9YpXuysLVKAZSe7yMP4+bPf0YeBUQdbK+qCpU/n4hX0GiSNCRp/P 26RToFNSafGtRJkXRKVURfHqjE0s6jqHRNaSqCKg= Subject: [PATCH] c++: Relax too strict assert in stabilize_expr [PR111160] From: =?utf-8?q?Simon_Martin?= To: =?utf-8?q?gcc-patches=40gcc=2Egnu=2Eorg?= Date: Wed, 26 Jun 2024 19:00:57 +0000 Mime-Version: 1.0 References: <20240626190054.57209-1-simon@nasilyan.com> X-Mailer: Amazon WorkMail Thread-Index: AQHax/sssD4HNKomQ36MYEqUvep7aA== Thread-Topic: [PATCH] c++: Relax too strict assert in stabilize_expr [PR111160] X-Original-Mailer: git-send-email 2.44.0 X-Wm-Sent-Timestamp: 1719428456 Message-ID: <0102019055ec2368-f8b335ab-baf4-421a-8748-f131254376c3-000000@eu-west-1.amazonses.com> Feedback-ID: ::1.eu-west-1.b24dn6frgCi6dh20skzbuMRr7UL8M6Soir/3ogtEjHQ=:AmazonSES X-SES-Outgoing: 2024.06.26-54.240.51.218 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 The case in the ticket is an ICE on invalid due to an assert in stabilize_expr, but the underlying issue can actually trigger on this *valid* code: === cut here === struct TheClass { TheClass() {} TheClass(volatile TheClass& t) {} TheClass operator=(volatile TheClass& t) volatile { return t; } }; void the_func() { volatile TheClass x, y, z; (false ? x : y) = z; } === cut here === The problem is that stabilize_expr asserts that it returns an expression without TREE_SIDE_EFFECTS, which can't be if the involved type is volatile. This patch relaxes the assert to accept having TREE_THIS_VOLATILE on the returned expression. Successfully tested on x86_64-pc-linux-gnu. PR c++/111160 gcc/cp/ChangeLog: * tree.cc (stabilize_expr): Stabilized expressions can have TREE_SIDE_EFFECTS if they're volatile. gcc/testsuite/ChangeLog: * g++.dg/overload/error8.C: New test. * g++.dg/overload/volatile2.C: New test. --- gcc/cp/tree.cc | 2 +- gcc/testsuite/g++.dg/overload/error8.C | 9 +++++++++ gcc/testsuite/g++.dg/overload/volatile2.C | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/overload/error8.C create mode 100644 gcc/testsuite/g++.dg/overload/volatile2.C diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 28648c14c6d..dfd4a3a948b 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -5969,7 +5969,7 @@ stabilize_expr (tree exp, tree* initp) } *initp = init_expr; - gcc_assert (!TREE_SIDE_EFFECTS (exp)); + gcc_assert (!TREE_SIDE_EFFECTS (exp) || TREE_THIS_VOLATILE (exp)); return exp; } diff --git a/gcc/testsuite/g++.dg/overload/error8.C b/gcc/testsuite/g++.dg/overload/error8.C new file mode 100644 index 00000000000..a7e745860e0 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/error8.C @@ -0,0 +1,9 @@ +// PR c++/111160 +// { dg-do compile { target c++11 } } + +class TheClass {}; // { dg-error "discards|bind|discards|bind" } +void the_func() { + TheClass x; + volatile TheClass y; + (false ? x : x) = y; // { dg-error "ambiguous|ambiguous" } +} diff --git a/gcc/testsuite/g++.dg/overload/volatile2.C b/gcc/testsuite/g++.dg/overload/volatile2.C new file mode 100644 index 00000000000..9f27357aed6 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/volatile2.C @@ -0,0 +1,12 @@ +// PR c++/111160 +// { dg-do compile { target c++11 } } + +struct TheClass { + TheClass() {} + TheClass(volatile TheClass& t) {} + TheClass operator=(volatile TheClass& t) volatile { return t; } +}; +void the_func() { + volatile TheClass x, y, z; + (false ? x : y) = z; +}