[PATCH] D130181: [clang-tidy] Add readability-use-early-exits check

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 23 00:30:53 PDT 2023


PiotrZSL added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/readability/UseEarlyExitsCheck.cpp:359
+void UseEarlyExitsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(translationUnitDecl(), this);
+}
----------------
This will trigger on all system code, and then users will complain again that they see poor clang-tidy performance...

when it could be just something like

```
ifStmt(unless(isExpansionInSystemHeader()),
       unless(isConsteval()),
       unless(isConstexpr()),
       unless(hasElse(stmt())),
       unless(hasInitStatement(stmt()),
       hasThen(compoundStmt(hasSizeAboeLineTreshold())),
       ...
```

Simply everything that could be put into matcher should be put into matcher (easier to maintain), also what's a point of checking functions that doesn't have if's. On that point also some implicit functions or if statement should be ignored, to avoid checking templates twice.



================
Comment at: clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits.cpp:144
+  //  CHECK-FIXES-NEXT:     }
+}
----------------
- Missing test with if in template function & implicit specialization, just to make sure that fixes won't get to mess up.
- Missing test with if under macro.
- Missing test with if under switch under loop (to check if brak/continue will be used correctly, instead of return).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130181/new/

https://reviews.llvm.org/D130181



More information about the cfe-commits mailing list