CodeQL library for C/C++
codeql/cpp-all 2.0.2 (changelog, source)
Search

Predicate eqOpWithSwapAndNegate

Holds if cmp is an equality operation (== or !=) with fully-converted children a and b, isEQ is true if cmp is an == operation and false if it is an != operation, and the result is branch.

This allows for the comparison to be either as written, or with its arguments reversed; for example, if cmp is x == 5 then eqOpWithSwapAndNegate(cmp, x, 5, true, true), eqOpWithSwapAndNegate(cmp, 5, x, true, true), eqOpWithSwapAndNegate(cmp, x, 5, false, false) and eqOpWithSwapAndNegate(cmp, 5, x, false, false) hold.

Import path

import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
predicate eqOpWithSwapAndNegate(EqualityOperation cmp, Expr a, Expr b, boolean isEQ, boolean branch)