From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3408C4332E for ; Mon, 8 Mar 2021 21:31:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84D966519A for ; Mon, 8 Mar 2021 21:31:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230385AbhCHVa4 (ORCPT ); Mon, 8 Mar 2021 16:30:56 -0500 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:14813 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230404AbhCHVad (ORCPT ); Mon, 8 Mar 2021 16:30:33 -0500 X-IronPort-AV: E=Sophos;i="5.81,233,1610406000"; d="scan'208";a="375142415" Received: from 173.121.68.85.rev.sfr.net (HELO hadrien) ([85.68.121.173]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Mar 2021 22:30:31 +0100 Date: Mon, 8 Mar 2021 22:30:31 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Denis Efremov cc: Julia Lawall , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] coccinelle: misc: add minmax script In-Reply-To: <20210308070445.104768-1-efremov@linux.com> Message-ID: References: <20210216160326.1341741-1-efremov@linux.com> <20210308070445.104768-1-efremov@linux.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > +@pmaxif depends on patch@ > +identifier func; > +expression x, y; > +expression max_val; > +binary operator cmp = {>=, >}; > +@@ > + > +func(...) > +{ > + <... > +- if ((x) cmp (y)) { > +- max_val = (x); > +- } else { > +- max_val = (y); > +- } > ++ max_val = max(x, y); > + ...> > +} Things work better if there are no parentheses in max_val = (x) and max_val = (y). Leaving them there seems to cause the match to work in two ways, causing an already tagged token error. An example is in crypto/jitterentropy.c The same is true of the pminif rule. Only the patch rules are affected. Double matches are allowed in the context cas, ince there is no real transfotmation in that case. julia > + > +@pmin depends on patch@ > +identifier func; > +expression x, y; > +binary operator cmp = {<=, <}; > +@@ > + > +func(...) > +{ > + <... > +- ((x) cmp (y) ? (x) : (y)) > ++ min(x, y) > + ...> > +} > + > +@pminif depends on patch@ > +identifier func; > +expression x, y; > +expression min_val; > +binary operator cmp = {<=, <}; > +@@ > + > +func(...) > +{ > + <... > +- if ((x) cmp (y)) { > +- min_val = (x); > +- } else { > +- min_val = (y); > +- } > ++ min_val = min(x, y); > + ...> > +} > + > +@script:python depends on report@ > +p << rmax.p; > +@@ > + > +for p0 in p: > + coccilib.report.print_report(p0, "WARNING opportunity for max()") > + > +@script:python depends on org@ > +p << rmax.p; > +@@ > + > +for p0 in p: > + coccilib.org.print_todo(p0, "WARNING opportunity for max()") > + > +@script:python depends on report@ > +p << rmaxif.p; > +@@ > + > +for p0 in p: > + coccilib.report.print_report(p0, "WARNING opportunity for max()") > + > +@script:python depends on org@ > +p << rmaxif.p; > +@@ > + > +for p0 in p: > + coccilib.org.print_todo(p0, "WARNING opportunity for max()") > + > +@script:python depends on report@ > +p << rmin.p; > +@@ > + > +for p0 in p: > + coccilib.report.print_report(p0, "WARNING opportunity for min()") > + > +@script:python depends on org@ > +p << rmin.p; > +@@ > + > +for p0 in p: > + coccilib.org.print_todo(p0, "WARNING opportunity for min()") > + > +@script:python depends on report@ > +p << rminif.p; > +@@ > + > +for p0 in p: > + coccilib.report.print_report(p0, "WARNING opportunity for min()") > + > +@script:python depends on org@ > +p << rminif.p; > +@@ > + > +for p0 in p: > + coccilib.org.print_todo(p0, "WARNING opportunity for min()") > -- > 2.26.2 > >