Skip to content

Commit

Permalink
coccinelle: misc: add excluded_middle.cocci script
Browse files Browse the repository at this point in the history
Check for !A || A && B condition. It's equivalent to !A || B.

Signed-off-by: Denis Efremov <[email protected]>
Signed-off-by: Julia Lawall <[email protected]>
  • Loading branch information
evdenis authored and JuliaLawall committed Sep 21, 2020
1 parent a19d135 commit b76f0ea
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions scripts/coccinelle/misc/excluded_middle.cocci
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-2.0-only
///
/// Condition !A || A && B is equivalent to !A || B.
///
// Confidence: High
// Copyright: (C) 2020 Denis Efremov ISPRAS
// Options: --no-includes --include-headers

virtual patch
virtual context
virtual org
virtual report

@r depends on !patch@
expression A, B;
position p;
@@

* !A || (A &&@p B)

@depends on patch@
expression A, B;
@@

!A ||
- (A && B)
+ B

@script:python depends on report@
p << r.p;
@@
coccilib.report.print_report(p[0], "WARNING !A || A && B is equivalent to !A || B")
@script:python depends on org@
p << r.p;
@@
coccilib.org.print_todo(p[0], "WARNING !A || A && B is equivalent to !A || B")

0 comments on commit b76f0ea

Please sign in to comment.