[clang] 6b991ba - [clang][dataflow] Change `transfer` API to take a reference.
Yitzhak Mandelbaum via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 15 07:38:00 PST 2023
Author: Yitzhak Mandelbaum
Date: 2023-02-15T15:37:21Z
New Revision: 6b991ba486b64f09e7d90ebc1fc2118ab48c8bff
URL: https://github.com/llvm/llvm-project/commit/6b991ba486b64f09e7d90ebc1fc2118ab48c8bff
DIFF: https://github.com/llvm/llvm-project/commit/6b991ba486b64f09e7d90ebc1fc2118ab48c8bff.diff
LOG: [clang][dataflow] Change `transfer` API to take a reference.
The provided `CFGElement` is never null, so a reference is a more precise type.
Differential Revision: https://reviews.llvm.org/D143920
Added:
Modified:
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index d7ca721246757..3be29cfed0a9c 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -41,7 +41,7 @@ namespace dataflow {
/// must provide the following public members:
/// * `LatticeT initialElement()` - returns a lattice element that models the
/// initial state of a basic block;
-/// * `void transfer(const CFGElement *, LatticeT &, Environment &)` - applies
+/// * `void transfer(const CFGElement &, LatticeT &, Environment &)` - applies
/// the analysis transfer function for a given CFG element and lattice
/// element.
///
@@ -122,8 +122,7 @@ class DataflowAnalysis : public TypeErasedDataflowAnalysis {
void transferTypeErased(const CFGElement &Element, TypeErasedLattice &E,
Environment &Env) final {
Lattice &L = llvm::any_cast<Lattice &>(E.Value);
- // FIXME: change the contract of `transfer` to take a reference.
- static_cast<Derived *>(this)->transfer(&Element, L, Env);
+ static_cast<Derived *>(this)->transfer(Element, L, Env);
}
void transferBranchTypeErased(bool Branch, const Stmt *Stmt,
@@ -239,7 +238,7 @@ runDataflowAnalysis(
class DataflowModel : public Environment::ValueModel {
public:
/// Return value indicates whether the model processed the `Element`.
- virtual bool transfer(const CFGElement *Element, Environment &Env) = 0;
+ virtual bool transfer(const CFGElement &Element, Environment &Env) = 0;
};
} // namespace dataflow
diff --git a/clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h b/clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
index e65f40b0b726e..b4315e41d79fa 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
@@ -13,7 +13,6 @@
#define CLANG_ANALYSIS_FLOWSENSITIVE_MODELS_CHROMIUMCHECKMODEL_H
#include "clang/AST/DeclCXX.h"
-#include "clang/AST/Stmt.h"
#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
#include "llvm/ADT/DenseSet.h"
@@ -26,7 +25,7 @@ namespace dataflow {
class ChromiumCheckModel : public DataflowModel {
public:
ChromiumCheckModel() = default;
- bool transfer(const CFGElement *Element, Environment &Env) override;
+ bool transfer(const CFGElement &Element, Environment &Env) override;
private:
/// Declarations for `::logging::CheckError::.*Check`, lazily initialized.
diff --git a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
index 2d52ee5fc846d..23dfdd49e94d9 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
@@ -52,7 +52,7 @@ class UncheckedOptionalAccessModel
static NoopLattice initialElement() { return {}; }
- void transfer(const CFGElement *Elt, NoopLattice &L, Environment &Env);
+ void transfer(const CFGElement &Elt, NoopLattice &L, Environment &Env);
ComparisonResult compare(QualType Type, const Value &Val1,
const Environment &Env1, const Value &Val2,
diff --git a/clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h b/clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h
index bf27ec3a58ddb..e28a7f902faf1 100644
--- a/clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h
@@ -38,7 +38,7 @@ class NoopAnalysis : public DataflowAnalysis<NoopAnalysis, NoopLattice> {
static NoopLattice initialElement() { return {}; }
- void transfer(const CFGElement *E, NoopLattice &L, Environment &Env) {}
+ void transfer(const CFGElement &E, NoopLattice &L, Environment &Env) {}
};
} // namespace dataflow
diff --git a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
index d69adfad396d1..e012b13400bce 100644
--- a/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
@@ -104,6 +104,7 @@ class TypeErasedDataflowAnalysis : public Environment::ValueModel {
/// @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.
+ // FIXME: Change `Stmt` argument to a reference.
virtual void transferBranchTypeErased(bool Branch, const Stmt *,
TypeErasedLattice &, Environment &) = 0;
diff --git a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
index f457964fb1324..969883874052b 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
@@ -50,8 +50,8 @@ bool isCheckLikeMethod(llvm::SmallDenseSet<const CXXMethodDecl *> &CheckDecls,
return CheckDecls.contains(&D);
}
-bool ChromiumCheckModel::transfer(const CFGElement *Element, Environment &Env) {
- auto CS = Element->getAs<CFGStmt>();
+bool ChromiumCheckModel::transfer(const CFGElement &Element, Environment &Env) {
+ auto CS = Element.getAs<CFGStmt>();
if (!CS)
return false;
auto Stmt = CS->getStmt();
diff --git a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index ef34492f7d851..aebe326b024f2 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -832,10 +832,10 @@ UncheckedOptionalAccessModel::UncheckedOptionalAccessModel(ASTContext &Ctx)
: DataflowAnalysis<UncheckedOptionalAccessModel, NoopLattice>(Ctx),
TransferMatchSwitch(buildTransferMatchSwitch()) {}
-void UncheckedOptionalAccessModel::transfer(const CFGElement *Elt,
+void UncheckedOptionalAccessModel::transfer(const CFGElement &Elt,
NoopLattice &L, Environment &Env) {
LatticeTransferState State(L, Env);
- TransferMatchSwitch(*Elt, getASTContext(), State);
+ TransferMatchSwitch(Elt, getASTContext(), State);
}
ComparisonResult UncheckedOptionalAccessModel::compare(
diff --git a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
index 1e149db9b44e7..86feca486ec7c 100644
--- a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
@@ -118,7 +118,7 @@ class ModelAdaptorAnalysis
static NoopLattice initialElement() { return NoopLattice(); }
- void transfer(const CFGElement *E, NoopLattice &, Environment &Env) {
+ void transfer(const CFGElement &E, NoopLattice &, Environment &Env) {
M.transfer(E, Env);
}
diff --git a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
index 9cfbe45119c3f..bc51b5c59d19f 100644
--- a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
@@ -133,9 +133,9 @@ class ConstantPropagationAnalysis
return ConstantPropagationLattice::bottom();
}
- void transfer(const CFGElement *E, ConstantPropagationLattice &Vars,
+ void transfer(const CFGElement &E, ConstantPropagationLattice &Vars,
Environment &Env) {
- auto CS = E->getAs<CFGStmt>();
+ auto CS = E.getAs<CFGStmt>();
if (!CS)
return;
auto S = CS->getStmt();
diff --git a/clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp b/clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
index 7f58d5f2f2599..405d5b217c0be 100644
--- a/clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
@@ -330,9 +330,9 @@ class SignPropagationAnalysis
static NoopLattice initialElement() { return {}; }
- void transfer(const CFGElement *Elt, NoopLattice &L, Environment &Env) {
+ void transfer(const CFGElement &Elt, NoopLattice &L, Environment &Env) {
LatticeTransferState State(L, Env);
- TransferMatchSwitch(*Elt, getASTContext(), State);
+ TransferMatchSwitch(Elt, getASTContext(), State);
}
bool merge(QualType Type, const Value &Val1, const Environment &Env1,
const Value &Val2, const Environment &Env2, Value &MergedVal,
diff --git a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
index e0c1dcf4f5ddf..4b6f575641c5c 100644
--- a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
@@ -124,9 +124,9 @@ class ConstantPropagationAnalysis
return ConstantPropagationLattice::bottom();
}
- void transfer(const CFGElement *E, ConstantPropagationLattice &Element,
+ void transfer(const CFGElement &E, ConstantPropagationLattice &Element,
Environment &Env) {
- auto CS = E->getAs<CFGStmt>();
+ auto CS = E.getAs<CFGStmt>();
if (!CS)
return;
auto S = CS->getStmt();
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
index 6633f9d070f03..ef78131dd72a3 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
@@ -44,7 +44,7 @@ class TestPropagationAnalysis
explicit TestPropagationAnalysis(ASTContext &Context)
: DataflowAnalysis<TestPropagationAnalysis, TestLattice>(Context) {}
static TestLattice initialElement() { return TestLattice::bottom(); }
- void transfer(const CFGElement *, TestLattice &, Environment &) {}
+ void transfer(const CFGElement &, TestLattice &, Environment &) {}
void transferBranch(bool Branch, const Stmt *S, TestLattice &L,
Environment &Env) {
L.Branch = Branch;
diff --git a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index 0b0c77558df92..89f53ccdbfa2f 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -112,7 +112,7 @@ class NonConvergingAnalysis
static NonConvergingLattice initialElement() { return {0}; }
- void transfer(const CFGElement *, NonConvergingLattice &E, Environment &) {
+ void transfer(const CFGElement &, NonConvergingLattice &E, Environment &) {
++E.State;
}
};
@@ -194,8 +194,8 @@ class FunctionCallAnalysis
static FunctionCallLattice initialElement() { return {}; }
- void transfer(const CFGElement *Elt, FunctionCallLattice &E, Environment &) {
- auto CS = Elt->getAs<CFGStmt>();
+ void transfer(const CFGElement &Elt, FunctionCallLattice &E, Environment &) {
+ auto CS = Elt.getAs<CFGStmt>();
if (!CS)
return;
const auto *S = CS->getStmt();
@@ -350,8 +350,8 @@ class SpecialBoolAnalysis final
static NoopLattice initialElement() { return {}; }
- void transfer(const CFGElement *Elt, NoopLattice &, Environment &Env) {
- auto CS = Elt->getAs<CFGStmt>();
+ void transfer(const CFGElement &Elt, NoopLattice &, Environment &Env) {
+ auto CS = Elt.getAs<CFGStmt>();
if (!CS)
return;
const auto *S = CS->getStmt();
@@ -508,8 +508,8 @@ class OptionalIntAnalysis final
static NoopLattice initialElement() { return {}; }
- void transfer(const CFGElement *Elt, NoopLattice &, Environment &Env) {
- auto CS = Elt->getAs<CFGStmt>();
+ void transfer(const CFGElement &Elt, NoopLattice &, Environment &Env) {
+ auto CS = Elt.getAs<CFGStmt>();
if (!CS)
return;
const Stmt *S = CS->getStmt();
@@ -1202,8 +1202,8 @@ class TopAnalysis final : public DataflowAnalysis<TopAnalysis, NoopLattice> {
static NoopLattice initialElement() { return {}; }
- void transfer(const CFGElement *Elt, NoopLattice &, Environment &Env) {
- auto CS = Elt->getAs<CFGStmt>();
+ void transfer(const CFGElement &Elt, NoopLattice &, Environment &Env) {
+ auto CS = Elt.getAs<CFGStmt>();
if (!CS)
return;
const Stmt *S = CS->getStmt();
More information about the cfe-commits
mailing list