Messages in this thread | | | Date | Mon, 8 Mar 2021 22:30:31 +0100 (CET) | From | Julia Lawall <> | Subject | Re: [PATCH v4] coccinelle: misc: add minmax script |
| |
> +@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 > >
| |