[clang] [clang][dataflow] Add support for serialization and deserialization. (PR #152487)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 7 05:35:55 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- clang/include/clang/Analysis/FlowSensitive/FormulaSerialization.h clang/lib/Analysis/FlowSensitive/FormulaSerialization.cpp clang/unittests/Analysis/FlowSensitive/FormulaTest.cpp clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h clang/include/clang/Analysis/FlowSensitive/Formula.h clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 2266eff05..076714462 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -163,8 +163,7 @@ public:
/// constructors. This constructor is for specialized use, including
/// deserialization and delegation from other constructors.
Environment(DataflowAnalysisContext &DACtx, Atom FlowConditionToken)
- : DACtx(&DACtx),
- FlowConditionToken(FlowConditionToken) {}
+ : DACtx(&DACtx), FlowConditionToken(FlowConditionToken) {}
/// Creates an environment that uses `DACtx` to store objects that encompass
/// the state of a program. Populates a fresh atom as flow condition token.
diff --git a/clang/include/clang/Analysis/FlowSensitive/FormulaSerialization.h b/clang/include/clang/Analysis/FlowSensitive/FormulaSerialization.h
index f72954d21..da03fe9a8 100644
--- a/clang/include/clang/Analysis/FlowSensitive/FormulaSerialization.h
+++ b/clang/include/clang/Analysis/FlowSensitive/FormulaSerialization.h
@@ -23,7 +23,7 @@
namespace clang::dataflow {
///
-void serializeFormula(const Formula& F, llvm::raw_ostream &OS);
+void serializeFormula(const Formula &F, llvm::raw_ostream &OS);
/// Parses `Str` to build a serialized Formula.
/// @returns error on parse failure or if parsing does not fully consume `Str`.
@@ -35,6 +35,5 @@ llvm::Expected<const Formula *>
parseFormula(llvm::StringRef Str, Arena &A,
llvm::DenseMap<unsigned, Atom> &AtomMap);
-
} // namespace clang::dataflow
#endif
diff --git a/clang/lib/Analysis/FlowSensitive/FormulaSerialization.cpp b/clang/lib/Analysis/FlowSensitive/FormulaSerialization.cpp
index 12c92636d..cfec0851a 100644
--- a/clang/lib/Analysis/FlowSensitive/FormulaSerialization.cpp
+++ b/clang/lib/Analysis/FlowSensitive/FormulaSerialization.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/Analysis/FlowSensitive/Formula.h"
#include "clang/Analysis/FlowSensitive/FormulaSerialization.h"
#include "clang/Analysis/FlowSensitive/Arena.h"
+#include "clang/Analysis/FlowSensitive/Formula.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
@@ -69,7 +69,7 @@ void serializeFormula(const Formula &F, llvm::raw_ostream &OS) {
static llvm::Expected<const Formula *>
parsePrefix(llvm::StringRef &Str, Arena &A,
- llvm::DenseMap<unsigned, Atom> &AtomMap) {
+ llvm::DenseMap<unsigned, Atom> &AtomMap) {
if (Str.empty())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"unexpected end of input");
diff --git a/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp b/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
index 052d35343..07323952b 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -17,8 +17,8 @@ namespace {
using namespace clang;
using namespace dataflow;
-using ::testing::UnorderedElementsAre;
using ::testing::IsEmpty;
+using ::testing::UnorderedElementsAre;
class DataflowAnalysisContextTest : public ::testing::Test {
protected:
@@ -149,11 +149,11 @@ TEST_F(DataflowAnalysisContextTest, GetFlowConditionConstraints) {
const Formula *CS1 = Context.getFlowConditionConstraints(FC1);
ASSERT_NE(CS1, nullptr);
- EXPECT_TRUE(Context.equivalentFormulas(*CS1, A.makeAnd(C1,C3)));
+ EXPECT_TRUE(Context.equivalentFormulas(*CS1, A.makeAnd(C1, C3)));
const Formula *CS2 = Context.getFlowConditionConstraints(FC2);
ASSERT_NE(CS2, nullptr);
- EXPECT_TRUE(Context.equivalentFormulas(*CS2, A.makeAnd(C2,C3)));
+ EXPECT_TRUE(Context.equivalentFormulas(*CS2, A.makeAnd(C2, C3)));
}
TEST_F(DataflowAnalysisContextTest, EquivBoolVals) {
@@ -295,7 +295,6 @@ TEST_F(GetTransitiveClosureTest, SimpleDependencyChain) {
UnorderedElementsAre(FC1, FC2, FC3));
}
-
TEST_F(GetTransitiveClosureTest, DependencyTree) {
Atom FC1 = A.makeFlowConditionToken();
Atom FC2 = A.makeFlowConditionToken();
diff --git a/clang/unittests/Analysis/FlowSensitive/FormulaTest.cpp b/clang/unittests/Analysis/FlowSensitive/FormulaTest.cpp
index 1d6db3cc6..49c02a8f1 100644
--- a/clang/unittests/Analysis/FlowSensitive/FormulaTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/FormulaTest.cpp
@@ -59,32 +59,32 @@ TEST_F(SerializeFormulaTest, Not) {
}
TEST_F(SerializeFormulaTest, Or) {
- serializeFormula(A.makeOr(A1,A2), OS);
+ serializeFormula(A.makeOr(A1, A2), OS);
EXPECT_EQ(Out, "|V0V1");
}
TEST_F(SerializeFormulaTest, And) {
- serializeFormula(A.makeAnd(A1,A2), OS);
+ serializeFormula(A.makeAnd(A1, A2), OS);
EXPECT_EQ(Out, "&V0V1");
}
TEST_F(SerializeFormulaTest, Implies) {
- serializeFormula(A.makeImplies(A1,A2), OS);
+ serializeFormula(A.makeImplies(A1, A2), OS);
EXPECT_EQ(Out, ">V0V1");
}
TEST_F(SerializeFormulaTest, Equal) {
- serializeFormula(A.makeEquals(A1,A2), OS);
+ serializeFormula(A.makeEquals(A1, A2), OS);
EXPECT_EQ(Out, "=V0V1");
}
TEST_F(SerializeFormulaTest, NestedBinaryUnary) {
- serializeFormula(A.makeEquals(A.makeOr(A1,A2),A2), OS);
+ serializeFormula(A.makeEquals(A.makeOr(A1, A2), A2), OS);
EXPECT_EQ(Out, "=|V0V1V1");
}
TEST_F(SerializeFormulaTest, NestedBinaryBinary) {
- serializeFormula(A.makeEquals(A.makeOr(A1,A2),A.makeAnd(A1,A2)), OS);
+ serializeFormula(A.makeEquals(A.makeOr(A1, A2), A.makeAnd(A1, A2)), OS);
EXPECT_EQ(Out, "=|V0V1&V0V1");
}
@@ -107,8 +107,8 @@ protected:
};
TEST_F(ParseFormulaTest, Atom) {
- EXPECT_THAT_EXPECTED(parseFormula( "V0", A, AtomMap), HasValue(&A1));
- EXPECT_THAT_EXPECTED(parseFormula( "V1", A, AtomMap), HasValue(&A2));
+ EXPECT_THAT_EXPECTED(parseFormula("V0", A, AtomMap), HasValue(&A1));
+ EXPECT_THAT_EXPECTED(parseFormula("V1", A, AtomMap), HasValue(&A2));
}
TEST_F(ParseFormulaTest, LiteralTrue) {
@@ -128,27 +128,27 @@ TEST_F(ParseFormulaTest, Not) {
TEST_F(ParseFormulaTest, Or) {
EXPECT_THAT_EXPECTED(parseFormula("|V0V1", A, AtomMap),
- HasValue(&A.makeOr(A1,A2)));
+ HasValue(&A.makeOr(A1, A2)));
}
TEST_F(ParseFormulaTest, And) {
EXPECT_THAT_EXPECTED(parseFormula("&V0V1", A, AtomMap),
- HasValue(&A.makeAnd(A1,A2)));
+ HasValue(&A.makeAnd(A1, A2)));
}
TEST_F(ParseFormulaTest, Implies) {
EXPECT_THAT_EXPECTED(parseFormula(">V0V1", A, AtomMap),
- HasValue(&A.makeImplies(A1,A2)));
+ HasValue(&A.makeImplies(A1, A2)));
}
TEST_F(ParseFormulaTest, Equal) {
EXPECT_THAT_EXPECTED(parseFormula("=V0V1", A, AtomMap),
- HasValue(&A.makeEquals(A1,A2)));
+ HasValue(&A.makeEquals(A1, A2)));
}
TEST_F(ParseFormulaTest, NestedBinaryUnary) {
EXPECT_THAT_EXPECTED(parseFormula("=|V0V1V1", A, AtomMap),
- HasValue(&A.makeEquals(A.makeOr(A1,A2),A2)));
+ HasValue(&A.makeEquals(A.makeOr(A1, A2), A2)));
}
TEST_F(ParseFormulaTest, NestedBinaryBinary) {
@@ -176,5 +176,4 @@ TEST_F(ParseFormulaTest, FormulaWithSuffixFails) {
EXPECT_THAT_EXPECTED(parseFormula("=V0V1Hello", A, AtomMap), llvm::Failed());
}
-
} // namespace
``````````
</details>
https://github.com/llvm/llvm-project/pull/152487
More information about the cfe-commits
mailing list