[09/33] cocci: Combine min()/max() rules

Submitted by Lyude Paul on June 10, 2019, 3:02 p.m.

Details

Message ID 20190610150321.512-9-lyude@redhat.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in IGT - Trybot

Not browsing as part of any series.

Commit Message

Lyude Paul June 10, 2019, 3:02 p.m.
From: Lyude Paul <lyude@redhat.com>

These don't need to be seperate rules - we can just combine these into a
single rule with a disjoint and save some space/processing time for
cocci. Additionally, we can remove the disjoint rule used for matching
both < & <= + > & >= and simply specify binary operator metavariables.

Signed-off-by: Lyude Paul <lyude@redhat.com>
---
 lib/igt.cocci | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/igt.cocci b/lib/igt.cocci
index c241f34a..373fbc15 100644
--- a/lib/igt.cocci
+++ b/lib/igt.cocci
@@ -116,31 +116,19 @@  position p;
 @@
 #define i(...) <+...E@p...+>
 
-// Replace open-coded min()
+// Replace open-coded min/max()
 @@
 position p != min_max_ignore.p;
 expression a;
 expression b;
+binary operator lt_op = {<,<=};
+binary operator gt_op = {>,>=};
 @@
 (
-- ((a) < (b) ? (a) : (b@p))
+- ((a) lt_op (b) ? (a) : (b@p))
 + min(a, b)
 |
-- ((a) <= (b) ? (a) : (b@p))
-+ min(a, b)
-)
-
-// Replace open-coded max()
-@@
-position p != min_max_ignore.p;
-expression a;
-expression b;
-@@
-(
-- ((a) > (b) ? (a) : (b@p))
-+ max(a, b)
-|
-- ((a) >= (b) ? (a) : (b@p))
+- ((a) gt_op (b) ? (a) : (b@p))
 + max(a, b)
 )