From patchwork Mon Aug 15 10:31:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp1279009pxh; Mon, 15 Aug 2022 03:32:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4oyR5uejk1C9RFvgrx7gorI2VZJ0x0VotCW2LDI7jPQwMkTBziRiCm/H+3WthBh/yxvClZ X-Received: by 2002:a17:906:93f0:b0:730:6d25:8a1e with SMTP id yl16-20020a17090693f000b007306d258a1emr10004127ejb.431.1660559520880; Mon, 15 Aug 2022 03:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660559520; cv=none; d=google.com; s=arc-20160816; b=EXxTJpYLOXtNhmbazn8C/b2IEyyiMcMTN4nulvZ3Db9FhPxfHQymTz+4CZplYG1x0R lNw6DTlsQueC6VZ1u43MYmnxflBlcZbT5Q0YbMAexlG4/MJ4oJXOss3pl8fh3+o1bFAB N6OpleCVSBlMiinko+WTdylZHQBMs5Zz4st/wDLfS6HgeU3tvuiLREREVKbZwdymTDhc pvaUzQ54MVHgGz+LJKvva4rTQVdeWn87Vuk4rnsOPkDSMz6xI9kBcWiRaYuxMAsaUu/z iQPCQlFxZCPR2NkAStw4A09CllsimNiuFPg68IarnrvEuF+JIsr2AwUS7+nFEB3W9tIx H6Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=ztnvE9AzbVlr5Fcj6TrjKaFjEOBGUuVDTPFAem8L2Mc=; b=zduTZkPox8zGOtKQUWHglXWTnLIBofELAYNy2FU5DrjqnKJivBePiK8g62sxBSNCCt XaQ9HS/8yyDHcXUAhLC6Y5Cr3jqyAsB6PNDK0UG+45ZlbRjeiQvCXsyuPZLhG714Gu0X jAq7rMAPX9D1n0yBqRGp9wnGP9mCSlH6hBzoxpXjQOatK8xT8/dDDkeFYzi+pwhm2gKE kRgtBNRNUfpGqONkLYgRa3uFWDdGdZjJat5u8/zjI4bKjKOTnVOZuVrRZosinsX/puRS pBKNIHmGNkUg5qk3XFJXoyBeMSFxqVTX6XLpduIKrNkbXZFTRsafLsRn7ZhxthQmRjBT Ljhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pMvCtlpE; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 9-20020a508749000000b0043cd07bb8c3si6754906edv.380.2022.08.15.03.32.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 03:32:00 -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=pMvCtlpE; 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 8F7093857C46 for ; Mon, 15 Aug 2022 10:31:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F7093857C46 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660559519; bh=ztnvE9AzbVlr5Fcj6TrjKaFjEOBGUuVDTPFAem8L2Mc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=pMvCtlpEjcyR4Dvr1wZUsguUJa54eqvg7H9ccH3QOhiR1C9ovyeW9Xxzx4n05E1tt TnOiW+dhekhX68XWVB0R3vqUl6Cg69eL6D+og4HYR9GfzjWq/XqnwJ2K1+86FeiwAl 5ZgUo5LkkOVKZxXbD9yroMwyk6inngqdG/el4/Ko= 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 72BE83858D32 for ; Mon, 15 Aug 2022 10:31:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72BE83858D32 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-225-aHIJBlLcMdidjpIhbZEU8w-1; Mon, 15 Aug 2022 06:31:15 -0400 X-MC-Unique: aHIJBlLcMdidjpIhbZEU8w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C1F783C10140 for ; Mon, 15 Aug 2022 10:31:14 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 60BD2C15BAD; Mon, 15 Aug 2022 10:31:13 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 27FAVAbi1240943 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 Aug 2022 12:31:11 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 27FAVAKT1240942; Mon, 15 Aug 2022 12:31:10 +0200 Date: Mon, 15 Aug 2022 12:31:10 +0200 To: Jason Merrill Subject: [PATCH] c++: Implement P2327R1 - De-deprecating volatile compound operations Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: Marek Polacek , gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741222860429898658?= X-GMAIL-MSGID: =?utf-8?q?1741222860429898658?= Hi! From what I can see, this has been voted in as a DR and as it means we warn less often than before in -std={gnu,c}++2{0,3} modes or with -Wvolatile, I wonder if it shouldn't be backported to affected release branches as well. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-08-15 Jakub Jelinek * typeck.cc (cp_build_modify_expr): Implement P2327R1 - De-deprecating volatile compound operations. Don't warn for |=, &= or ^= with volatile lhs. * expr.cc (mark_use) : Adjust warning wording, leave out simple. * g++.dg/cpp2a/volatile1.C: Adjust for de-deprecation of volatile compound |=, &= and ^= operations. * g++.dg/cpp2a/volatile3.C: Likewise. * g++.dg/cpp2a/volatile5.C: Likewise. Jakub --- gcc/cp/typeck.cc.jj 2022-06-17 17:36:19.689107831 +0200 +++ gcc/cp/typeck.cc 2022-08-14 11:14:15.368316963 +0200 @@ -9136,10 +9136,14 @@ cp_build_modify_expr (location_t loc, tr /* An expression of the form E1 op= E2. [expr.ass] says: "Such expressions are deprecated if E1 has volatile-qualified - type." We warn here rather than in cp_genericize_r because + type and op is not one of the bitwise operators |, &, ^." + We warn here rather than in cp_genericize_r because for compound assignments we are supposed to warn even if the assignment is a discarded-value expression. */ - if (TREE_THIS_VOLATILE (lhs) || CP_TYPE_VOLATILE_P (lhstype)) + if (modifycode != BIT_AND_EXPR + && modifycode != BIT_IOR_EXPR + && modifycode != BIT_XOR_EXPR + && (TREE_THIS_VOLATILE (lhs) || CP_TYPE_VOLATILE_P (lhstype))) warning_at (loc, OPT_Wvolatile, "compound assignment with %-qualified left " "operand is deprecated"); --- gcc/cp/expr.cc.jj 2022-06-27 11:18:02.268063761 +0200 +++ gcc/cp/expr.cc 2022-08-14 11:41:37.555649422 +0200 @@ -220,7 +220,7 @@ mark_use (tree expr, bool rvalue_p, bool case MODIFY_EXPR: { tree lhs = TREE_OPERAND (expr, 0); - /* [expr.ass] "A simple assignment whose left operand is of + /* [expr.ass] "An assignment whose left operand is of a volatile-qualified type is deprecated unless the assignment is either a discarded-value expression or appears in an unevaluated context." */ @@ -230,7 +230,7 @@ mark_use (tree expr, bool rvalue_p, bool && !TREE_THIS_VOLATILE (expr)) { if (warning_at (location_of (expr), OPT_Wvolatile, - "using value of simple assignment with " + "using value of assignment with " "%-qualified left operand is " "deprecated")) /* Make sure not to warn about this assignment again. */ --- gcc/testsuite/g++.dg/cpp2a/volatile1.C.jj 2020-07-28 15:39:10.013756159 +0200 +++ gcc/testsuite/g++.dg/cpp2a/volatile1.C 2022-08-14 11:46:42.721626890 +0200 @@ -56,6 +56,9 @@ fn2 () vi = i; vi = i = 42; i = vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + i = vi |= 42; // { dg-warning "using value of assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + i = vi &= 42; // { dg-warning "using value of assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + i = vi ^= 42; // { dg-warning "using value of assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } &(vi = i); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } (vi = 42, 45); (i = vi = 42, 10); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } @@ -74,8 +77,9 @@ fn2 () vi += i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } vi -= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } vi %= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } - vi ^= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } - vi |= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + vi ^= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } + vi |= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } + vi &= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi /= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } vi = vi += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } vi += vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } @@ -131,7 +135,8 @@ void raccoon () volatile T t, u; t = 42; u = t = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } - t &= 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + t += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" "" { target c++20 } } + t &= 42; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } } void --- gcc/testsuite/g++.dg/cpp2a/volatile3.C.jj 2020-01-12 11:54:37.149402305 +0100 +++ gcc/testsuite/g++.dg/cpp2a/volatile3.C 2022-08-14 11:47:05.691324132 +0200 @@ -57,6 +57,9 @@ fn2 () vi = i; vi = i = 42; i = vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + i = vi |= 42; // { dg-warning "using value of assignment with .volatile.-qualified left operand is deprecated" } + i = vi &= 42; // { dg-warning "using value of assignment with .volatile.-qualified left operand is deprecated" } + i = vi ^= 42; // { dg-warning "using value of assignment with .volatile.-qualified left operand is deprecated" } &(vi = i); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } (vi = 42, 45); (i = vi = 42, 10); // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } @@ -75,8 +78,9 @@ fn2 () vi += i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } vi -= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } vi %= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } - vi ^= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } - vi |= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + vi ^= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } + vi |= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } + vi &= i; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } vi /= i; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } vi = vi += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } vi += vi = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } @@ -132,7 +136,8 @@ void raccoon () volatile T t, u; t = 42; u = t = 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } - t &= 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + t += 42; // { dg-warning "assignment with .volatile.-qualified left operand is deprecated" } + t &= 42; // { dg-bogus "assignment with .volatile.-qualified left operand is deprecated" } } void --- gcc/testsuite/g++.dg/cpp2a/volatile5.C.jj 2021-02-08 19:07:33.110166905 +0100 +++ gcc/testsuite/g++.dg/cpp2a/volatile5.C 2022-08-14 11:42:47.779723765 +0200 @@ -8,8 +8,8 @@ f (bool b) { (b ? x : y) = 1; (b ? x : y) += 1; // { dg-warning "compound assignment" "" { target c++20 } } - z = (b ? x : y) = 1; // { dg-warning "using value of simple assignment" "" { target c++20 } } - ((z = 2) ? x : y) = 1; // { dg-warning "using value of simple assignment" "" { target c++20 } } - (b ? (x = 2) : y) = 1; // { dg-warning "using value of simple assignment" "" { target c++20 } } - (b ? x : (y = 5)) = 1; // { dg-warning "using value of simple assignment" "" { target c++20 } } + z = (b ? x : y) = 1; // { dg-warning "using value of assignment" "" { target c++20 } } + ((z = 2) ? x : y) = 1; // { dg-warning "using value of assignment" "" { target c++20 } } + (b ? (x = 2) : y) = 1; // { dg-warning "using value of assignment" "" { target c++20 } } + (b ? x : (y = 5)) = 1; // { dg-warning "using value of assignment" "" { target c++20 } } }