[clang] ba53906 - [clang][dataflow] Add support for comma binary operator
Stanislav Gatev via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 17 10:48:46 PDT 2022
Author: Stanislav Gatev
Date: 2022-06-17T17:48:21Z
New Revision: ba53906ceff1e7979cac37ff6fdc27e976fc169a
URL: https://github.com/llvm/llvm-project/commit/ba53906ceff1e7979cac37ff6fdc27e976fc169a
DIFF: https://github.com/llvm/llvm-project/commit/ba53906ceff1e7979cac37ff6fdc27e976fc169a.diff
LOG: [clang][dataflow] Add support for comma binary operator
Add support for comma binary operator.
Differential Revision: https://reviews.llvm.org/D128013
Reviewed-by: ymandel, xazax.hun
Added:
Modified:
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index a56e277f7962f..befd3c6263114 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -95,6 +95,11 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
: Env.makeNot(LHSEqRHSValue));
break;
}
+ case BO_Comma: {
+ if (auto *Loc = Env.getStorageLocation(*RHS, SkipPast::None))
+ Env.setStorageLocation(*S, *Loc);
+ break;
+ }
default:
break;
}
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index e3c97367b17ca..ab51bf2196b79 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3557,4 +3557,35 @@ TEST_F(TransferTest, StructuredBindingAssignFromStructIntMembersToInts) {
});
}
+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
More information about the cfe-commits
mailing list