18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/// Find confusingly indented code in or after an if.  An if branch should
38c2ecf20Sopenharmony_ci/// be indented.  The code following an if should not be indented.
48c2ecf20Sopenharmony_ci/// Sometimes, code after an if that is indented is actually intended to be
58c2ecf20Sopenharmony_ci/// part of the if branch.
68c2ecf20Sopenharmony_ci///
78c2ecf20Sopenharmony_ci//# This has a high rate of false positives, because Coccinelle's column
88c2ecf20Sopenharmony_ci//# calculation does not distinguish between spaces and tabs, so code that
98c2ecf20Sopenharmony_ci//# is not visually aligned may be considered to be in the same column.
108c2ecf20Sopenharmony_ci//
118c2ecf20Sopenharmony_ci// Confidence: Low
128c2ecf20Sopenharmony_ci// Copyright: (C) 2010 Nicolas Palix, DIKU.
138c2ecf20Sopenharmony_ci// Copyright: (C) 2010 Julia Lawall, DIKU.
148c2ecf20Sopenharmony_ci// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
158c2ecf20Sopenharmony_ci// URL: http://coccinelle.lip6.fr/
168c2ecf20Sopenharmony_ci// Comments:
178c2ecf20Sopenharmony_ci// Options: --no-includes --include-headers
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_civirtual org
208c2ecf20Sopenharmony_civirtual report
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci@r disable braces4@
238c2ecf20Sopenharmony_ciposition p1,p2;
248c2ecf20Sopenharmony_cistatement S1,S2;
258c2ecf20Sopenharmony_ci@@
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci(
288c2ecf20Sopenharmony_ciif (...) { ... }
298c2ecf20Sopenharmony_ci|
308c2ecf20Sopenharmony_ciif (...) S1@p1 S2@p2
318c2ecf20Sopenharmony_ci)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci@script:python depends on org@
348c2ecf20Sopenharmony_cip1 << r.p1;
358c2ecf20Sopenharmony_cip2 << r.p2;
368c2ecf20Sopenharmony_ci@@
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ciif (p1[0].column == p2[0].column):
398c2ecf20Sopenharmony_ci  cocci.print_main("branch",p1)
408c2ecf20Sopenharmony_ci  cocci.print_secs("after",p2)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci@script:python depends on report@
438c2ecf20Sopenharmony_cip1 << r.p1;
448c2ecf20Sopenharmony_cip2 << r.p2;
458c2ecf20Sopenharmony_ci@@
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciif (p1[0].column == p2[0].column):
488c2ecf20Sopenharmony_ci  msg = "code aligned with following code on line %s" % (p2[0].line)
498c2ecf20Sopenharmony_ci  coccilib.report.print_report(p1[0],msg)
50