================ @@ -403,4 +405,35 @@ TEST_F(EnvironmentTest, Contains(Member)); } +TEST_F(EnvironmentTest, Stmt) { + using namespace ast_matchers; + + std::string Code = R"cc( + struct S {int i;}; + void foo() { + S AnS = S{1}; + } + )cc"; + auto Unit = + tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++11"}); + auto &Context = Unit->getASTContext(); + + ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U); + + auto *DeclStatement = const_cast<DeclStmt *>( + selectFirst<DeclStmt>("d", match(declStmt().bind("d"), Context))); + ASSERT_THAT(DeclStatement, NotNull()); + auto *ConstructExpr = selectFirst<CXXConstructExpr>( + "c", match(cxxConstructExpr().bind("c"), Context)); + ASSERT_THAT(ConstructExpr, NotNull()); + + // Verify that we can retrieve the result object location for the construction + // expression when we analyze the DeclStmt for `AnS`. + Environment Env(DAContext, *DeclStatement); + // Don't crash when initializing. + Env.initialize(); + // And don't crash when retrieving the result object location. + Env.getResultObjectLocation(*ConstructExpr); ---------------- bazuzi wrote:
Correct, only result objects and referenced decls. I didn't see much opportunity to check the value of anything in particular. https://github.com/llvm/llvm-project/pull/91616 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits