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

Predicate relOpWithSwapAndNegate

Holds if rel is a comparison operation (<, >, <= or >=) with fully-converted children a and b, described by dir and strict, with result branch.

This allows for the relation to be either as written, or with its arguments reversed; for example, if rel is x < 5 then relOpWithSwapAndNegate(rel, x, 5, Lesser(), Strict(), true), relOpWithSwapAndNegate(rel, 5, x, Greater(), Strict(), true), relOpWithSwapAndNegate(rel, x, 5, Greater(), Nonstrict(), false) and relOpWithSwapAndNegate(rel, 5, x, Lesser(), Nonstrict(), false) hold.

Import path

import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
predicate relOpWithSwapAndNegate(RelationalOperation rel, Expr a, Expr b, RelationDirection dir, RelationStrictness strict, boolean branch)