[all-commits] [llvm/llvm-project] 99217f: [clang-tidy] Recognize labelled statements when si...

Richard Thomson via All-commits all-commits at lists.llvm.org
Fri Jan 28 15:10:07 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 99217fa8a027a893a9b2f46ed315ec4cab850e3d
      https://github.com/llvm/llvm-project/commit/99217fa8a027a893a9b2f46ed315ec4cab850e3d
  Author: Richard <legalize at xmission.com>
  Date:   2022-01-28 (Fri, 28 Jan 2022)

  Changed paths:
    M clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
    M clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
    A clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprMatchers.h
    A clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-case.cpp
    M clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
    M clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
    M clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp

  Log Message:
  -----------
  [clang-tidy] Recognize labelled statements when simplifying boolean exprs

Inside a switch the caseStmt() and defaultStmt() have a nested statement
associated with them.  Similarly, labelStmt() has a nested statement.
These statements were being missed when looking for a compound-if of the
form "if (x) return true; return false;" when the if is nested under one
of these labelling constructs.

Enhance the matchers to look for these nested statements using some
private matcher hasSubstatement() traversal matcher on case, default
and label statements.  Add the private matcher hasSubstatementSequence()
to match the compound "if (x) return true; return false;" pattern.

- Add unit tests for private matchers and corresponding test
  infrastructure
- Add corresponding test file readability-simplify-bool-expr-case.cpp.
- Fix variable name copy/paste error in readability-simplify-bool-expr.cpp.
- Drop the asserts, which were used only for debugging matchers.
- Run clang-format on the whole check.
- Move local functions out of anonymous namespace and declare state, per
  LLVM style guide
- Declare labels constexpr
- Declare visitor arguments as pointer to const
- Drop braces around simple control statements per LLVM style guide
- Prefer explicit arguments over default arguments to methods

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

Fixes #27078




More information about the All-commits mailing list