https://github.com/martinboehme created https://github.com/llvm/llvm-project/pull/85072
I'm working on an upcoming change that will improve the semantics of `Environment::GetResultObjectLocation()` (see the FIXME in the method comment), and this patch improves the test coverage for this change. >From a9193ba0d2a0d4ed3dfd1e35b836a1629aa9a731 Mon Sep 17 00:00:00 2001 From: Martin Braenne <mboe...@google.com> Date: Wed, 13 Mar 2024 13:18:16 +0000 Subject: [PATCH] [clang][dataflow] Add a test for result object location on `CXXDefaultArgExpr`. I'm working on an upcoming change that will improve the semantics of `Environment::GetResultObjectLocation()` (see the FIXME in the method comment), and this patch improves the test coverage for this change. --- .../Analysis/FlowSensitive/TransferTest.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index a8c282f140b4cd..86c7f32f0104be 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -2924,6 +2924,36 @@ TEST(TransferTest, ResultObjectLocation) { }); } +TEST(TransferTest, ResultObjectLocationForDefaultArgExpr) { + std::string Code = R"( + struct S {}; + void funcWithDefaultArg(S s = S()); + void target() { + funcWithDefaultArg(); + // [[p]] + } + )"; + + using ast_matchers::cxxDefaultArgExpr; + using ast_matchers::match; + using ast_matchers::selectFirst; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + auto *DefaultArg = selectFirst<CXXDefaultArgExpr>( + "default_arg", + match(cxxDefaultArgExpr().bind("default_arg"), ASTCtx)); + ASSERT_NE(DefaultArg, nullptr); + + // The values for default arguments aren't modeled; we merely verify + // that we can get a result object location for a default arg. + Env.getResultObjectLocation(*DefaultArg); + }); +} + TEST(TransferTest, ResultObjectLocationForDefaultInitExpr) { std::string Code = R"( struct S {}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits