[clang] Introduce virtual interface for lattices and remove dependency on `llvm::Any`. (PR #120967)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 23 05:58:47 PST 2024
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 11676da80874787a47856da87911234837c53f06 43385b7341ef6d3bd5f689670ca407f6e5f91949 --extensions h,cpp -- clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h clang/include/clang/Analysis/FlowSensitive/DataflowLattice.h clang/include/clang/Analysis/FlowSensitive/Logger.h clang/include/clang/Analysis/FlowSensitive/MapLattice.h clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h clang/include/clang/Analysis/FlowSensitive/NoopLattice.h clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h clang/lib/Analysis/FlowSensitive/Arena.cpp clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp clang/lib/Analysis/FlowSensitive/Logger.cpp clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp clang/lib/Analysis/FlowSensitive/Transfer.cpp clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp clang/unittests/Analysis/FlowSensitive/TestingSupport.h clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
index 8dd9cd546b..b8d03f04d7 100644
--- a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
+++ b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
@@ -154,11 +154,12 @@ joinConstMethodMap(
} // namespace internal
template <typename Base>
-LatticeEffect CachedConstAccessorsLattice<Base>::join(
- const DataflowLattice &Other) {
+LatticeEffect
+CachedConstAccessorsLattice<Base>::join(const DataflowLattice &Other) {
LatticeEffect Effect = Base::join(Other);
- const auto &OtherL = llvm::cast<const CachedConstAccessorsLattice<Base>>(Other);
+ const auto &OtherL =
+ llvm::cast<const CachedConstAccessorsLattice<Base>>(Other);
// For simplicity, we only retain values that are identical, but not ones that
// are non-identical but equivalent. This is likely to be sufficient in
diff --git a/clang/include/clang/Analysis/FlowSensitive/Logger.h b/clang/include/clang/Analysis/FlowSensitive/Logger.h
index 34d5865f6b..32719b9170 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Logger.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Logger.h
@@ -40,8 +40,7 @@ public:
/// Called by the framework as we start analyzing a new function or statement.
/// Forms a pair with endAnalysis().
- virtual void beginAnalysis(const AdornedCFG &, DataflowAnalysis &) {
- }
+ virtual void beginAnalysis(const AdornedCFG &, DataflowAnalysis &) {}
virtual void endAnalysis() {}
// At any time during the analysis, we're computing the state for some target
diff --git a/clang/include/clang/Analysis/FlowSensitive/MapLattice.h b/clang/include/clang/Analysis/FlowSensitive/MapLattice.h
index 0321d55b98..ec6e97920e 100644
--- a/clang/include/clang/Analysis/FlowSensitive/MapLattice.h
+++ b/clang/include/clang/Analysis/FlowSensitive/MapLattice.h
@@ -93,7 +93,6 @@ public:
mapped_type &operator[](const key_type &K) { return C[K]; }
-
DataflowLatticePtr clone() override {
return std::make_unique<MapLattice>(*this);
}
diff --git a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
index 654c76efec..d94599ee37 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
@@ -59,8 +59,7 @@ struct UncheckedOptionalAccessLattice
/// Dataflow analysis that models whether optionals hold values or not.
///
/// Models the `std::optional`, `absl::optional`, and `base::Optional` types.
-class UncheckedOptionalAccessModel
- : public DataflowAnalysis {
+class UncheckedOptionalAccessModel : public DataflowAnalysis {
public:
using Lattice = UncheckedOptionalAccessLattice;
diff --git a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
index dbad9d334e..43f2dc8a04 100644
--- a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
@@ -85,37 +85,39 @@ class DataflowAnalysis : public Environment::ValueModel {
DataflowAnalysisOptions Options;
public:
- explicit DataflowAnalysis(ASTContext &Context) : Context(Context) {}
-
- explicit DataflowAnalysis(ASTContext &Context, DataflowAnalysisOptions Options)
- : Context(Context), Options(Options) {}
-
- /// Returns the `ASTContext` that is used by the analysis.
- ASTContext &getASTContext() { return Context; }
-
- /// Returns a lattice element that models the initial state of a
- /// basic block.
- virtual DataflowLatticePtr initialElement() = 0;
-
- /// Applies the analysis transfer function for a given control flow graph
- /// element and type-erased lattice element. The derived type of Lattice will
- /// always match the type of the lattice returned by `initialElement`.
- virtual void transfer(const CFGElement &, DataflowLattice &Lattice,
- Environment &) = 0;
-
- /// Applies the analysis transfer function for a given edge from a CFG block
- /// of a conditional statement. This method is optional and so the default
- /// implementation is a no-op.
- /// @param Stmt The condition which is responsible for the split in the CFG.
- /// @param Branch True if the edge goes to the basic block where the
- /// condition is true.
- virtual void transferBranch(bool Branch, const Stmt &Stmt, DataflowLattice &,
- Environment &) {};
-
- /// If the built-in model is enabled, returns the options to be passed to
- /// them. Otherwise returns empty.
- const std::optional<DataflowAnalysisContext::Options> &builtinOptions() const {
- return Options.BuiltinOpts;
+ explicit DataflowAnalysis(ASTContext &Context) : Context(Context) {}
+
+ explicit DataflowAnalysis(ASTContext &Context,
+ DataflowAnalysisOptions Options)
+ : Context(Context), Options(Options) {}
+
+ /// Returns the `ASTContext` that is used by the analysis.
+ ASTContext &getASTContext() { return Context; }
+
+ /// Returns a lattice element that models the initial state of a
+ /// basic block.
+ virtual DataflowLatticePtr initialElement() = 0;
+
+ /// Applies the analysis transfer function for a given control flow graph
+ /// element and type-erased lattice element. The derived type of Lattice will
+ /// always match the type of the lattice returned by `initialElement`.
+ virtual void transfer(const CFGElement &, DataflowLattice &Lattice,
+ Environment &) = 0;
+
+ /// Applies the analysis transfer function for a given edge from a CFG block
+ /// of a conditional statement. This method is optional and so the default
+ /// implementation is a no-op.
+ /// @param Stmt The condition which is responsible for the split in the CFG.
+ /// @param Branch True if the edge goes to the basic block where the
+ /// condition is true.
+ virtual void transferBranch(bool Branch, const Stmt &Stmt, DataflowLattice &,
+ Environment &) {};
+
+ /// If the built-in model is enabled, returns the options to be passed to
+ /// them. Otherwise returns empty.
+ const std::optional<DataflowAnalysisContext::Options> &
+ builtinOptions() const {
+ return Options.BuiltinOpts;
}
};
diff --git a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
index a7f2e4900b..47dece3ae2 100644
--- a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
@@ -67,12 +67,8 @@ struct ValueLattice : public llvm::RTTIExtends<ValueLattice, DataflowLattice> {
explicit ValueLattice(int64_t V) : State(ValueState::Defined), Value(V) {}
explicit ValueLattice(ValueState S) : State(S), Value(std::nullopt) {}
- static ValueLattice bottom() {
- return ValueLattice(ValueState::Undefined);
- }
- static ValueLattice top() {
- return ValueLattice(ValueState::Defined);
- }
+ static ValueLattice bottom() { return ValueLattice(ValueState::Undefined); }
+ static ValueLattice top() { return ValueLattice(ValueState::Defined); }
friend bool operator==(const ValueLattice &Lhs, const ValueLattice &Rhs) {
return Lhs.State == Rhs.State && Lhs.Value == Rhs.Value;
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
index 651541923f..e9da152efb 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
@@ -57,7 +57,8 @@ public:
std::unique_ptr<DataflowLattice> initialElement() override {
return std::make_unique<Lattice>(TestLattice::bottom());
}
- void transfer(const CFGElement &, DataflowLattice &, Environment &) override {}
+ void transfer(const CFGElement &, DataflowLattice &, Environment &) override {
+ }
void transferBranch(bool Branch, const Stmt &S, DataflowLattice &L,
Environment &Env) override {
llvm::cast<Lattice>(L).Branch = Branch;
diff --git a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index ce0af893a8..8d5b82fd95 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -728,8 +728,7 @@ TEST_F(NoreturnDestructorTest, ConditionalOperatorNestedBranchReturns) {
}
// Models an analysis that uses flow conditions.
-class SpecialBoolAnalysis final
- : public DataflowAnalysis {
+class SpecialBoolAnalysis final : public DataflowAnalysis {
public:
using Lattice = NoopLattice;
``````````
</details>
https://github.com/llvm/llvm-project/pull/120967
More information about the cfe-commits
mailing list