mboehme created this revision. Herald added subscribers: martong, xazax.hun. Herald added a project: All. mboehme requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D155074 Files: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp =================================================================== --- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -2940,6 +2940,39 @@ }); } +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 {
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp =================================================================== --- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -2940,6 +2940,39 @@ }); } +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 {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits