Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1698204 > unrolled thread
| Started by | "Gustavo A. R. Silva" <gustavo@embeddedor.com> |
|---|---|
| First post | 2017-07-27 19:20 +0200 |
| Last post | 2017-07-29 07:10 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] Coccinelle: Script to remove unnecessary static on local variables "Gustavo A. R. Silva" <gustavo@embeddedor.com> - 2017-07-27 19:20 +0200
Re: [PATCH] Coccinelle: Script to remove unnecessary static on local variables Julia Lawall <julia.lawall@lip6.fr> - 2017-07-29 07:10 +0200
| From | "Gustavo A. R. Silva" <gustavo@embeddedor.com> |
|---|---|
| Date | 2017-07-27 19:20 +0200 |
| Subject | [PATCH] Coccinelle: Script to remove unnecessary static on local variables |
| Message-ID | <u7UC5-sM-1@gated-at.bofh.it> |
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
[toc] | [next] | [standalone]
| From | Julia Lawall <julia.lawall@lip6.fr> |
|---|---|
| Date | 2017-07-29 07:10 +0200 |
| Message-ID | <u8saK-60y-5@gated-at.bofh.it> |
| In reply to | #1698204 |
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
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web