This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG1e7329cd79c5: [clang][dataflow] Model variables / fields / funcs used in default initializers. (authored by mboehme).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D154420/new/ https://reviews.llvm.org/D154420 Files: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 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 @@ -5547,4 +5547,40 @@ }); } +TEST(TransferTest, AnonymousStructWithReferenceField) { + std::string Code = R"( + int global_i = 0; + struct target { + target() { + (void)0; + // [[p]] + } + struct { + int &i = global_i; + }; + }; + )"; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + const ValueDecl *GlobalIDecl = findValueDecl(ASTCtx, "global_i"); + const ValueDecl *IDecl = findValueDecl(ASTCtx, "i"); + const IndirectFieldDecl *IndirectField = + findIndirectFieldDecl(ASTCtx, "i"); + + auto *ThisLoc = + cast<AggregateStorageLocation>(Env.getThisPointeeStorageLocation()); + auto &AnonStruct = cast<AggregateStorageLocation>(ThisLoc->getChild( + *cast<ValueDecl>(IndirectField->chain().front()))); + + auto *RefVal = + cast<ReferenceValue>(Env.getValue(AnonStruct.getChild(*IDecl))); + + ASSERT_EQ(&RefVal->getReferentLoc(), + Env.getStorageLocation(*GlobalIDecl)); + }); +} + } // namespace Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp =================================================================== --- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -194,6 +194,8 @@ for (auto *Child : S.children()) if (Child != nullptr) getFieldsGlobalsAndFuncs(*Child, Fields, Vars, Funcs); + if (const auto *DefaultInit = dyn_cast<CXXDefaultInitExpr>(&S)) + getFieldsGlobalsAndFuncs(*DefaultInit->getExpr(), Fields, Vars, Funcs); if (auto *DS = dyn_cast<DeclStmt>(&S)) { if (DS->isSingleDecl())
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp =================================================================== --- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -5547,4 +5547,40 @@ }); } +TEST(TransferTest, AnonymousStructWithReferenceField) { + std::string Code = R"( + int global_i = 0; + struct target { + target() { + (void)0; + // [[p]] + } + struct { + int &i = global_i; + }; + }; + )"; + runDataflow( + Code, + [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results, + ASTContext &ASTCtx) { + const Environment &Env = getEnvironmentAtAnnotation(Results, "p"); + const ValueDecl *GlobalIDecl = findValueDecl(ASTCtx, "global_i"); + const ValueDecl *IDecl = findValueDecl(ASTCtx, "i"); + const IndirectFieldDecl *IndirectField = + findIndirectFieldDecl(ASTCtx, "i"); + + auto *ThisLoc = + cast<AggregateStorageLocation>(Env.getThisPointeeStorageLocation()); + auto &AnonStruct = cast<AggregateStorageLocation>(ThisLoc->getChild( + *cast<ValueDecl>(IndirectField->chain().front()))); + + auto *RefVal = + cast<ReferenceValue>(Env.getValue(AnonStruct.getChild(*IDecl))); + + ASSERT_EQ(&RefVal->getReferentLoc(), + Env.getStorageLocation(*GlobalIDecl)); + }); +} + } // namespace Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp =================================================================== --- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -194,6 +194,8 @@ for (auto *Child : S.children()) if (Child != nullptr) getFieldsGlobalsAndFuncs(*Child, Fields, Vars, Funcs); + if (const auto *DefaultInit = dyn_cast<CXXDefaultInitExpr>(&S)) + getFieldsGlobalsAndFuncs(*DefaultInit->getExpr(), Fields, Vars, Funcs); if (auto *DS = dyn_cast<DeclStmt>(&S)) { if (DS->isSingleDecl())
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits