blob: 7b000ab2f54f6c9b20b78da939a64b17d6f0e254 [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//===--- 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
17namespace clang {
18namespace tidy {
19namespace 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.
26class ComparisonInTempFailureRetryCheck : public ClangTidyCheck {
27public:
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
33private:
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