From patchwork Thu Mar 31 21:57:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 604524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qbdfQ2ksvz9s9G for ; Fri, 1 Apr 2016 08:57:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=mSV/Q/vZ; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=yXT243FfiJEQJ+gV zUt//uL//ZxdpgjJxrK77VZ6TXmrxW3HtsZknLJy2I5Syufv7HS7wn5ZfS0HDFKz XzHDrA6IH6bTpW3zuDAS1m5xiFdQwJzTSuOx2UUJMvl5P0m0RK+oovkGco1bsNkM GLas73DnZ5YGnJ2eqg6GrJnZx1g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=fwLm4WgUirWwVqZznA3wtj wCTg8=; b=mSV/Q/vZBNJPGk394FEbvi6RpdFjfbHWVKT40uK/nejrTwKx8BMoXl z0xXGBIl2Xa+TirMphY5TQ3zK1dfNIv2YZbvP0vLJnsTsZtVZMeb+bYPhdqu9Yvb OQ9NYZTVRTixRHCB2v4Aygpwgn1g4M/7cxEuQPhxEOyE/FzZy2Dgw= Received: (qmail 49207 invoked by alias); 31 Mar 2016 21:57:23 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 49192 invoked by uid 89); 31 Mar 2016 21:57:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=3342 X-HELO: mail-qg0-f65.google.com Received: from mail-qg0-f65.google.com (HELO mail-qg0-f65.google.com) (209.85.192.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 31 Mar 2016 21:57:12 +0000 Received: by mail-qg0-f65.google.com with SMTP id b32so8253772qgf.2 for ; Thu, 31 Mar 2016 14:57:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=s+UUZoblBVOtA1TfD5v28u8Mqtw1q/Ov5kmus7p/Ch8=; b=LlpNwTg00OovyXH6I4AfdoI4KkwtUg012wmRexEer/MOvOjSRLWhtkHlMLGNkDrv8j n8u9+GrrWt+h6OLQOGfiXFpyk29Q75qTbKdfgbuD41M9em+Pf5HltJdRBh8UsNRUNiOL IGphSyeE74QMyr6vg1LTkJKDyfgi1hNCZonIaoGRKA0Q6D5LKs67CD3JQZdWa2Zugs/S MYk2MvXMdzljeauWMWJtDAodIIQApRWcRybZcFnmEDZNUaIHjJIgWFTNYCu4nUAVkRXe 8pn36VOq3ca9FVtSbe/isRy0e9m3eqPgdUCvV+WKrLAQ1JFMFULqpck5Gvq1fLzmGsDo yw/Q== X-Gm-Message-State: AD7BkJI4nPt+OXpB7ZjP1603b5yS7xcUvPRTLYan8TQDEHRZcZ/inPqxBL3eb4yJjVwVtQ== X-Received: by 10.140.173.133 with SMTP id t127mr2113535qht.23.1459461430361; Thu, 31 Mar 2016 14:57:10 -0700 (PDT) Received: from [192.168.1.130] (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id w66sm4808969qgd.26.2016.03.31.14.57.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Mar 2016 14:57:09 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 31 Mar 2016 17:57:08 -0400 (EDT) To: Jakub Jelinek cc: Patrick Palka , gcc-patches@gcc.gnu.org, jason@redhat.com Subject: Re: [PATCH 2/2] Fix C++ side of PR c/70436 (missing -Wparentheses warnings) In-Reply-To: <20160331213759.GQ3017@tucnak.redhat.com> Message-ID: References: <1459457644-20663-1-git-send-email-patrick@parcs.ath.cx> <20160331213759.GQ3017@tucnak.redhat.com> User-Agent: Alpine 2.20.11 (DEB 116 2015-12-14) MIME-Version: 1.0 On Thu, 31 Mar 2016, Jakub Jelinek wrote: > On Thu, Mar 31, 2016 at 04:54:04PM -0400, Patrick Palka wrote: > > I think that covers all the vanilla C++ constructs that this warning has > > to consider. As for C++ extensions, we still fail to warn for > > > > if (a) > > #pragma GCC ivdep > > while (1) > > if (b) > > bar (); > > else > > baz (); > > > > and > > > > if (a) > > _Cilk_for (int i = 0; i < 10; i++) > > if (b) > > bar (); > > else > > baz (); > > > > and probably other constructs. I suppose support for this can be > > implemented in a subsequent patch if deemed appropriate at this stage. > > It would probably just involve more threading of the parameter IF_P. > > > > Is this OK to commit after bootstrap + regtesting? > > If this makes it in, I can take care of OpenMP, perhaps Cilk+ too. > > > --- a/gcc/cp/parser.c > > +++ b/gcc/cp/parser.c > > @@ -2104,7 +2104,7 @@ static tree cp_parser_selection_statement > > static tree cp_parser_condition > > (cp_parser *); > > static tree cp_parser_iteration_statement > > - (cp_parser *, bool); > > + (cp_parser *, bool *if_p, bool); > > I wouldn't add a named argument where all others are unnamed in the > prototype. > > > static bool cp_parser_for_init_statement > > (cp_parser *, tree *decl); > > static tree cp_parser_for > > @@ -2127,7 +2127,7 @@ static void cp_parser_declaration_statement > > static tree cp_parser_implicitly_scoped_statement > > (cp_parser *, bool *, const token_indent_info &, vec * = NULL); > > static void cp_parser_already_scoped_statement > > - (cp_parser *, const token_indent_info &); > > + (cp_parser *, bool *if_p, const token_indent_info &); > > Likewise here. > > > +void > > +foo (void) > > +{ > > + if (a) /* { dg-warning "ambiguous" } */ > > + for (;;) > > + if (b) > > + bar (); > > + else > > + baz (); > > What about multiple nested for or while loops, like: > if (a) > for (i = 0; i < 10; i++) > for (j = 0; j < 10; j++) > if (b) > bar (); > else > baz (); > and similarly for multiple nested while loops? > I only see while (1) for (;;) in the test. > > Otherwise, I'll defer to Jason. > > Jakub > Thanks, patch updated with your requested changes. Here's an incremental diff of the changes (since they are relatively minor): diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index af2a8f2..6dd6280 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -2104,7 +2104,7 @@ static tree cp_parser_selection_statement static tree cp_parser_condition (cp_parser *); static tree cp_parser_iteration_statement - (cp_parser *, bool *if_p, bool); + (cp_parser *, bool *, bool); static bool cp_parser_for_init_statement (cp_parser *, tree *decl); static tree cp_parser_for @@ -2127,7 +2127,7 @@ static void cp_parser_declaration_statement static tree cp_parser_implicitly_scoped_statement (cp_parser *, bool *, const token_indent_info &, vec * = NULL); static void cp_parser_already_scoped_statement - (cp_parser *, bool *if_p, const token_indent_info &); + (cp_parser *, bool *, const token_indent_info &); /* Declarations [gram.dcl.dcl] */ diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-29.C b/gcc/testsuite/g++.dg/warn/Wparentheses-29.C index 125e6b4..7832415 100644 --- a/gcc/testsuite/g++.dg/warn/Wparentheses-29.C +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-29.C @@ -1,13 +1,15 @@ /* PR c/70436 */ /* { dg-options "-Wparentheses" } */ -int a, b; +int a, b, c; void bar (void); void baz (void); void foo (void) { + int i, j; + if (a) /* { dg-warning "ambiguous" } */ for (;;) if (b) @@ -31,6 +33,42 @@ foo (void) baz (); if (a) /* { dg-warning "ambiguous" } */ + while (1) + while (1) + if (b) + bar (); + else + baz (); + + if (a) /* { dg-warning "ambiguous" } */ + for (i = 0; i < 10; i++) + for (j = 0; j < 10; j++) + if (b) + bar (); + else + baz (); + + if (a) + for (i = 0; i < 10; i++) + if (b) /* { dg-warning "ambiguous" } */ + for (j = 0; j < 10; j++) + if (c) + bar (); + else + baz (); + + if (a) /* { dg-warning "ambiguous" } */ + for (i = 0; i < 10; i++) + if (b) + for (j = 0; j < 10; j++) + if (c) + bar (); + else + baz (); + else + bar (); + + if (a) /* { dg-warning "ambiguous" } */ for (;;) if (b) while (1)