From patchwork Sun Dec 13 16:12:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Uecker, Martin" X-Patchwork-Id: 1415609 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=med.uni-goettingen.de 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cv8gC3zrlz9sTL for ; Mon, 14 Dec 2020 03:12:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F819386101C; Sun, 13 Dec 2020 16:12:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail1.med.uni-goettingen.de (mail1.med.uni-goettingen.de [134.76.103.230]) by sourceware.org (Postfix) with ESMTPS id 780EC3857004 for ; Sun, 13 Dec 2020 16:12:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 780EC3857004 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=med.uni-goettingen.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=prvs=0616242b6b=martin.uecker@med.uni-goettingen.de Received: from umg-exc-2.ads.local.med.uni-goettingen.de ([10.76.100.69]:7925) by mail1.med.uni-goettingen.de with esmtps (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1koTyk-0003U6-2g; Sun, 13 Dec 2020 17:12:10 +0100 Received: from UMG-EXC-1.ads.local.med.uni-goettingen.de ([fe80::c97f:60fd:6a2d:e4b9]) by umg-exc-2.ads.local.med.uni-goettingen.de ([fe80::40b1:448:7be6:e2cf%13]) with mapi id 14.03.0487.000; Sun, 13 Dec 2020 17:12:10 +0100 From: "Uecker, Martin" To: "gcc-patches@gcc.gnu.org" Subject: [C PATCH] Avoid incorrect warning for volatile in compound expressions [PR 98260] Thread-Topic: [C PATCH] Avoid incorrect warning for volatile in compound expressions [PR 98260] Thread-Index: AQHW0Wq1BkOVZXrq0UOr3X9uH2gJxA== Date: Sun, 13 Dec 2020 16:12:09 +0000 Message-ID: <1607875929.20906.2.camel@med.uni-goettingen.de> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [134.76.125.21] Content-ID: <3574CD393C631C48A83FBF1865D29574@med.uni-goettingen.de> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: "joseph@codesourcery.com" Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Here is a patch that fixes an incorrect warning for volatile that appeared with the lvalue change.  -- Martin C: Avoid incorrect warning for volatile in compound expressions [PR98260]      2020-12-12  Martin Uecker        gcc/c/      PR c/98260      * c-parser.c (c_parser_expression): Look into      nop expression when marking expressions as read.       gcc/testsuite/      PR c/98260      * gcc.dg/unused-9.c: New test. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 87ee8f47806..1388a60c495 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -10615,8 +10615,14 @@ c_parser_expression (c_parser *parser)        c_parser_consume_token (parser);        expr_loc = c_parser_peek_token (parser)->location;        lhsval = expr.value; -      while (TREE_CODE (lhsval) == COMPOUND_EXPR) - lhsval = TREE_OPERAND (lhsval, 1); +      while (TREE_CODE (lhsval) == COMPOUND_EXPR +      || TREE_CODE (lhsval) == NOP_EXPR) + { +   if (TREE_CODE (lhsval) == COMPOUND_EXPR) +     lhsval = TREE_OPERAND (lhsval, 1); +   else +     lhsval = TREE_OPERAND (lhsval, 0); + }        if (DECL_P (lhsval) || handled_component_p (lhsval))   mark_exp_read (lhsval);        next = c_parser_expr_no_commas (parser, NULL); diff --git a/gcc/testsuite/gcc.dg/unused-9.c b/gcc/testsuite/gcc.dg/unused-9.c new file mode 100644 index 00000000000..b32f7ef6c03 --- /dev/null +++ b/gcc/testsuite/gcc.dg/unused-9.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + + +void g(void) +{ +  int i = 0; +  volatile int x; +  (x, i++); /* { dg-bogus "set but not used" } */ +} + +