From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751598AbdG0RTZ (ORCPT ); Thu, 27 Jul 2017 13:19:25 -0400 Received: from gateway23.websitewelcome.com ([192.185.49.219]:41141 "EHLO gateway23.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751122AbdG0RTY (ORCPT ); Thu, 27 Jul 2017 13:19:24 -0400 X-Greylist: delayed 1234 seconds by postgrey-1.27 at vger.kernel.org; Thu, 27 Jul 2017 13:19:24 EDT Date: Thu, 27 Jul 2017 11:58:48 -0500 From: "Gustavo A. R. Silva" To: Julia Lawall , Gilles Muller , Nicolas Palix , Michal Marek Cc: cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org, Pavel Machek , Borislav Petkov , Peter Senna Tschudin , "Gustavo A. R. Silva" Subject: [PATCH] Coccinelle: Script to remove unnecessary static on local variables Message-ID: <20170727165848.GA15831@embeddedgus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.152.151.15 X-Exim-ID: 1dam7d-0014pE-0n X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedgus) [189.152.151.15]:39644 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 7 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Coccinelle script to remove unnecessary static on local variables when the variables are not used before update. Signed-off-by: Gustavo A. R. Silva --- scripts/coccinelle/misc/static_unnecessary.cocci | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scripts/coccinelle/misc/static_unnecessary.cocci diff --git a/scripts/coccinelle/misc/static_unnecessary.cocci b/scripts/coccinelle/misc/static_unnecessary.cocci new file mode 100644 index 0000000..79fc899 --- /dev/null +++ b/scripts/coccinelle/misc/static_unnecessary.cocci @@ -0,0 +1,89 @@ +/// Drop static on local variable when the variable is not used before update. +//# NOTE: Be aware that if a large object is initialized all at once, it might +//# not be wise to remove the static because that would increase the risk of a +//# stack overflow. +/// +// Confidence: Moderate +// Copyright: (C) 2017 Julia Lawall, Inria. GPLv2. +// Copyright: (C) 2017 Gustavo A. R. Silva, Core Infrastructure Initiative. +// Copyright: (C) 2017 GPLv2. +// URL: http://coccinelle.lip6.fr/ +// Options: --no-includes --include-headers +// Keywords: static + +virtual patch +virtual context +virtual org +virtual report + +// +@bad exists@ +position p; +identifier x; +expression e; +type T; +@@ + +static T x@p; +... when != x = e +x = <+...x...+> + +@worse exists@ +position p; +identifier x; +type T; +@@ + +static T x@p; +... + &x + +@modify depends on patch && !context && !org && !report@ +identifier x; +expression e; +type T; +position p != {bad.p,worse.p}; +@@ + +-static + T x@p; + ... when != x + when strict +?x = e; +// + + +// ---------------------------------------------------------------------------- + +@modify_context depends on !patch && (context || org || report) forall@ +type T; +identifier x; +expression e; +position p != {bad.p,worse.p}; +position j0; +@@ + +* static + T x@j0@p; + ... when != x + when strict +?x = e; + +// ---------------------------------------------------------------------------- + +@script:python modify_org depends on org@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.org.print_todo(j0[0], msg) + +// ---------------------------------------------------------------------------- + +@script:python modify_report depends on report@ +j0 << modify_context.j0; +@@ + +msg = "Unnecessary static on local variable." +coccilib.report.print_report(j0[0], msg) + -- 2.5.0