Re: [PATCH] scripts/coccinelle/misc/semicolon.cocci: Add unneededsemicolon test
From: Peter Senna Tschudin
Date: Sun Dec 09 2012 - 12:51:08 EST
On Sat, Dec 8, 2012 at 4:39 PM, Joe Perches <joe@xxxxxxxxxxx> wrote:
> On Sat, 2012-12-08 at 16:13 -0200, Peter Senna Tschudin wrote:
>> On Sat, Dec 8, 2012 at 3:45 PM, Joe Perches <joe@xxxxxxxxxxx> wrote:
>> > On Sat, 2012-12-08 at 15:34 -0200, Peter Senna Tschudin wrote:
>> >> This semantic patch looks for semicolons that can be removed without
>> >> changing the semantics of the code. The confidence is moderate
>> >> because there are some false positives on cases like:
>> >>
>> >> b/drivers/mmc/host/cb710-mmc.c:589
>> >> break;
>> >> case MMC_POWER_UP:
>> >> default:
>> >> - /* ignore */;
>> >> }
>> > []
>> >> diff --git a/scripts/coccinelle/misc/semicolon.cocci b/scripts/coccinelle/misc/semicolon.cocci
>> > []
>> >> +@r1@
>> >> +statement S;
>> >> +position p1;
>> >> +position p != {r_default.p, r_case.p};
>> >> +identifier label;
>> >> +@@
>> >> +(
>> >> +label:;
>> >> +|
>> >> +S@p1;@p
>> >> +)
>> >> +
>> >
>> > I believe this also fails on this case:
> []
>> > where gcc needs a semicolon after a label before a function exit.
>>
>> No it does not fail. This issue is switch/case specific. See how I've tested:
>
> Thanks Peter, I didn't notice the switch requirement.
>
> In this case, I'd suggest replacement of the
> nominally false positive ; with break;
I agree with you that the best is to replace ; with break; but I
prefer to not change the unneeded semicolon test semantic patch to add
breaks before ;. I can make other semantic patch for that. The point
is that adding break is more than detecting unneeded semicolons, so I
prefer to not mix the two.
But even with the moderate confidence this semantic patch seems to be
useful as new unneeded semicolons are being added to the Kernel.
>
> cheers, Joe
>
Thanks for your help!
Peter
--
Peter
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/