All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts: coccinelle: check for !(un)?likely usage
@ 2019-08-25 13:05 ` Denis Efremov
  0 siblings, 0 replies; 54+ messages in thread
From: Denis Efremov @ 2019-08-25 13:05 UTC (permalink / raw)
  To: cocci
  Cc: Denis Efremov, linux-kernel, Julia Lawall, Gilles Muller,
	Nicolas Palix, Michal Marek

This patch adds coccinelle script for detecting !likely and !unlikely
usage. It's better to use unlikely instead of !likely and vice versa.

Signed-off-by: Denis Efremov <efremov@linux.com>
---
 scripts/coccinelle/misc/unlikely.cocci | 70 ++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 scripts/coccinelle/misc/unlikely.cocci

diff --git a/scripts/coccinelle/misc/unlikely.cocci b/scripts/coccinelle/misc/unlikely.cocci
new file mode 100644
index 000000000000..88278295d76a
--- /dev/null
+++ b/scripts/coccinelle/misc/unlikely.cocci
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/// Use unlikely instead of !likely and likely instead of !unlikely.
+///
+// Confidence: High
+// Copyright: (C) 2019 Denis Efremov, ISPRAS.
+// Options: --include-headers
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+//----------------------------------------------------------
+//  For context mode
+//----------------------------------------------------------
+
+@depends on context disable unlikely@
+expression E;
+@@
+
+(
+* !likely(E)
+|
+* !unlikely(E)
+)
+
+//----------------------------------------------------------
+//  For patch mode
+//----------------------------------------------------------
+
+@depends on patch disable unlikely@
+expression E;
+@@
+
+(
+-!likely(E)
++unlikely(E)
+|
+-!unlikely(E)
++likely(E)
+)
+
+//----------------------------------------------------------
+//  For org and report mode
+//----------------------------------------------------------
+
+@r depends on (org || report) disable unlikely@
+expression E;
+position p;
+@@
+
+(
+ !likely@p(E)
+|
+ !unlikely@p(E)
+)
+
+@script:python depends on org@
+p << r.p;
+@@
+
+coccilib.org.print_todo(p[0], "WARNING use unlikely instead of !likely")
+
+@script:python depends on report@
+p << r.p;
+@@
+
+msg="WARNING: Use unlikely instead of !likely"
+coccilib.report.print_report(p[0], msg)
+
-- 
2.21.0


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

end of thread, other threads:[~2019-09-07  8:05 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-25 13:05 [PATCH] scripts: coccinelle: check for !(un)?likely usage Denis Efremov
2019-08-25 13:05 ` [Cocci] " Denis Efremov
2019-08-25 15:30 ` Markus Elfring
2019-08-25 15:30   ` [Cocci] " Markus Elfring
2019-08-25 21:06   ` Denis Efremov
2019-08-25 21:06     ` [Cocci] " Denis Efremov
2019-08-25 15:30 ` Markus Elfring
2019-08-25 15:30   ` [Cocci] " Markus Elfring
2019-08-25 16:37 ` Joe Perches
2019-08-25 16:37   ` [Cocci] " Joe Perches
2019-08-25 18:59   ` Denis Efremov
2019-08-25 18:59     ` [Cocci] " Denis Efremov
2019-08-25 19:19     ` Julia Lawall
2019-08-25 19:19       ` [Cocci] " Julia Lawall
2019-08-28 11:33       ` Rasmus Villemoes
2019-08-28 11:33         ` [Cocci] " Rasmus Villemoes
2019-08-28 11:59         ` Joe Perches
2019-08-28 11:59           ` [Cocci] " Joe Perches
2019-08-28 12:33         ` Denis Efremov
2019-08-28 12:33           ` [Cocci] " Denis Efremov
2019-08-28 13:05           ` Rasmus Villemoes
2019-08-28 13:14             ` Denis Efremov
2019-08-28 12:33         ` Julia Lawall
2019-08-28 12:33           ` [Cocci] " Julia Lawall
2019-08-28 12:41       ` Denis Efremov
2019-08-28 12:41         ` [Cocci] " Denis Efremov
2019-08-28 13:57         ` Denis Efremov
2019-08-28 13:57           ` [Cocci] " Denis Efremov
2019-08-25 21:19     ` Denis Efremov
2019-08-25 21:19       ` [Cocci] " Denis Efremov
2019-09-01 17:24   ` Pavel Machek
2019-09-01 17:39     ` Denis Efremov
2019-09-01 17:39       ` [Cocci] " Denis Efremov
2019-08-29 17:10 ` [PATCH v2] " Denis Efremov
2019-08-29 17:10   ` [Cocci] " Denis Efremov
2019-08-29 17:13   ` Denis Efremov
2019-08-29 17:13     ` [Cocci] " Denis Efremov
2019-08-30  0:42     ` Julia Lawall
2019-08-30  0:42       ` [Cocci] " Julia Lawall
2019-08-30  6:56       ` Denis Efremov
2019-08-30  6:56         ` [Cocci] " Denis Efremov
2019-08-30  8:06         ` Rasmus Villemoes
2019-08-30  8:06           ` [Cocci] " Rasmus Villemoes
2019-08-29 20:07   ` Markus Elfring
2019-08-29 20:07     ` [Cocci] " Markus Elfring
2019-08-30  7:55   ` Markus Elfring
2019-08-30  7:55     ` [Cocci] " Markus Elfring
2019-08-30  7:55     ` Markus Elfring
2019-09-06 20:19   ` Julia Lawall
2019-09-06 20:19     ` [Cocci] " Julia Lawall
2019-09-06 20:55     ` Denis Efremov
2019-09-06 20:55       ` [Cocci] " Denis Efremov
2019-09-07  8:05       ` [v2] " Markus Elfring
2019-09-07  8:05         ` [Cocci] " Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.