[PATCH] D126314: [clang][dataflow] Relax `Environment` comparison operation.
Yitzhak Mandelbaum via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 24 13:58:45 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2f93bbb9cd7c: [clang][dataflow] Relax `Environment` comparison operation. (authored by ymandel).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126314/new/
https://reviews.llvm.org/D126314
Files:
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.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
@@ -3120,4 +3120,59 @@
});
}
+TEST_F(TransferTest, LoopWithStructReferenceAssignmentConverges) {
+ std::string Code = R"(
+ struct Lookup {
+ int x;
+ };
+
+ void target(Lookup val, bool b) {
+ const Lookup* l = nullptr;
+ while (b) {
+ l = &val;
+ /*[[p-inner]]*/
+ }
+ (void)0;
+ /*[[p-outer]]*/
+ }
+ )";
+ // The key property that we are verifying is implicit in `runDataflow` --
+ // namely, that the analysis succeeds, rather than hitting the maximum number
+ // of iterations.
+ runDataflow(
+ Code, [](llvm::ArrayRef<
+ std::pair<std::string, DataflowAnalysisState<NoopLattice>>>
+ Results,
+ ASTContext &ASTCtx) {
+ ASSERT_THAT(Results,
+ ElementsAre(Pair("p-outer", _), Pair("p-inner", _)));
+ const Environment &OuterEnv = Results[0].second.Env;
+ const Environment &InnerEnv = Results[1].second.Env;
+
+ const ValueDecl *ValDecl = findValueDecl(ASTCtx, "val");
+ ASSERT_THAT(ValDecl, NotNull());
+
+ const ValueDecl *LDecl = findValueDecl(ASTCtx, "l");
+ ASSERT_THAT(LDecl, NotNull());
+
+ // Inner.
+ auto *LVal = dyn_cast<IndirectionValue>(
+ InnerEnv.getValue(*LDecl, SkipPast::None));
+ ASSERT_THAT(LVal, NotNull());
+
+ EXPECT_EQ(&LVal->getPointeeLoc(),
+ InnerEnv.getStorageLocation(*ValDecl, SkipPast::Reference));
+
+ // Outer.
+ LVal = dyn_cast<IndirectionValue>(
+ OuterEnv.getValue(*LDecl, SkipPast::None));
+ ASSERT_THAT(LVal, NotNull());
+
+ // The loop body may not have been executed, so we should not conclude
+ // that `l` points to `val`.
+ EXPECT_NE(&LVal->getPointeeLoc(),
+ OuterEnv.getStorageLocation(*ValDecl, SkipPast::Reference));
+});
+}
+
} // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -239,9 +239,6 @@
if (ExprToLoc != Other.ExprToLoc)
return false;
- if (MemberLocToStruct != Other.MemberLocToStruct)
- return false;
-
// Compare the contents for the intersection of their domains.
for (auto &Entry : LocToVal) {
const StorageLocation *Loc = Entry.first;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126314.431785.patch
Type: text/x-patch
Size: 2719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220524/17ea5b59/attachment.bin>
More information about the cfe-commits
mailing list