Skip to content

Commit

Permalink
[clang][dataflow] Add context-sensitive test for returning a record b…
Browse files Browse the repository at this point in the history
…y value. (llvm#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).
  • Loading branch information
martinboehme authored Mar 8, 2024
1 parent 2d539db commit 9b74c43
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9b74c43

Please sign in to comment.