[07/33] cocci: Ignore opencoded min()/max() in min()/max() defines

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

Details

Message ID 20190610150321.512-7-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>

You can't use min() inside min(), and vice-versa

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

Patch hide | download patch | download mbox

diff --git a/lib/igt.cocci b/lib/igt.cocci
index d6d564d7..8e72be55 100644
--- a/lib/igt.cocci
+++ b/lib/igt.cocci
@@ -108,29 +108,39 @@  T a, b, tmp;
 - b = tmp;
 + igt_swap(a, b);
 
+// So we don't complain about #define min(), #define max(), etc.
+@min_max_ignore@
+identifier i =~ "^m(in|ax)$";
+expression E;
+position p;
+@@
+#define i(...) <+...E@p...+>
+
 // Replace open-coded min()
 @@
+position p != min_max_ignore.p;
 expression a;
 expression b;
 @@
 (
-- ((a) < (b) ? (a) : (b))
+- ((a) < (b) ? (a) : (b@p))
 + min(a, b)
 |
-- ((a) <= (b) ? (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))
+- ((a) > (b) ? (a) : (b@p))
 + max(a, b)
 |
-- ((a) >= (b) ? (a) : (b))
+- ((a) >= (b) ? (a) : (b@p))
 + max(a, b)
 )