Skip to content

Commit

Permalink
[clang][dataflow] Add a test for not explicitly initialized fields in…
Browse files Browse the repository at this point in the history
… aggregate initialization.

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D155074
  • Loading branch information
martinboehme committed Jul 17, 2023
1 parent c6bd873 commit 4782597
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 @@ -2944,6 +2944,39 @@ TEST(TransferTest, AggregateInitializationReferenceField) {
});
}

TEST(TransferTest, AggregateInitialization_NotExplicitlyInitializedField) {
std::string Code = R"(
struct S {
int i1;
int i2;
};
void target(int i) {
S s = { i };
/*[[p]]*/
}
)";
runDataflow(
Code,
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
ASTContext &ASTCtx) {
const Environment &Env = getEnvironmentAtAnnotation(Results, "p");

const ValueDecl *I1FieldDecl = findValueDecl(ASTCtx, "i1");
const ValueDecl *I2FieldDecl = findValueDecl(ASTCtx, "i2");

auto &SLoc = getLocForDecl<AggregateStorageLocation>(ASTCtx, Env, "s");

auto &IValue = getValueForDecl<IntegerValue>(ASTCtx, Env, "i");
auto &I1Value =
*cast<IntegerValue>(getFieldValue(&SLoc, *I1FieldDecl, Env));
EXPECT_EQ(&I1Value, &IValue);
auto &I2Value =
*cast<IntegerValue>(getFieldValue(&SLoc, *I2FieldDecl, Env));
EXPECT_NE(&I2Value, &IValue);
});
}

TEST(TransferTest, AssignToUnionMember) {
std::string Code = R"(
union A {
Expand Down

0 comments on commit 4782597

Please sign in to comment.