[PATCH] D117754: [clang][dataflow] Intersect ExprToLoc when joining environments
Stanislav Gatev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 20 06:04:28 PST 2022
sgatev updated this revision to Diff 401615.
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
@@ -23,6 +23,7 @@
#include "clang/Analysis/FlowSensitive/Transfer.h"
#include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
#include "clang/Analysis/FlowSensitive/Value.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/raw_ostream.h"
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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117754.401615.patch
Type: text/x-patch
Size: 2979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220120/bf77ef36/attachment.bin>
More information about the cfe-commits
mailing list