Skip to content

Commit a9193ba

Browse files
committed
[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.
1 parent f1ca2a0 commit a9193ba

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,36 @@ TEST(TransferTest, ResultObjectLocation) {
29242924
});
29252925
}
29262926

2927+
TEST(TransferTest, ResultObjectLocationForDefaultArgExpr) {
2928+
std::string Code = R"(
2929+
struct S {};
2930+
void funcWithDefaultArg(S s = S());
2931+
void target() {
2932+
funcWithDefaultArg();
2933+
// [[p]]
2934+
}
2935+
)";
2936+
2937+
using ast_matchers::cxxDefaultArgExpr;
2938+
using ast_matchers::match;
2939+
using ast_matchers::selectFirst;
2940+
runDataflow(
2941+
Code,
2942+
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
2943+
ASTContext &ASTCtx) {
2944+
const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
2945+
2946+
auto *DefaultArg = selectFirst<CXXDefaultArgExpr>(
2947+
"default_arg",
2948+
match(cxxDefaultArgExpr().bind("default_arg"), ASTCtx));
2949+
ASSERT_NE(DefaultArg, nullptr);
2950+
2951+
// The values for default arguments aren't modeled; we merely verify
2952+
// that we can get a result object location for a default arg.
2953+
Env.getResultObjectLocation(*DefaultArg);
2954+
});
2955+
}
2956+
29272957
TEST(TransferTest, ResultObjectLocationForDefaultInitExpr) {
29282958
std::string Code = R"(
29292959
struct S {};

0 commit comments

Comments
 (0)