9 #include "../utils/Matchers.h" 11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/Lex/Lexer.h" 22 AST_MATCHER(BinaryOperator, isRHSATempFailureRetryArg) {
23 if (!Node.getBeginLoc().isMacroID())
26 const SourceManager &SM = Finder->getASTContext().getSourceManager();
27 if (!SM.isMacroArgExpansion(Node.getRHS()->IgnoreParenCasts()->getBeginLoc()))
30 const LangOptions &Opts = Finder->getASTContext().getLangOpts();
31 SourceLocation LocStart = Node.getBeginLoc();
32 while (LocStart.isMacroID()) {
33 SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart);
35 if (!Lexer::getRawToken(SM.getSpellingLoc(Invocation), Tok, SM, Opts,
37 if (Tok.getKind() == tok::raw_identifier &&
38 Tok.getRawIdentifier() ==
"TEMP_FAILURE_RETRY")
42 LocStart = Invocation;
48 void ComparisonInTempFailureRetryCheck::registerMatchers(MatchFinder *Finder) {
66 hasRHS(ignoringParenCasts(
67 binaryOperator(matchers::isComparisonOperator()).bind(
"binop"))),
68 isRHSATempFailureRetryArg()),
72 void ComparisonInTempFailureRetryCheck::check(
73 const MatchFinder::MatchResult &
Result) {
74 const auto &BinOp = *Result.Nodes.getNodeAs<BinaryOperator>(
"binop");
75 diag(BinOp.getOperatorLoc(),
"top-level comparison in TEMP_FAILURE_RETRY");
AST_MATCHER(Expr, isMacroID)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result