GNU Linux-libre 4.19.264-gnu1
[releases.git] / scripts / coccinelle / tests / doubletest.cocci
1 /// Find &&/|| operations that include the same argument more than once
2 //# A common source of false positives is when the expression, or
3 //# another expresssion in the same && or || operation, performs a
4 //# side effect.
5 ///
6 // Confidence: Moderate
7 // Copyright: (C) 2010 Nicolas Palix, DIKU.  GPLv2.
8 // Copyright: (C) 2010 Julia Lawall, DIKU.  GPLv2.
9 // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.  GPLv2.
10 // URL: http://coccinelle.lip6.fr/
11 // Comments:
12 // Options: --no-includes --include-headers
13
14 virtual context
15 virtual org
16 virtual report
17
18 @r expression@
19 expression E;
20 position p;
21 @@
22
23 (
24  E@p || ... || E
25 |
26  E@p && ... && E
27 )
28
29 @bad@
30 expression r.E,e1,e2,fn;
31 position r.p;
32 assignment operator op;
33 @@
34
35 (
36 E@p
37 &
38  <+... \(fn(...)\|e1 op e2\|e1++\|e1--\|++e1\|--e1\) ...+>
39 )
40
41 @depends on context && !bad@
42 expression r.E;
43 position r.p;
44 @@
45
46 *E@p
47
48 @script:python depends on org && !bad@
49 p << r.p;
50 @@
51
52 cocci.print_main("duplicated argument to && or ||",p)
53
54 @script:python depends on report && !bad@
55 p << r.p;
56 @@
57
58 coccilib.report.print_report(p[0],"duplicated argument to && or ||")