[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker
Dmitri Gribenko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 23 07:45:32 PDT 2022
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:159
+ llvm::SmallSet<const Decl *, 16> &Callees) {
+ if (const CallExpr *Call = dyn_cast<CallExpr>(StmtNode)) {
+ const Decl *Callee = Call->getDirectCallee();
----------------
Eugene.Zelenko wrote:
> `auto` could be used, because type is spelled in same statement.
Please clang-format before submitting (it looks like this block is indented 4 instead of 2).
================
Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:184-185
+ const Decl *Func) {
+ bool containsFunc = false;
+ bool overlap = false;
+
----------------
================
Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:188-191
+ const Decl *CanoDecl = GNode->getDecl()->getCanonicalDecl();
+
+ containsFunc |= (CanoDecl == Func);
+ overlap |= Callees.contains(CanoDecl);
----------------
Canonical => Can is the usual abbreviation, if you want to use one (e.g., see CanQualType)
================
Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:198-199
+
+/// returns true iff `Cond` involves at least one static local variable.
+static bool hasStaticLocalVariable(const Stmt *Cond) {
+ if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Cond))
----------------
================
Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:210
+
+/// Tests if the loop `Cond` involves static local variables and
+/// the enclosing function `Func` is recursive.
----------------
`Cond` is not the loop itself.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128401/new/
https://reviews.llvm.org/D128401
More information about the cfe-commits
mailing list