From patchwork Mon Jun 10 15:02:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [09/33] cocci: Combine min()/max() rules From: Lyude X-Patchwork-Id: 309543 Message-Id: <20190610150321.512-9-lyude@redhat.com> To: intel-gfx-trybot@lists.freedesktop.org Date: Mon, 10 Jun 2019 11:02:57 -0400 From: Lyude Paul 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 --- lib/igt.cocci | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) 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) )