using namespace clang;
using namespace dataflow;
using ::clang::dataflow::test::getFieldValue;
+using ::testing::IsNull;
using ::testing::NotNull;
class EnvironmentTest : public ::testing::Test {
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