[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 25 06:59:14 PDT 2024
================
@@ -323,12 +342,13 @@ class ExprEngine {
/// ProcessBranch - Called by CoreEngine. Used to generate successor
/// nodes by processing the 'effects' of a branch condition.
- void processBranch(const Stmt *Condition,
- NodeBuilderContext& BuilderCtx,
- ExplodedNode *Pred,
- ExplodedNodeSet &Dst,
- const CFGBlock *DstT,
- const CFGBlock *DstF);
+ /// If the branch condition is a loop condition, IterationsFinishedInLoop is
+ /// the number of already finished iterations (0, 1, 2...); otherwise it's
+ /// std::nullopt.
----------------
NagyDonat wrote:
> Can't IterationsFinishedInLoop be a state trait?
We could introduce it, but we'd need to maintain a nested stack of loops (1 iteration in that `while`, then 2 iterations in the `for`, then 1 iteration in this other `for` in the function called there...) to correctly monitor the number of iterations.
This would make the heuristic introduced in this commit slightly more accurate, but I think that for practical purposes the current code is already good enough, so I didn't invest time into implementing this loop iteration count stack. (However it would be a nice follow-up commit if I have time.)
https://github.com/llvm/llvm-project/pull/109804
More information about the cfe-commits
mailing list