Coccinelle Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] coccinelle: bool if (foo) return true; else return false;
       [not found]                 ` <alpine.DEB.2.02.1604172001410.2004@localhost6.localdomain6>
@ 2016-04-19 19:12                   ` Joe Perches
  2016-04-19 19:15                     ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2016-04-19 19:12 UTC (permalink / raw)
  To: cocci

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;
...>
}

@@
identifier fn;
expression e;
@@

bool fn ( ... )
{
<...
-	if (e) return false; else return true;
+	return !e;
...>
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Cocci] coccinelle: bool if (foo) return true; else return false;
  2016-04-19 19:12                   ` [Cocci] coccinelle: bool if (foo) return true; else return false; Joe Perches
@ 2016-04-19 19:15                     ` Julia Lawall
  2016-04-20  7:19                       ` Michael Stefaniuc
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2016-04-19 19:15 UTC (permalink / raw)
  To: cocci



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;
> ...>
> }
> 
> @@
> identifier fn;
> expression e;
> @@
> 
> bool fn ( ... )
> {
> <...
> -	if (e) return false; else return true;
> +	return !e;
> ...>
> }

Thanks for the suggestion.  I will take care of it shortly.

julia

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Cocci] coccinelle: bool if (foo) return true; else return false;
  2016-04-19 19:15                     ` Julia Lawall
@ 2016-04-20  7:19                       ` Michael Stefaniuc
  2016-04-20  7:25                         ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Stefaniuc @ 2016-04-20  7:19 UTC (permalink / raw)
  To: cocci

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
?


>> ...>
>> }
>>
>> @@
>> identifier fn;
>> expression e;
>> @@
>>
>> bool fn ( ... )
>> {
>> <...
>> -	if (e) return false; else return true;
>> +	return !e;
>> ...>
>> }
> 
> Thanks for the suggestion.  I will take care of it shortly.


bye
	michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Cocci] coccinelle: bool if (foo) return true; else return false;
  2016-04-20  7:19                       ` Michael Stefaniuc
@ 2016-04-20  7:25                         ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2016-04-20  7:25 UTC (permalink / raw)
  To: cocci

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-20  7:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1460828078-5224-1-git-send-email-dave@stgolabs.net>
     [not found] ` <1460833453.19090.79.camel@perches.com>
     [not found]   ` <1460836099.19090.82.camel@perches.com>
     [not found]     ` <alpine.DEB.2.02.1604170743060.2068@localhost6.localdomain6>
     [not found]       ` <1460881671.19090.90.camel@perches.com>
     [not found]         ` <alpine.DEB.2.02.1604171337450.2034@localhost6.localdomain6>
     [not found]           ` <1460908959.19090.95.camel@perches.com>
     [not found]             ` <alpine.DEB.2.02.1604171944500.2004@localhost6.localdomain6>
     [not found]               ` <1460915801.19090.100.camel@perches.com>
     [not found]                 ` <alpine.DEB.2.02.1604172001410.2004@localhost6.localdomain6>
2016-04-19 19:12                   ` [Cocci] coccinelle: bool if (foo) return true; else return false; Joe Perches
2016-04-19 19:15                     ` Julia Lawall
2016-04-20  7:19                       ` Michael Stefaniuc
2016-04-20  7:25                         ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox