[clang][dataflow] Modify `transfer` in `DataflowModel` to take `CFGElement` as input instead of `Stmt`.

To keep API of transfer functions consistent.

The single use of this transfer function in `ChromiumCheckModel` is also updated.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133933
This commit is contained in:
Wei Yi Tee 2022-09-19 18:13:50 +00:00
parent 1bb293f658
commit 41d52c5a7f
4 changed files with 9 additions and 7 deletions

View File

@ -193,8 +193,8 @@ runDataflowAnalysis(
/// example, a model may capture a type and its related functions.
class DataflowModel : public Environment::ValueModel {
public:
/// Return value indicates whether the model processed the `Stmt`.
virtual bool transfer(const Stmt *Stmt, Environment &Env) = 0;
/// Return value indicates whether the model processed the `Element`.
virtual bool transfer(const CFGElement *Element, Environment &Env) = 0;
};
} // namespace dataflow

View File

@ -26,7 +26,7 @@ namespace dataflow {
class ChromiumCheckModel : public DataflowModel {
public:
ChromiumCheckModel() = default;
bool transfer(const Stmt *Stmt, Environment &Env) override;
bool transfer(const CFGElement *Element, Environment &Env) override;
private:
/// Declarations for `::logging::CheckError::.*Check`, lazily initialized.

View File

@ -50,7 +50,11 @@ bool isCheckLikeMethod(llvm::SmallDenseSet<const CXXMethodDecl *> &CheckDecls,
return CheckDecls.contains(&D);
}
bool ChromiumCheckModel::transfer(const Stmt *Stmt, Environment &Env) {
bool ChromiumCheckModel::transfer(const CFGElement *Element, Environment &Env) {
auto CS = Element->getAs<CFGStmt>();
if (!CS)
return false;
auto Stmt = CS->getStmt();
if (const auto *Call = dyn_cast<CallExpr>(Stmt)) {
if (const auto *M = dyn_cast<CXXMethodDecl>(Call->getDirectCallee())) {
if (isCheckLikeMethod(CheckDecls, *M)) {

View File

@ -119,9 +119,7 @@ public:
static NoopLattice initialElement() { return NoopLattice(); }
void transfer(const CFGElement *E, NoopLattice &, Environment &Env) {
if (auto S = E->getAs<CFGStmt>()) {
M.transfer(S->getStmt(), Env);
}
M.transfer(E, Env);
}
private: