================ @@ -9,22 +9,33 @@ #include "FloatLoopCounter.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" using namespace clang::ast_matchers; namespace clang::tidy::cert { void FloatLoopCounter::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher( - forStmt(hasIncrement(expr(hasType(realFloatingPointType())))).bind("for"), - this); + Finder->addMatcher(forStmt(hasIncrement(forEachDescendant( + declRefExpr(hasType(realFloatingPointType()), + to(varDecl().bind("var"))))), + hasCondition(forEachDescendant(declRefExpr( + hasType(realFloatingPointType()), + to(varDecl(equalsBoundNode("var"))))))) + .bind("for"), + this); } void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) { const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for"); - diag(FS->getInc()->getExprLoc(), "loop induction expression should not have " - "floating-point type"); + diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have " + "floating-point type"); ---------------- 5chmidti wrote:
Thoughts on binding both `declRefExpr`s and streaming their source ranges into the diagnostic? ``` for (float val = 0.1f; val <= 1.0f; val += 0.1f) {} ~~~ ^~~ ``` (probably also changing the diag location to the `declRefExpr` in the increment as well) You could also add the name of the bound variable to the diagnostic https://github.com/llvm/llvm-project/pull/108706 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits