diff options
author | martinboehme <mboehme@google.com> | 2024-04-17 08:05:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 08:05:43 +0200 |
commit | b851c7f1fc4fd83ea84d565bbdc30fd0d356788c (patch) | |
tree | cab5322c05ab5c574692e01cf52d7a1b8b3a6aa3 /clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | |
parent | 024281d4d26344f9613b9115ea1fcbdbdba23235 (diff) | |
download | llvm-b851c7f1fc4fd83ea84d565bbdc30fd0d356788c.zip llvm-b851c7f1fc4fd83ea84d565bbdc30fd0d356788c.tar.gz llvm-b851c7f1fc4fd83ea84d565bbdc30fd0d356788c.tar.bz2 |
[clang][dataflow] Support `StmtExpr` in `PropagateResultObject()`. (#88872)
This patch adds a test that assert-fails without the fix.
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/TransferTest.cpp')
-rw-r--r-- | clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index d8bcc3d..d7a51b0 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -3182,6 +3182,32 @@ TEST(TransferTest, ResultObjectLocationForStdInitializerListExpr) { }); } +TEST(TransferTest, ResultObjectLocationForStmtExpr) { + std::string Code = R"( + struct S {}; + void target() { + S s = ({ S(); }); + // [[p]] + } + )"; + using ast_matchers::cxxConstructExpr; + using ast_matchers::match; + using ast_matchers::selectFirst; + using ast_matchers::traverse; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + auto *Construct = selectFirst<CXXConstructExpr>( + "construct", match(cxxConstructExpr().bind("construct"), ASTCtx)); + + EXPECT_EQ(&Env.getResultObjectLocation(*Construct), + &getLocForDecl<RecordStorageLocation>(ASTCtx, Env, "s")); + }); +} + TEST(TransferTest, ResultObjectLocationPropagatesThroughConditionalOperator) { std::string Code = R"( struct A { |