[clang] [clang][dataflow] Add a test for result object location on `CXXDefaultArgExpr`. (PR #85072)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 13 06:19:41 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (martinboehme)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/85072.diff
1 Files Affected:
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+30)
``````````diff
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 {};
``````````
</details>
https://github.com/llvm/llvm-project/pull/85072
More information about the cfe-commits
mailing list