forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coccinelle: Add misc/doubleinit.cocci
Find duplicate field initializations. This has a high rate of false positives due to #ifdefs, which Coccinelle is not aware of in a structure initialization. Signed-off-by: Nicolas Palix <npalix@diku.dk> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: Michal Marek <mmarek@suse.cz>
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// Find duplicate field initializations. This has a high rate of false | ||
/// positives due to #ifdefs, which Coccinelle is not aware of in a structure | ||
/// initialization. | ||
/// | ||
// Confidence: Low | ||
// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2. | ||
// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2. | ||
// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. | ||
// URL: http://coccinelle.lip6.fr/ | ||
// Comments: | ||
// Options: -no_includes -include_headers | ||
|
||
virtual org | ||
virtual report | ||
|
||
@r@ | ||
identifier I, s, fld; | ||
position p0,p; | ||
expression E; | ||
@@ | ||
|
||
struct I s =@p0 { ... .fld@p = E, ...}; | ||
|
||
@s@ | ||
identifier I, s, r.fld; | ||
position r.p0,p; | ||
expression E; | ||
@@ | ||
|
||
struct I s =@p0 { ... .fld@p = E, ...}; | ||
|
||
@script:python depends on org@ | ||
p0 << r.p0; | ||
fld << r.fld; | ||
ps << s.p; | ||
pr << r.p; | ||
@@ | ||
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)): | ||
cocci.print_main(fld,p0) | ||
cocci.print_secs("s",ps) | ||
cocci.print_secs("r",pr) | ||
@script:python depends on report@ | ||
p0 << r.p0; | ||
fld << r.fld; | ||
ps << s.p; | ||
pr << r.p; | ||
@@ | ||
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)): | ||
msg = "%s: first occurrence %s, second occurrence %s" % (fld,ps[0].line,pr[0].line) | ||
coccilib.report.print_report(p0[0],msg) |