[clang] [dataflow] CXXForRangeStmt should extend flow condition (PR #80989)
Paul Semel via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 7 05:29:23 PST 2024
https://github.com/paulsemel created https://github.com/llvm/llvm-project/pull/80989
This is needed in order to correctly assume implicit iterator validity in the iterator checker.
>From b227aa82732cdc087ead5df62077055042d22696 Mon Sep 17 00:00:00 2001
From: Paul Semel <semelpaul at gmail.com>
Date: Wed, 7 Feb 2024 13:06:40 +0000
Subject: [PATCH] [dataflow] CXXForRangeStmt should extend flow condition
This is needed in order to correctly assume implicit iterator validity
in the iterator checker.
---
.../FlowSensitive/TypeErasedDataflowAnalysis.cpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 4c88c46142d64d..f02c65094113ec 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -103,9 +103,12 @@ class TerminatorVisitor
return {nullptr, false};
}
- TerminatorVisitorRetTy VisitCXXForRangeStmt(const CXXForRangeStmt *) {
- // Don't do anything special for CXXForRangeStmt, because the condition
- // (being implicitly generated) isn't visible from the loop body.
+ TerminatorVisitorRetTy VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
+ // Even though the condition isn't visible from the loop body, analysis
+ // might depend on the implicit implicit statements implied by the loop.
+ auto *Cond = S->getCond();
+ if (Cond != nullptr)
+ return extendFlowCondition(*Cond);
return {nullptr, false};
}
More information about the cfe-commits
mailing list