linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Coccinelle: Script to remove unnecessary static on local variables
@ 2017-07-27 16:58 Gustavo A. R. Silva
  2017-07-29  5:04 ` Julia Lawall
  2017-08-01  4:38 ` [PATCH v2] " Gustavo A. R. Silva
  0 siblings, 2 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2017-07-27 16:58 UTC (permalink / raw)
  To: Julia Lawall, Gilles Muller, Nicolas Palix, Michal Marek
  Cc: cocci, linux-kernel, Pavel Machek, Borislav Petkov,
	Peter Senna Tschudin, Gustavo A. R. Silva

Coccinelle script to remove unnecessary static on local variables when
the variables are not used before update.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 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
+
+// <smpl>
+@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;
+// </smpl>
+
+
+// ----------------------------------------------------------------------------
+
+@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

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

* Re: [PATCH] Coccinelle: Script to remove unnecessary static on local variables
  2017-07-27 16:58 [PATCH] Coccinelle: Script to remove unnecessary static on local variables Gustavo A. R. Silva
@ 2017-07-29  5:04 ` Julia Lawall
  2017-08-01  4:38 ` [PATCH v2] " Gustavo A. R. Silva
  1 sibling, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2017-07-29  5:04 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Julia Lawall, Gilles Muller, Nicolas Palix, Michal Marek, cocci,
	linux-kernel, Pavel Machek, Borislav Petkov,
	Peter Senna Tschudin



On Thu, 27 Jul 2017, Gustavo A. R. Silva wrote:

> Coccinelle script to remove unnecessary static on local variables when
> the variables are not used before update.
>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Acked-by: Julia Lawall <julia.lawall@lip6.fr>

> ---
>  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
> +
> +// <smpl>
> +@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;
> +// </smpl>
> +
> +
> +// ----------------------------------------------------------------------------
> +
> +@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
>
>

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

* [PATCH v2] Coccinelle: Script to remove unnecessary static on local variables
  2017-07-27 16:58 [PATCH] Coccinelle: Script to remove unnecessary static on local variables Gustavo A. R. Silva
  2017-07-29  5:04 ` Julia Lawall
@ 2017-08-01  4:38 ` Gustavo A. R. Silva
  2017-08-01  5:04   ` Julia Lawall
  1 sibling, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2017-08-01  4:38 UTC (permalink / raw)
  To: Julia Lawall, Gilles Muller, Nicolas Palix, Michal Marek
  Cc: cocci, linux-kernel, Pavel Machek, Borislav Petkov,
	Peter Senna Tschudin, Gustavo A. R. Silva

Coccinelle script to remove unnecessary static on local variables when
the variables are not used before update.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
Changes in v2:
 Update header and Copyright note.

 scripts/coccinelle/misc/static_unnecessary.cocci | 96 ++++++++++++++++++++++++
 1 file changed, 96 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..2b10586
--- /dev/null
+++ b/scripts/coccinelle/misc/static_unnecessary.cocci
@@ -0,0 +1,96 @@
+/// Drop static on local variable when the variable is not used before update.
+//#
+//# Removing unnecessary static on local variables reduces the code
+//# size and increases maintainability.
+//#
+//# On the other hand, even though it is rare, 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.
+// URL: http://coccinelle.lip6.fr/
+// Copyright: (C) 2017 Gustavo A. R. Silva. GPLv2.
+// Work supported by a grant from
+// The Linux Foundation's Core Infrastructure Initiative.
+// URL: https://www.coreinfrastructure.org/
+// Options: --no-includes --include-headers
+// Keywords: static
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+// <smpl>
+@bad exists@
+position p;
+identifier x;
+expression e;
+type T;
+@@
+
+T x@p;
+... when != x = e
+x = <+...x...+>
+
+@worse exists@
+position p;
+identifier x;
+type T;
+@@
+
+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;
+// </smpl>
+
+
+// ----------------------------------------------------------------------------
+
+@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

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

* Re: [PATCH v2] Coccinelle: Script to remove unnecessary static on local variables
  2017-08-01  4:38 ` [PATCH v2] " Gustavo A. R. Silva
@ 2017-08-01  5:04   ` Julia Lawall
  0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2017-08-01  5:04 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Julia Lawall, Gilles Muller, Nicolas Palix, Michal Marek, cocci,
	linux-kernel, Pavel Machek, Borislav Petkov,
	Peter Senna Tschudin

Acked-by: Julia Lawall <julia.lawall@lip6.fr>

On Mon, 31 Jul 2017, Gustavo A. R. Silva wrote:

> Coccinelle script to remove unnecessary static on local variables when
> the variables are not used before update.
>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
> Changes in v2:
>  Update header and Copyright note.
>
>  scripts/coccinelle/misc/static_unnecessary.cocci | 96 ++++++++++++++++++++++++
>  1 file changed, 96 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..2b10586
> --- /dev/null
> +++ b/scripts/coccinelle/misc/static_unnecessary.cocci
> @@ -0,0 +1,96 @@
> +/// Drop static on local variable when the variable is not used before update.
> +//#
> +//# Removing unnecessary static on local variables reduces the code
> +//# size and increases maintainability.
> +//#
> +//# On the other hand, even though it is rare, 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.
> +// URL: http://coccinelle.lip6.fr/
> +// Copyright: (C) 2017 Gustavo A. R. Silva. GPLv2.
> +// Work supported by a grant from
> +// The Linux Foundation's Core Infrastructure Initiative.
> +// URL: https://www.coreinfrastructure.org/
> +// Options: --no-includes --include-headers
> +// Keywords: static
> +
> +virtual patch
> +virtual context
> +virtual org
> +virtual report
> +
> +// <smpl>
> +@bad exists@
> +position p;
> +identifier x;
> +expression e;
> +type T;
> +@@
> +
> +T x@p;
> +... when != x = e
> +x = <+...x...+>
> +
> +@worse exists@
> +position p;
> +identifier x;
> +type T;
> +@@
> +
> +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;
> +// </smpl>
> +
> +
> +// ----------------------------------------------------------------------------
> +
> +@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
>
>

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

end of thread, other threads:[~2017-08-01  5:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-27 16:58 [PATCH] Coccinelle: Script to remove unnecessary static on local variables Gustavo A. R. Silva
2017-07-29  5:04 ` Julia Lawall
2017-08-01  4:38 ` [PATCH v2] " Gustavo A. R. Silva
2017-08-01  5:04   ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).