sgatev updated this revision to Diff 401581. sgatev marked an inline comment as done. sgatev added a comment.
Address reviewers' comments. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D117754/new/ https://reviews.llvm.org/D117754 Files: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 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 @@ -1828,4 +1828,41 @@ }); } +TEST_F(TransferTest, VarDeclInDoWhile) { + std::string Code = R"( + void target(int *Foo) { + do { + int Bar = *Foo; + } while (true); + (void)0; + /*[[p]]*/ + } + )"; + runDataflow(Code, + [](llvm::ArrayRef< + std::pair<std::string, DataflowAnalysisState<NoopLattice>>> + Results, + ASTContext &ASTCtx) { + ASSERT_THAT(Results, ElementsAre(Pair("p", _))); + const Environment &Env = Results[0].second.Env; + + const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo"); + ASSERT_THAT(FooDecl, NotNull()); + + const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); + ASSERT_THAT(BarDecl, NotNull()); + + const auto *FooVal = + cast<PointerValue>(Env.getValue(*FooDecl, SkipPast::None)); + const auto *FooPointeeVal = + cast<IntegerValue>(Env.getValue(FooVal->getPointeeLoc())); + + const auto *BarVal = dyn_cast_or_null<IntegerValue>( + Env.getValue(*BarDecl, SkipPast::None)); + ASSERT_THAT(BarVal, NotNull()); + + EXPECT_EQ(BarVal, FooPointeeVal); + }); +} + } // namespace Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp =================================================================== --- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp +++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include <memory> +#include <set> #include <utility> #include <vector> @@ -30,6 +31,16 @@ namespace clang { namespace dataflow { +struct CFGBlockPtrCompare { + bool operator()(const CFGBlock *LHS, const CFGBlock *RHS) const { + if (LHS == nullptr) + return true; + if (RHS == nullptr) + return false; + return LHS->getBlockID() < RHS->getBlockID(); + } +}; + /// Computes the input state for a given basic block by joining the output /// states of its predecessors. /// @@ -43,7 +54,9 @@ std::vector<llvm::Optional<TypeErasedDataflowAnalysisState>> &BlockStates, const CFGBlock &Block, const Environment &InitEnv, TypeErasedDataflowAnalysis &Analysis) { - llvm::DenseSet<const CFGBlock *> Preds; + // Ensure the order of predecessor blocks is deterministic to avoid flakiness + // in tests. + std::set<const CFGBlock *, CFGBlockPtrCompare> Preds; Preds.insert(Block.pred_begin(), Block.pred_end()); if (Block.getTerminator().isTemporaryDtorsBranch()) { // This handles a special case where the code that produced the CFG includes Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp =================================================================== --- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -83,6 +83,11 @@ if (DeclToLocSizeBefore != DeclToLoc.size()) Effect = LatticeJoinEffect::Changed; + const unsigned ExprToLocSizeBefore = ExprToLoc.size(); + ExprToLoc = intersectDenseMaps(ExprToLoc, Other.ExprToLoc); + if (ExprToLocSizeBefore != ExprToLoc.size()) + Effect = LatticeJoinEffect::Changed; + // FIXME: Add support for joining distinct values that are assigned to the // same storage locations in `LocToVal` and `Other.LocToVal`. const unsigned LocToValSizeBefore = LocToVal.size();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits