aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
diff options
context:
space:
mode:
authormartinboehme <mboehme@google.com>2024-03-18 13:36:20 +0100
committerGitHub <noreply@github.com>2024-03-18 13:36:20 +0100
commit27d504998ec7ec596bc9ff5d16333aea7a1bac18 (patch)
tree688d107c11bb1a556d949d0db4ca6215069926fa /clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
parent24692088181dd18e491a413d98d9c2ae30464454 (diff)
downloadllvm-27d504998ec7ec596bc9ff5d16333aea7a1bac18.zip
llvm-27d504998ec7ec596bc9ff5d16333aea7a1bac18.tar.gz
llvm-27d504998ec7ec596bc9ff5d16333aea7a1bac18.tar.bz2
[clang][dataflow] Fix `getResultObjectLocation()` on `CXXDefaultArgExpr`. (#85072)
This patch includes a test that causes an assertion failure without the other changes in this patch.
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/TransferTest.cpp')
-rw-r--r--clang/unittests/Analysis/FlowSensitive/TransferTest.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index a8c282f..86c7f32 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 {};