1 // SPDX-License-Identifier: GPL-2.0-only
3 /// Check for opencoded min(), max() implementations.
4 /// Generated patches sometimes require adding a cast to fix compile warning.
5 /// Warnings/patches scope intentionally limited to a function body.
8 // Copyright: (C) 2021 Denis Efremov ISPRAS
9 // Options: --no-includes --include-headers
20 @rmax depends on !patch@
23 binary operator cmp = {>, >=};
30 * ((x) cmp@p (y) ? (x) : (y))
34 @rmaxif depends on !patch@
38 binary operator cmp = {>, >=};
45 * if ((x) cmp@p (y)) {
53 // Ignore errcode returns.
58 binary operator cmp = {<, <=};
64 return ((x) cmp@p 0 ? (x) : 0);
68 @rmin depends on !patch@
71 binary operator cmp = {<, <=};
72 position p != errcode.p;
78 * ((x) cmp@p (y) ? (x) : (y))
82 @rminif depends on !patch@
86 binary operator cmp = {<, <=};
93 * if ((x) cmp@p (y)) {
101 @pmax depends on patch@
104 binary operator cmp = {>=, >};
110 - ((x) cmp (y) ? (x) : (y))
115 @pmaxif depends on patch@
119 binary operator cmp = {>=, >};
130 + max_val = max(x, y);
134 @pmin depends on patch@
137 binary operator cmp = {<=, <};
138 position p != errcode.p;
144 - ((x) cmp@p (y) ? (x) : (y))
149 @pminif depends on patch@
153 binary operator cmp = {<=, <};
164 + min_val = min(x, y);
168 @script:python depends on report@
173 coccilib.report.print_report(p0, "WARNING opportunity for max()")
175 @script:python depends on org@
180 coccilib.org.print_todo(p0, "WARNING opportunity for max()")
182 @script:python depends on report@
187 coccilib.report.print_report(p0, "WARNING opportunity for max()")
189 @script:python depends on org@
194 coccilib.org.print_todo(p0, "WARNING opportunity for max()")
196 @script:python depends on report@
201 coccilib.report.print_report(p0, "WARNING opportunity for min()")
203 @script:python depends on org@
208 coccilib.org.print_todo(p0, "WARNING opportunity for min()")
210 @script:python depends on report@
215 coccilib.report.print_report(p0, "WARNING opportunity for min()")
217 @script:python depends on org@
222 coccilib.org.print_todo(p0, "WARNING opportunity for min()")