[PATCH] D128833: [clang][dataflow] Handle `for` statements without conditions
Stanislav Gatev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 30 00:01:46 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8207c2a66030: [clang][dataflow] Handle `for` statements without conditions (authored by sgatev).
Herald added a reviewer: NoQ.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128833/new/
https://reviews.llvm.org/D128833
Files:
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===================================================================
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3827,4 +3827,30 @@
});
}
+TEST_F(TransferTest, ForStmtBranchWithoutConditionDoesNotExtendFlowCondition) {
+ std::string Code = R"(
+ void target(bool Foo) {
+ for (;;) {
+ (void)0;
+ // [[loop_body]]
+ }
+ }
+ )";
+ runDataflow(
+ Code, [](llvm::ArrayRef<
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
+ Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results, ElementsAre(Pair("loop_body", _)));
+ const Environment &LoopBodyEnv = Results[0].second.Env;
+
+ const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
+ ASSERT_THAT(FooDecl, NotNull());
+
+ BoolValue &LoopBodyFooVal =
+ *cast<BoolValue>(LoopBodyEnv.getValue(*FooDecl, SkipPast::None));
+ EXPECT_FALSE(LoopBodyEnv.flowConditionImplies(LoopBodyFooVal));
+ });
+}
+
} // namespace
Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -97,8 +97,8 @@
void VisitForStmt(const ForStmt *S) {
auto *Cond = S->getCond();
- assert(Cond != nullptr);
- extendFlowCondition(*Cond);
+ if (Cond != nullptr)
+ extendFlowCondition(*Cond);
}
void VisitBinaryOperator(const BinaryOperator *S) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128833.441277.patch
Type: text/x-patch
Size: 1724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220630/db8f9a86/attachment.bin>
More information about the cfe-commits
mailing list