• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===--- ComparisonInTempFailureRetryCheck.h - clang-tidy--------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_COMPARISONINTEMPFAILURERETRYCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_COMPARISONINTEMPFAILURERETRYCHECK_H
11 
12 #include "../ClangTidyCheck.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/ADT/StringRef.h"
15 #include <string>
16 
17 namespace clang {
18 namespace tidy {
19 namespace android {
20 
21 /// Attempts to catch calls to TEMP_FAILURE_RETRY with a top-level comparison
22 /// operation, like `TEMP_FAILURE_RETRY(read(...) != N)`. In these cases, the
23 /// comparison should go outside of the TEMP_FAILURE_RETRY.
24 ///
25 /// TEMP_FAILURE_RETRY is a macro provided by both glibc and Bionic.
26 class ComparisonInTempFailureRetryCheck : public ClangTidyCheck {
27 public:
28   ComparisonInTempFailureRetryCheck(StringRef Name, ClangTidyContext *Context);
29   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
30   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
31   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32 
33 private:
34   const std::string RawRetryList;
35   SmallVector<StringRef, 5> RetryMacros;
36 };
37 
38 } // namespace android
39 } // namespace tidy
40 } // namespace clang
41 
42 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_COMPARISONINTEMPFAILURERETRYCHECK_H
43