[PATCH] D63623: [clang-tidy] new check: bugprone-posix-return

Dmitri Gribenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 1 05:53:38 PDT 2019


gribozavr accepted this revision.
gribozavr added a comment.

Good improvements!



================
Comment at: clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp:21
+static StringRef getFunctionSpelling(const MatchFinder::MatchResult &Result, const char *BindingStr) {
+  const CallExpr *MatchedCall = cast <CallExpr>((Result.Nodes.getNodeAs<BinaryOperator>(BindingStr))->getLHS());
+  const SourceManager &SM = *Result.SourceManager;
----------------
Please clang-format (the whole file).


================
Comment at: clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp:56
+    SourceLocation OperatorLoc = LessThanZeroOp->getOperatorLoc();
+    diag(OperatorLoc, "%0 only returns nonnegative values")
+        << getFunctionSpelling(Result, "ltzop")
----------------
"non-negative"

"the comparison always evaluates to false because %0 always returns non-negative values"


================
Comment at: clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp:62
+  if (const auto *AlwaysTrueOp = Result.Nodes.getNodeAs<BinaryOperator>("atop")) {
+    diag(AlwaysTrueOp->getOperatorLoc(), "redundant check as %0 only returns nonnegative values")
+        << getFunctionSpelling(Result, "atop");
----------------
I'd suggest "the comparison always evaluates to true because %0 always returns a non-negative value"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63623





More information about the cfe-commits mailing list