Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2107116pxb; Mon, 8 Mar 2021 14:31:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxyeilB03Tox5QewdqpTZ7eC7Vob+ib5XK1JQ4DZJyQnrhvfRJ2bGazWiX6Tt/y9nZ3zKNJ X-Received: by 2002:a05:6402:510f:: with SMTP id m15mr790677edd.328.1615242670664; Mon, 08 Mar 2021 14:31:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615242670; cv=none; d=google.com; s=arc-20160816; b=jX9PbgmpxvStuJZn40a2ytmBvjHZwdWrM59FczRussK4xWOs3/gmwGa1B8wlKjC6QQ M4gBgsEazuBVv/M6FvlS99QICiVDzs9tUDIYAQN2kpKmd58AfBSQcaSZpoj2Ua4PejtH GC5UoQmnGpR6ZKDPHpSDT5MjI3VCxcfGpHkS4Rd+8j0GqGFHacnnnn4vy4+5s+1FDzrQ r6VqGpn1hPPckUaajTrdBLjUgb3F90AZY5wQx9FrLEYuxnAMTgYm05xDo5CLRquxUJeu foLI2xsdfKs0ZpGbl7d+w61fyBxnk3EClsjDQiNS7+dt1EuDoEac6m61m+sRW13fwU+i Ko2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=HufV3N/er92IUrqvGIVCraQXMfxsDR+WpHc5LlvOnLk=; b=0u415ingXb7QonMzX1IN1Tzy98j/kFMbkLO0ReBtZUzUEQ6G4nzDQkloW+MDGW1NmX ULxOZyCzwvgJFhGrXBrx1E11FfQCK1Qa7yPVhrKsbv3lq0vD0WKwWWrWFWYcdgsWOOh0 65QrrzarTvTQzzo3ss3jL17Sy2qTHVLLjWU6tt/FGjZVCTbEd9/qpsi7zW8qrGKWTKeT gzlPWbw7xx963lsxG3K5h7cTpdTbj76A+7cf93nNCVsRVyuTAzqrwYZpV7SyXHjYtPz1 JxZrhcIzlQNHQvf8Hf1bVAarva+rFz9fb7CErGw2xHmzBjztrZevVDGw8TTkqnMe+QHQ Ra1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ke20si7773136ejc.305.2021.03.08.14.30.45; Mon, 08 Mar 2021 14:31:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231296AbhCHVa4 (ORCPT + 99 others); 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 > >