blob: 2f80d3ab38dd69803c383cbe1bc43aeefe9ecf11 [file] [log] [blame]
Thomas Gleixner7f904d72019-06-04 10:11:38 +02001// SPDX-License-Identifier: GPL-2.0-only
Nicolas Palix033456e2010-08-24 17:39:11 +02002/// Find duplicate field initializations. This has a high rate of false
3/// positives due to #ifdefs, which Coccinelle is not aware of in a structure
4/// initialization.
5///
6// Confidence: Low
Thomas Gleixner7f904d72019-06-04 10:11:38 +02007// Copyright: (C) 2010-2012 Nicolas Palix.
8// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
9// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
Nicolas Palix033456e2010-08-24 17:39:11 +020010// URL: http://coccinelle.lip6.fr/
Julia Lawalla1087ef2010-11-24 15:54:18 +010011// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise
Nicolas Palix93f14462013-06-20 13:10:56 +020012// Options: --no-includes --include-headers
Nicolas Palix033456e2010-08-24 17:39:11 +020013
14virtual org
15virtual report
16
17@r@
18identifier I, s, fld;
19position p0,p;
20expression E;
21@@
22
Julia Lawalla1087ef2010-11-24 15:54:18 +010023struct I s =@p0 { ..., .fld@p = E, ...};
Nicolas Palix033456e2010-08-24 17:39:11 +020024
25@s@
26identifier I, s, r.fld;
27position r.p0,p;
28expression E;
29@@
30
Julia Lawalla1087ef2010-11-24 15:54:18 +010031struct I s =@p0 { ..., .fld@p = E, ...};
Nicolas Palix033456e2010-08-24 17:39:11 +020032
33@script:python depends on org@
34p0 << r.p0;
35fld << r.fld;
36ps << s.p;
37pr << r.p;
38@@
39
40if 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)):
41 cocci.print_main(fld,p0)
42 cocci.print_secs("s",ps)
43 cocci.print_secs("r",pr)
44
45@script:python depends on report@
46p0 << r.p0;
47fld << r.fld;
48ps << s.p;
49pr << r.p;
50@@
51
52if 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)):
Julia Lawall29a36d42012-01-14 23:41:54 +010053 msg = "%s: first occurrence line %s, second occurrence line %s" % (fld,ps[0].line,pr[0].line)
Nicolas Palix033456e2010-08-24 17:39:11 +020054 coccilib.report.print_report(p0[0],msg)