qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] scripts/coccinelle: New range.cocci


From: Yao Xingtao
Subject: [PATCH] scripts/coccinelle: New range.cocci
Date: Thu, 25 Jul 2024 01:54:47 -0400

This is the semantic patch from commit 7b3e371526 "cxl/mailbox: make
range overlap check more readable"

Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
---
 scripts/coccinelle/range.cocci | 49 ++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 scripts/coccinelle/range.cocci

diff --git a/scripts/coccinelle/range.cocci b/scripts/coccinelle/range.cocci
new file mode 100644
index 000000000000..21b07945ccb2
--- /dev/null
+++ b/scripts/coccinelle/range.cocci
@@ -0,0 +1,49 @@
+/*
+  Usage:
+
+    spatch \
+           --macro-file scripts/cocci-macro-file.h \
+           --sp-file scripts/coccinelle/range.cocci \
+           --keep-comments \
+           --in-place \
+           --dir .
+
+  Description:
+    Find out the range overlap check and use ranges_overlap() instead.
+
+  Note:
+    This pattern cannot accurately match the region overlap check, and you
+    need to manually delete the use cases that do not meet the conditions.
+
+    In addition, the parameters of ranges_overlap() may be filled incorrectly,
+    and some use cases may be better to use range_overlaps_range().
+*/
+
+@@
+expression E1, E2, E3, E4;
+@@
+(
+- E2 <= E3 || E1 >= E4
++ !ranges_overlap(E1, E2, E3, E4)
+|
+
+- (E2 <= E3) || (E1 >= E4)
++ !ranges_overlap(E1, E2, E3, E4)
+|
+
+- E1 < E4 && E2 > E3
++ ranges_overlap(E1, E2, E3, E4)
+|
+
+- (E1 < E4) && (E2 > E3)
++ ranges_overlap(E1, E2, E3, E4)
+|
+
+- (E1 >= E3 && E1 < E4) || (E2 > E3 && E2 <= E4)
++ ranges_overlap(E1, E2, E3, E4)
+
+|
+- ((E1 >= E3) && (E1 < E4)) || ((E2 > E3) && (E2 <= E4))
++ ranges_overlap(E1, E2, E3, E4)
+)
+
-- 
2.41.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]