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) {
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) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits