18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/// Find duplicate field initializations. This has a high rate of false 38c2ecf20Sopenharmony_ci/// positives due to #ifdefs, which Coccinelle is not aware of in a structure 48c2ecf20Sopenharmony_ci/// initialization. 58c2ecf20Sopenharmony_ci/// 68c2ecf20Sopenharmony_ci// Confidence: Low 78c2ecf20Sopenharmony_ci// Copyright: (C) 2010-2012 Nicolas Palix. 88c2ecf20Sopenharmony_ci// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. 98c2ecf20Sopenharmony_ci// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. 108c2ecf20Sopenharmony_ci// URL: http://coccinelle.lip6.fr/ 118c2ecf20Sopenharmony_ci// Comments: requires at least Coccinelle 0.2.4, lex or parse error otherwise 128c2ecf20Sopenharmony_ci// Options: --no-includes --include-headers 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_civirtual org 158c2ecf20Sopenharmony_civirtual report 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci@r@ 188c2ecf20Sopenharmony_ciidentifier I, s, fld; 198c2ecf20Sopenharmony_ciposition p0,p; 208c2ecf20Sopenharmony_ciexpression E; 218c2ecf20Sopenharmony_ci@@ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistruct I s =@p0 { ..., .fld@p = E, ...}; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci@s@ 268c2ecf20Sopenharmony_ciidentifier I, s, r.fld; 278c2ecf20Sopenharmony_ciposition r.p0,p; 288c2ecf20Sopenharmony_ciexpression E; 298c2ecf20Sopenharmony_ci@@ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistruct I s =@p0 { ..., .fld@p = E, ...}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci@script:python depends on org@ 348c2ecf20Sopenharmony_cip0 << r.p0; 358c2ecf20Sopenharmony_cifld << r.fld; 368c2ecf20Sopenharmony_cips << s.p; 378c2ecf20Sopenharmony_cipr << r.p; 388c2ecf20Sopenharmony_ci@@ 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciif 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)): 418c2ecf20Sopenharmony_ci cocci.print_main(fld,p0) 428c2ecf20Sopenharmony_ci cocci.print_secs("s",ps) 438c2ecf20Sopenharmony_ci cocci.print_secs("r",pr) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci@script:python depends on report@ 468c2ecf20Sopenharmony_cip0 << r.p0; 478c2ecf20Sopenharmony_cifld << r.fld; 488c2ecf20Sopenharmony_cips << s.p; 498c2ecf20Sopenharmony_cipr << r.p; 508c2ecf20Sopenharmony_ci@@ 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciif 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)): 538c2ecf20Sopenharmony_ci msg = "%s: first occurrence line %s, second occurrence line %s" % (fld,ps[0].line,pr[0].line) 548c2ecf20Sopenharmony_ci coccilib.report.print_report(p0[0],msg) 55