diff options
author | Yan Wang <yawanng@google.com> | 2017-06-29 19:13:29 +0000 |
---|---|---|
committer | Yan Wang <yawanng@google.com> | 2017-06-29 19:13:29 +0000 |
commit | 600a6133ad65fa5f0ef9d5aad4b353e2bc32cedc (patch) | |
tree | f7c02ca3682a4ce77f9db2bf021511db047bc43b /clang-tools-extra/clang-tidy/android | |
parent | 99886f09a13127f676e5136e1c639021f35de02b (diff) | |
download | bcm5719-llvm-600a6133ad65fa5f0ef9d5aad4b353e2bc32cedc.tar.gz bcm5719-llvm-600a6133ad65fa5f0ef9d5aad4b353e2bc32cedc.zip |
[clang-tidy] Rename android-file-open-flag and fix a bug
Summary:
1. Rename android-file-open-flag to android-cloexec-open.
2. Handle a case when the function is passed as an argument of a function-like macro.
Reviewers: chh
Reviewed By: chh
Subscribers: srhines, mgorny, JDevlieghere, xazax.hun, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D34633
llvm-svn: 306728
Diffstat (limited to 'clang-tools-extra/clang-tidy/android')
-rw-r--r-- | clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp | 4 | ||||
-rw-r--r-- | clang-tools-extra/clang-tidy/android/CMakeLists.txt | 2 | ||||
-rw-r--r-- | clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp (renamed from clang-tools-extra/clang-tidy/android/FileOpenFlagCheck.cpp) | 24 | ||||
-rw-r--r-- | clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h (renamed from clang-tools-extra/clang-tidy/android/FileOpenFlagCheck.h) | 12 |
4 files changed, 22 insertions, 20 deletions
diff --git a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp index aa630986d40..701dd53dbb1 100644 --- a/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp @@ -12,7 +12,7 @@ #include "../ClangTidyModuleRegistry.h" #include "CloexecCreatCheck.h" #include "CloexecFopenCheck.h" -#include "FileOpenFlagCheck.h" +#include "CloexecOpenCheck.h" using namespace clang::ast_matchers; @@ -24,9 +24,9 @@ namespace android { class AndroidModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { - CheckFactories.registerCheck<FileOpenFlagCheck>("android-file-open-flag"); CheckFactories.registerCheck<CloexecCreatCheck>("android-cloexec-creat"); CheckFactories.registerCheck<CloexecFopenCheck>("android-cloexec-fopen"); + CheckFactories.registerCheck<CloexecOpenCheck>("android-cloexec-open"); } }; diff --git a/clang-tools-extra/clang-tidy/android/CMakeLists.txt b/clang-tools-extra/clang-tidy/android/CMakeLists.txt index 1c0bea40d5a..83caa6e0428 100644 --- a/clang-tools-extra/clang-tidy/android/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/android/CMakeLists.txt @@ -4,7 +4,7 @@ add_clang_library(clangTidyAndroidModule AndroidTidyModule.cpp CloexecCreatCheck.cpp CloexecFopenCheck.cpp - FileOpenFlagCheck.cpp + CloexecOpenCheck.cpp LINK_LIBS clangAST diff --git a/clang-tools-extra/clang-tidy/android/FileOpenFlagCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp index 8cb05e40029..4dfe3951d93 100644 --- a/clang-tools-extra/clang-tidy/android/FileOpenFlagCheck.cpp +++ b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp @@ -1,4 +1,4 @@ -//===--- FileOpenFlagCheck.cpp - clang-tidy--------------------------------===// +//===--- CloexecOpenCheck.cpp - clang-tidy---------------------------------===// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "FileOpenFlagCheck.h" +#include "CloexecOpenCheck.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/Lexer.h" @@ -21,11 +21,12 @@ namespace android { namespace { static constexpr const char *O_CLOEXEC = "O_CLOEXEC"; -bool HasCloseOnExecFlag(const Expr *Flags, const SourceManager &SM, +bool hasCloseOnExecFlag(const Expr *Flags, const SourceManager &SM, const LangOptions &LangOpts) { // If the Flag is an integer constant, check it. if (isa<IntegerLiteral>(Flags)) { - if (!SM.isMacroBodyExpansion(Flags->getLocStart())) + if (!SM.isMacroBodyExpansion(Flags->getLocStart()) && + !SM.isMacroArgExpansion(Flags->getLocStart())) return false; // Get the Marco name. @@ -37,16 +38,16 @@ bool HasCloseOnExecFlag(const Expr *Flags, const SourceManager &SM, // If it's a binary OR operation. if (const auto *BO = dyn_cast<BinaryOperator>(Flags)) if (BO->getOpcode() == clang::BinaryOperatorKind::BO_Or) - return HasCloseOnExecFlag(BO->getLHS()->IgnoreParenCasts(), SM, + return hasCloseOnExecFlag(BO->getLHS()->IgnoreParenCasts(), SM, LangOpts) || - HasCloseOnExecFlag(BO->getRHS()->IgnoreParenCasts(), SM, LangOpts); + hasCloseOnExecFlag(BO->getRHS()->IgnoreParenCasts(), SM, LangOpts); // Otherwise, assume it has the flag. return true; } } // namespace -void FileOpenFlagCheck::registerMatchers(MatchFinder *Finder) { +void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) { auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter()))); Finder->addMatcher( @@ -68,7 +69,7 @@ void FileOpenFlagCheck::registerMatchers(MatchFinder *Finder) { this); } -void FileOpenFlagCheck::check(const MatchFinder::MatchResult &Result) { +void CloexecOpenCheck::check(const MatchFinder::MatchResult &Result) { const Expr *FlagArg = nullptr; if (const auto *OpenFnCall = Result.Nodes.getNodeAs<CallExpr>("openFn")) FlagArg = OpenFnCall->getArg(1); @@ -81,12 +82,13 @@ void FileOpenFlagCheck::check(const MatchFinder::MatchResult &Result) { // Check the required flag. SourceManager &SM = *Result.SourceManager; - if (HasCloseOnExecFlag(FlagArg->IgnoreParenCasts(), SM, + if (hasCloseOnExecFlag(FlagArg->IgnoreParenCasts(), SM, Result.Context->getLangOpts())) return; - SourceLocation EndLoc = Lexer::getLocForEndOfToken( - FlagArg->getLocEnd(), 0, SM, Result.Context->getLangOpts()); + SourceLocation EndLoc = + Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getLocEnd()), 0, SM, + Result.Context->getLangOpts()); diag(EndLoc, "%0 should use %1 where possible") << FD << O_CLOEXEC diff --git a/clang-tools-extra/clang-tidy/android/FileOpenFlagCheck.h b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h index 7c39a5ad704..99281778ef2 100644 --- a/clang-tools-extra/clang-tidy/android/FileOpenFlagCheck.h +++ b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h @@ -1,4 +1,4 @@ -//===--- FileOpenFlagCheck.h - clang-tidy----------------------------------===// +//===--- CloexecOpenCheck.h - clang-tidy-----------------------------------===// // // The LLVM Compiler Infrastructure // @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_FILE_OPEN_FLAG_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_FILE_OPEN_FLAG_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H #include "../ClangTidy.h" @@ -25,9 +25,9 @@ namespace android { /// /// Only the symbolic 'O_CLOEXEC' macro definition is checked, not the concrete /// value. -class FileOpenFlagCheck : public ClangTidyCheck { +class CloexecOpenCheck : public ClangTidyCheck { public: - FileOpenFlagCheck(StringRef Name, ClangTidyContext *Context) + CloexecOpenCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context) {} void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; @@ -37,4 +37,4 @@ public: } // namespace tidy } // namespace clang -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_FILE_OPEN_FLAG_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H |