[PATCH] D36756: [clang-tidy] Use CloexecCheck as base class of CloexecSocketCheck.
Chih-Hung Hsieh via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 15 10:43:22 PDT 2017
chh created this revision.
Simplify registerMatchers and check functions in CloexecSocketCheck.
https://reviews.llvm.org/D36756
Files:
clang-tidy/android/CloexecSocketCheck.cpp
clang-tidy/android/CloexecSocketCheck.h
Index: clang-tidy/android/CloexecSocketCheck.h
===================================================================
--- clang-tidy/android/CloexecSocketCheck.h
+++ clang-tidy/android/CloexecSocketCheck.h
@@ -10,7 +10,7 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
-#include "../ClangTidy.h"
+#include "CloexecCheck.h"
namespace clang {
namespace tidy {
@@ -20,10 +20,10 @@
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-socket.html
-class CloexecSocketCheck : public ClangTidyCheck {
+class CloexecSocketCheck : public CloexecCheck {
public:
CloexecSocketCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context) {}
+ : CloexecCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
Index: clang-tidy/android/CloexecSocketCheck.cpp
===================================================================
--- clang-tidy/android/CloexecSocketCheck.cpp
+++ clang-tidy/android/CloexecSocketCheck.cpp
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
#include "CloexecSocketCheck.h"
-#include "../utils/ASTUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -21,35 +20,16 @@
static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";
void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(
- callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
- hasName("socket"),
- hasParameter(0, hasType(isInteger())),
- hasParameter(1, hasType(isInteger())),
- hasParameter(2, hasType(isInteger())))
- .bind("funcDecl")))
- .bind("socketFn"),
- this);
+ registerMatchersImpl(Finder,
+ functionDecl(isExternC(), returns(isInteger()),
+ hasName("socket"),
+ hasParameter(0, hasType(isInteger())),
+ hasParameter(1, hasType(isInteger())),
+ hasParameter(2, hasType(isInteger()))));
}
void CloexecSocketCheck::check(const MatchFinder::MatchResult &Result) {
- const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>("socketFn");
- const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("funcDecl");
- const Expr *FlagArg = MatchedCall->getArg(1);
- SourceManager &SM = *Result.SourceManager;
-
- if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
- Result.Context->getLangOpts(), SOCK_CLOEXEC))
- return;
-
- SourceLocation EndLoc =
- Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getLocEnd()), 0, SM,
- Result.Context->getLangOpts());
-
- diag(EndLoc, "%0 should use %1 where possible")
- << FD << SOCK_CLOEXEC
- << FixItHint::CreateInsertion(EndLoc,
- (Twine(" | ") + SOCK_CLOEXEC).str());
+ insertMacroFlag(Result, /*MarcoFlag=*/"SOCK_CLOEXEC", /*ArgPos=*/1);
}
} // namespace android
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36756.111203.patch
Type: text/x-patch
Size: 3424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170815/8c063c8c/attachment-0001.bin>
More information about the cfe-commits
mailing list