[PATCH] D38688: Misc redundant expressions checker updated for macros

Barancsuk Lilla via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 9 07:13:45 PDT 2017


barancsuk created this revision.
barancsuk added a project: clang-tools-extra.

Redundant Expression Checker is updated to be able to detect expressions that contain macro constants. Also, other small details are modified to improve the current implementation.

The improvements in detail are as follows:

**1.)** Binary and ternary operator expressions containing two constants, with at least one of them from a macro, are detected and tested for redundancy.

Macro expressions are treated somewhat differently from other expressions, because the particular values of macros can vary across builds. They can be considered correct and intentional, even if macro values equal, produce ranges that exclude each other or fully overlap, etc. The correctness of a macro expression is decided based on solely the operators involved in the expression.

Examples:

The following expression is always redundant, independently of the macro values, because the subexpression containing the larger constant can be eliminated without changing the meaning of the expression:

  (X < MACRO && X < OTHER_MACRO)

On the contrary, the following expression is considered meaningful, because some macro values (e.g.:  MACRO = 3, OTHER_MACRO = 2) produce a valid interval:

  (X < MACRO && X > OTHER_MACRO)

**2.) **The code structure is slightly modified: typos are corrected, comments are added and some functions are renamed to improve comprehensibility, both in the checker and the test file. A few test cases are moved to another function.

**3.)** The checker is now able to detect redundant CXXFunctionalCastExprs as well (it matched only CStyleCastExprs before). A corresponding test case is added.


https://reviews.llvm.org/D38688

Files:
  clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tidy/misc/RedundantExpressionCheck.h
  docs/clang-tidy/checks/misc-redundant-expression.rst
  test/clang-tidy/misc-redundant-expression.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38688.118186.patch
Type: text/x-patch
Size: 44413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171009/062b58f8/attachment-0001.bin>


More information about the cfe-commits mailing list