[PATCH] D155465: [clang][dataflow] Bugfix for `refreshStructValue()`.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 17 07:26:23 PDT 2023
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
In the case where the expression was not yet associated with a storage location,
we created a new storage location but failed to associate it with the
expression.
The newly added test fails without the fix.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155465
Files:
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
Index: clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
===================================================================
--- clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -26,6 +26,7 @@
using namespace dataflow;
using ::clang::dataflow::test::getFieldValue;
using ::testing::ElementsAre;
+using ::testing::IsNull;
using ::testing::NotNull;
using ::testing::Pair;
@@ -253,4 +254,35 @@
EXPECT_THAT(Env.getValue(*Var), NotNull());
}
+TEST_F(EnvironmentTest, RefreshStructValue) {
+ using namespace ast_matchers;
+
+ std::string Code = R"cc(
+ struct S {};
+ void target () {
+ S s;
+ s;
+ }
+ )cc";
+
+ auto Unit =
+ tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++11"});
+ auto &Context = Unit->getASTContext();
+
+ ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
+
+ auto Results = match(functionDecl(hasName("target")).bind("target"), Context);
+ const auto *Target = selectFirst<FunctionDecl>("target", Results);
+ ASSERT_THAT(Target, NotNull());
+
+ Results = match(declRefExpr(to(varDecl(hasName("s")))).bind("s"), Context);
+ const auto *DRE = selectFirst<DeclRefExpr>("s", Results);
+ ASSERT_THAT(DRE, NotNull());
+
+ Environment Env(DAContext, *Target);
+ EXPECT_THAT(Env.getStorageLocationStrict(*DRE), IsNull());
+ refreshStructValue(*DRE, Env);
+ EXPECT_THAT(Env.getStorageLocationStrict(*DRE), NotNull());
+}
+
} // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -1011,6 +1011,7 @@
StorageLocation *Loc = Env.getStorageLocationStrict(Expr);
if (Loc == nullptr) {
Loc = &Env.createStorageLocation(Expr);
+ Env.setStorageLocation(Expr, *Loc);
}
Env.setValue(*Loc, NewVal);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155465.541019.patch
Type: text/x-patch
Size: 2053 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230717/28a5221c/attachment-0001.bin>
More information about the cfe-commits
mailing list