This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGba53906ceff1: [clang][dataflow] Add support for comma binary operator (authored by sgatev).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128013/new/ https://reviews.llvm.org/D128013 Files: clang/lib/Analysis/FlowSensitive/Transfer.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 @@ -3557,4 +3557,35 @@ }); } +TEST_F(TransferTest, BinaryOperatorComma) { + std::string Code = R"( + void target(int Foo, int Bar) { + int &Baz = (Foo, Bar); + // [[p]] + } + )"; + runDataflow(Code, + [](llvm::ArrayRef< + std::pair<std::string, DataflowAnalysisState<NoopLattice>>> + Results, + ASTContext &ASTCtx) { + ASSERT_THAT(Results, ElementsAre(Pair("p", _))); + const Environment &Env = Results[0].second.Env; + + const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); + ASSERT_THAT(BarDecl, NotNull()); + + const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz"); + ASSERT_THAT(BazDecl, NotNull()); + + const StorageLocation *BarLoc = + Env.getStorageLocation(*BarDecl, SkipPast::Reference); + ASSERT_THAT(BarLoc, NotNull()); + + const StorageLocation *BazLoc = + Env.getStorageLocation(*BazDecl, SkipPast::Reference); + EXPECT_EQ(BazLoc, BarLoc); + }); +} + } // namespace Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp =================================================================== --- clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -95,6 +95,11 @@ : Env.makeNot(LHSEqRHSValue)); break; } + case BO_Comma: { + if (auto *Loc = Env.getStorageLocation(*RHS, SkipPast::None)) + Env.setStorageLocation(*S, *Loc); + break; + } default: break; }
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp =================================================================== --- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp +++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp @@ -3557,4 +3557,35 @@ }); } +TEST_F(TransferTest, BinaryOperatorComma) { + std::string Code = R"( + void target(int Foo, int Bar) { + int &Baz = (Foo, Bar); + // [[p]] + } + )"; + runDataflow(Code, + [](llvm::ArrayRef< + std::pair<std::string, DataflowAnalysisState<NoopLattice>>> + Results, + ASTContext &ASTCtx) { + ASSERT_THAT(Results, ElementsAre(Pair("p", _))); + const Environment &Env = Results[0].second.Env; + + const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar"); + ASSERT_THAT(BarDecl, NotNull()); + + const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz"); + ASSERT_THAT(BazDecl, NotNull()); + + const StorageLocation *BarLoc = + Env.getStorageLocation(*BarDecl, SkipPast::Reference); + ASSERT_THAT(BarLoc, NotNull()); + + const StorageLocation *BazLoc = + Env.getStorageLocation(*BazDecl, SkipPast::Reference); + EXPECT_EQ(BazLoc, BarLoc); + }); +} + } // namespace Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp =================================================================== --- clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -95,6 +95,11 @@ : Env.makeNot(LHSEqRHSValue)); break; } + case BO_Comma: { + if (auto *Loc = Env.getStorageLocation(*RHS, SkipPast::None)) + Env.setStorageLocation(*S, *Loc); + break; + } default: break; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits