[PATCH] D158848: [clang][dataflow] Support range-for loops in fixpoint algorithm.
Yitzhak Mandelbaum via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 25 07:49:41 PDT 2023
ymandel created this revision.
ymandel added reviewers: mboehme, xazax.hun.
Herald added a subscriber: martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.
Adds support for recognizing range-for loops in the main algorithm for computing
the model fixpoint.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158848
Files:
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===================================================================
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -1612,4 +1612,24 @@
});
}
+
+TEST_F(TopTest, ForRangeStmtConverges) {
+ std::string Code = R"(
+ void target(bool Foo) {
+ int Ints[10];
+ bool B = false;
+ for (int I : Ints)
+ B = true;
+ (void)0;
+ // [[after_loop]]
+ }
+ )";
+ runDataflow(
+ Code,
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
+ const AnalysisOutputs &) {
+ EXPECT_THAT(Results.keys(),
+ UnorderedElementsAre("loop_body", "after_loop"));
+ });
+}
} // namespace
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -58,6 +58,7 @@
case Stmt::WhileStmtClass:
case Stmt::DoStmtClass:
case Stmt::ForStmtClass:
+ case Stmt::CXXForRangeStmtClass:
return true;
default:
return false;
@@ -108,6 +109,9 @@
return {nullptr, false};
}
+ // Don't do anything special for CXXForRangeStmt, because the condition (being
+ // implicitly generated) isn't visible from the loop body.
+
TerminatorVisitorRetTy VisitBinaryOperator(const BinaryOperator *S) {
assert(S->getOpcode() == BO_LAnd || S->getOpcode() == BO_LOr);
auto *LHS = S->getLHS();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158848.553474.patch
Type: text/x-patch
Size: 1734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230825/faaf4143/attachment.bin>
More information about the cfe-commits
mailing list