2024-09-09 08:57:42 +00:00
|
|
|
/// Use BUG_ON instead of a if condition followed by BUG.
|
2024-09-09 08:52:07 +00:00
|
|
|
///
|
2024-09-09 08:57:42 +00:00
|
|
|
//# This makes an effort to find cases where BUG() follows an if
|
|
|
|
//# condition on an expression and replaces the if condition and BUG()
|
|
|
|
//# with a BUG_ON having the conditional expression of the if statement
|
|
|
|
//# as argument.
|
2024-09-09 08:52:07 +00:00
|
|
|
//
|
2024-09-09 08:57:42 +00:00
|
|
|
// Confidence: High
|
|
|
|
// Copyright: (C) 2014 Himangi Saraogi. GPLv2.
|
|
|
|
// Comments:
|
|
|
|
// Options: --no-includes --include-headers
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
virtual patch
|
2024-09-09 08:57:42 +00:00
|
|
|
virtual context
|
2024-09-09 08:52:07 +00:00
|
|
|
virtual org
|
|
|
|
virtual report
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
// For context mode
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
|
|
@depends on context@
|
2024-09-09 08:57:42 +00:00
|
|
|
expression e;
|
2024-09-09 08:52:07 +00:00
|
|
|
@@
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
*if (e) BUG();
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
// For patch mode
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
|
|
@depends on patch@
|
2024-09-09 08:57:42 +00:00
|
|
|
expression e;
|
2024-09-09 08:52:07 +00:00
|
|
|
@@
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
-if (e) BUG();
|
|
|
|
+BUG_ON(e);
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
// For org and report mode
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
@r@
|
|
|
|
expression e;
|
2024-09-09 08:52:07 +00:00
|
|
|
position p;
|
|
|
|
@@
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
if (e) BUG@p ();
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
@script:python depends on org@
|
|
|
|
p << r.p;
|
|
|
|
@@
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
coccilib.org.print_todo(p[0], "WARNING use BUG_ON")
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
@script:python depends on report@
|
|
|
|
p << r.p;
|
|
|
|
@@
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
msg="WARNING: Use BUG_ON"
|
2024-09-09 08:52:07 +00:00
|
|
|
coccilib.report.print_report(p[0], msg)
|
2024-09-09 08:57:42 +00:00
|
|
|
|