9#include "../utils/Matchers.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
13#include "clang/Lex/Lexer.h"
22 RawRetryList(Options.get(
"RetryMacros",
"TEMP_FAILURE_RETRY")) {
23 StringRef(RawRetryList).split(RetryMacros,
",", -1,
false);
47 binaryOperator(hasOperatorName(
"="),
48 hasRHS(ignoringParenCasts(
49 binaryOperator(isComparisonOperator()).bind(
"inner"))))
55 const MatchFinder::MatchResult &Result) {
56 StringRef RetryMacroName;
57 const auto &
Node = *Result.Nodes.getNodeAs<BinaryOperator>(
"outer");
58 if (!
Node.getBeginLoc().isMacroID())
61 const SourceManager &SM = *Result.SourceManager;
62 if (!SM.isMacroArgExpansion(
Node.getRHS()->IgnoreParenCasts()->getBeginLoc()))
65 const LangOptions &Opts = Result.Context->getLangOpts();
66 SourceLocation LocStart =
Node.getBeginLoc();
67 while (LocStart.isMacroID()) {
68 SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart);
70 if (!Lexer::getRawToken(SM.getSpellingLoc(Invocation), Tok, SM, Opts,
72 if (Tok.getKind() == tok::raw_identifier &&
73 llvm::is_contained(RetryMacros, Tok.getRawIdentifier())) {
74 RetryMacroName = Tok.getRawIdentifier();
79 LocStart = Invocation;
81 if (RetryMacroName.empty())
84 const auto &
Inner = *Result.Nodes.getNodeAs<BinaryOperator>(
"inner");
85 diag(
Inner.getOperatorLoc(),
"top-level comparison in %0") << RetryMacroName;
std::pair< Context, Canceler > Inner
llvm::SmallString< 256U > Name
::clang::DynTypedNode Node
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
ComparisonInTempFailureRetryCheck(StringRef Name, ClangTidyContext *Context)
llvm::StringMap< ClangTidyValue > OptionMap