[Clang-Tidy] New check `bugprone-redundant-branch-condition`

Authored by baloghadamsoftware on Jun 5 2020, 4:27 AM.


[Clang-Tidy] New check bugprone-redundant-branch-condition

Checking the same condition again in a nested if usually make no sense,
except if the value of the expression could have been changed between
the two checks. Although compilers may optimize this out, such code is
suspicious: the programmer may have meant to check something else.
Therefore it is worth to find such places in the code and notify the
user about the problem.

This patch implements a basic check for this problem. Currently it
only detects redundant conditions where the condition is a variable of
integral type. It also detects the possible bug if the variable is in an
or or and logical expression in the inner if and/or the variable
is in an and logical expression in the outer if statement. Negated
cases are not handled yet.

Differential Revision: https://reviews.llvm.org/D81272