^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /// Find duplicate field initializations. This has a high rate of false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /// positives due to #ifdefs, which Coccinelle is not aware of in a structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) /// initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ///
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) // Confidence: Low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) // Copyright: (C) 2010-2012 Nicolas Palix.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) // Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) // Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) // URL: http://coccinelle.lip6.fr/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) // Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) // Options: --no-includes --include-headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) virtual org
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) virtual report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) @r@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) identifier I, s, fld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) position p0,p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) expression E;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct I s =@p0 { ..., .fld@p = E, ...};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) @s@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) identifier I, s, r.fld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) position r.p0,p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) expression E;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct I s =@p0 { ..., .fld@p = E, ...};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) @script:python depends on org@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) p0 << r.p0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) fld << r.fld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) ps << s.p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) pr << r.p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if int(ps[0].line) < int(pr[0].line) or (int(ps[0].line) == int(pr[0].line) and int(ps[0].column) < int(pr[0].column)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) cocci.print_main(fld,p0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) cocci.print_secs("s",ps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) cocci.print_secs("r",pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) @script:python depends on report@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) p0 << r.p0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) fld << r.fld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ps << s.p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) pr << r.p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) @@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if int(ps[0].line) < int(pr[0].line) or (int(ps[0].line) == int(pr[0].line) and int(ps[0].column) < int(pr[0].column)):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) msg = "%s: first occurrence line %s, second occurrence line %s" % (fld,ps[0].line,pr[0].line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) coccilib.report.print_report(p0[0],msg)