xref: /openbmc/linux/scripts/coccinelle/tests/doubletest.cocci (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
17f904d7eSThomas Gleixner// SPDX-License-Identifier: GPL-2.0-only
297c1cf8fSJulia Lawall/// Find &&/|| operations that include the same argument more than once
309d4d964SJulia Lawall//# A common source of false positives is when the expression, or
409d4d964SJulia Lawall//# another expresssion in the same && or || operation, performs a
509d4d964SJulia Lawall//# side effect.
697c1cf8fSJulia Lawall///
797c1cf8fSJulia Lawall// Confidence: Moderate
87f904d7eSThomas Gleixner// Copyright: (C) 2010 Nicolas Palix, DIKU.
97f904d7eSThomas Gleixner// Copyright: (C) 2010 Julia Lawall, DIKU.
107f904d7eSThomas Gleixner// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
11*f01701ceSJulia Lawall// URL: https://coccinelle.gitlabpages.inria.fr/website
1297c1cf8fSJulia Lawall// Comments:
1393f14468SNicolas Palix// Options: --no-includes --include-headers
1497c1cf8fSJulia Lawall
1597c1cf8fSJulia Lawallvirtual context
1697c1cf8fSJulia Lawallvirtual org
1797c1cf8fSJulia Lawallvirtual report
1897c1cf8fSJulia Lawall
1997c1cf8fSJulia Lawall@r expression@
2097c1cf8fSJulia Lawallexpression E;
2197c1cf8fSJulia Lawallposition p;
2297c1cf8fSJulia Lawall@@
2397c1cf8fSJulia Lawall
2497c1cf8fSJulia Lawall(
2509d4d964SJulia Lawall E@p || ... || E
2697c1cf8fSJulia Lawall|
2709d4d964SJulia Lawall E@p && ... && E
2897c1cf8fSJulia Lawall)
2997c1cf8fSJulia Lawall
3009d4d964SJulia Lawall@bad@
3109d4d964SJulia Lawallexpression r.E,e1,e2,fn;
3209d4d964SJulia Lawallposition r.p;
3309d4d964SJulia Lawallassignment operator op;
3409d4d964SJulia Lawall@@
3509d4d964SJulia Lawall
3609d4d964SJulia Lawall(
3709d4d964SJulia LawallE@p
3809d4d964SJulia Lawall&
3909d4d964SJulia Lawall <+... \(fn(...)\|e1 op e2\|e1++\|e1--\|++e1\|--e1\) ...+>
4009d4d964SJulia Lawall)
4109d4d964SJulia Lawall
4209d4d964SJulia Lawall@depends on context && !bad@
4309d4d964SJulia Lawallexpression r.E;
4409d4d964SJulia Lawallposition r.p;
4509d4d964SJulia Lawall@@
4609d4d964SJulia Lawall
4709d4d964SJulia Lawall*E@p
4809d4d964SJulia Lawall
4909d4d964SJulia Lawall@script:python depends on org && !bad@
5097c1cf8fSJulia Lawallp << r.p;
5197c1cf8fSJulia Lawall@@
5297c1cf8fSJulia Lawall
5397c1cf8fSJulia Lawallcocci.print_main("duplicated argument to && or ||",p)
5497c1cf8fSJulia Lawall
5509d4d964SJulia Lawall@script:python depends on report && !bad@
5697c1cf8fSJulia Lawallp << r.p;
5797c1cf8fSJulia Lawall@@
5897c1cf8fSJulia Lawall
5997c1cf8fSJulia Lawallcoccilib.report.print_report(p[0],"duplicated argument to && or ||")
60