[PATCH] D155465: [clang][dataflow] Bugfix for `refreshStructValue()`.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 17 11:56:50 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f6cf5556749: [clang][dataflow] Bugfix for `refreshStructValue()`. (authored by mboehme).
Changed prior to commit:
https://reviews.llvm.org/D155465?vs=541019&id=541172#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155465/new/
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
@@ -25,6 +25,7 @@
using namespace clang;
using namespace dataflow;
using ::clang::dataflow::test::getFieldValue;
+using ::testing::IsNull;
using ::testing::NotNull;
class EnvironmentTest : public ::testing::Test {
@@ -252,4 +253,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
@@ -1005,6 +1005,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.541172.patch
Type: text/x-patch
Size: 2072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230717/7c137c81/attachment.bin>
More information about the cfe-commits
mailing list