[clang][dataflow] Modify `transfer` in `DataflowModel` to take `CFGElement` as input...
authorWei Yi Tee <wyt@google.com>
Mon, 19 Sep 2022 18:13:50 +0000 (18:13 +0000)
committerWei Yi Tee <wyt@google.com>
Mon, 19 Sep 2022 18:40:29 +0000 (18:40 +0000)
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

clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp

index 098c13c..cbd20ad 100644 (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
index 93c427b..e65f40b 100644 (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.
index 3910847..f457964 100644 (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)) {
index 5743669..1e149db 100644 (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: