diff options
author | martinboehme <mboehme@google.com> | 2024-03-08 08:19:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-08 08:19:41 +0100 |
commit | 9b74c43d70f4b39d6fea7b542d77f2b652e4d651 (patch) | |
tree | a579acef2574221fbbc976ea7c852d078ed289dd /clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | |
parent | 2d539db246fd9d26201255b84d04dacf2782eddf (diff) | |
download | llvm-9b74c43d70f4b39d6fea7b542d77f2b652e4d651.zip llvm-9b74c43d70f4b39d6fea7b542d77f2b652e4d651.tar.gz llvm-9b74c43d70f4b39d6fea7b542d77f2b652e4d651.tar.bz2 |
[clang][dataflow] Add context-sensitive test for returning a record by value. (#84317)
I'm making some changes to `Environment::getResultObjectLocation()`,
with the
ultimate goal of eliminating `RecordValue` entirely, and I'd like to
make sure
I don't break this behavior (and I've realized we don't have a test for
it yet).
Diffstat (limited to 'clang/unittests/Analysis/FlowSensitive/TransferTest.cpp')
-rw-r--r-- | clang/unittests/Analysis/FlowSensitive/TransferTest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp index 9fde417..a8c282f 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -5735,6 +5735,39 @@ TEST(TransferTest, ContextSensitiveReturnInt) { {BuiltinOptions{ContextSensitiveOptions{}}}); } +TEST(TransferTest, ContextSensitiveReturnRecord) { + std::string Code = R"( + struct S { + bool B; + }; + + S makeS(bool BVal) { return {BVal}; } + + void target() { + S FalseS = makeS(false); + S TrueS = makeS(true); + // [[p]] + } + )"; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + + auto &FalseSLoc = + getLocForDecl<RecordStorageLocation>(ASTCtx, Env, "FalseS"); + auto &TrueSLoc = + getLocForDecl<RecordStorageLocation>(ASTCtx, Env, "TrueS"); + + EXPECT_EQ(getFieldValue(&FalseSLoc, "B", ASTCtx, Env), + &Env.getBoolLiteralValue(false)); + EXPECT_EQ(getFieldValue(&TrueSLoc, "B", ASTCtx, Env), + &Env.getBoolLiteralValue(true)); + }, + {BuiltinOptions{ContextSensitiveOptions{}}}); +} + TEST(TransferTest, ContextSensitiveMethodLiteral) { std::string Code = R"( class MyClass { |