Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932512AbcDTHZy (ORCPT ); Wed, 20 Apr 2016 03:25:54 -0400 Received: from smtprelay0109.hostedemail.com ([216.40.44.109]:60619 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932256AbcDTHZx (ORCPT ); Wed, 20 Apr 2016 03:25:53 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:334:355:368:369:379:541:599:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1540:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3866:3867:3870:3871:3872:3874:4321:5007:7903:10004:10400:10848:11232:11658:11783:11914:12043:12517:12519:12740:13069:13161:13229:13311:13357:13439:13894:14181:14659:14721:21080:30054:30089:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: bit69_15e3cd2a0cf57 X-Filterd-Recvd-Size: 2317 Message-ID: <1461137134.1917.48.camel@perches.com> Subject: Re: [Cocci] coccinelle: bool if (foo) return true; else return false; From: Joe Perches To: Michael Stefaniuc , Julia Lawall Cc: cocci , LKML Date: Wed, 20 Apr 2016 00:25:34 -0700 In-Reply-To: <57172D78.707@redhat.com> References: <1460828078-5224-1-git-send-email-dave@stgolabs.net> <1460833453.19090.79.camel@perches.com> <1460836099.19090.82.camel@perches.com> <1460881671.19090.90.camel@perches.com> <1460908959.19090.95.camel@perches.com> <1460915801.19090.100.camel@perches.com> <1461093152.1917.26.camel@perches.com> <57172D78.707@redhat.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 873 Lines: 34 On Wed, 2016-04-20 at 09:19 +0200, Michael Stefaniuc wrote: > On 04/19/2016 09:15 PM, Julia Lawall wrote: > > On Tue, 19 Apr 2016, Joe Perches wrote: > > > There's ~150 of these in the kernel. > > > > > > Maybe there's use for this conversion to be added > > > to scripts/coccinelle/misc/boolreturn.cocci or in > > > a separate file. > > > > > > $ cat booltruefalse.cocci > > > @@ > > > identifier fn; > > > expression e; > > > typedef bool; > > > symbol true; > > > symbol false; > > > @@ > > > > > > bool fn ( ... ) > > > { > > > <... > > > - if (e) return true; else return false; > > > + return e; > Shouldn't that be: > ????return !!e > ? No, it's not necessary. The compiler does that because the return type is bool 6.3.1.2 Boolean type When any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1.