[clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `clang/Analysis/FlowSensitive`.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133931
This commit is contained in:
Wei Yi Tee 2022-09-19 17:36:50 +00:00
parent bbef90ace4
commit cf94c52e35
5 changed files with 35 additions and 11 deletions

View File

@ -14,7 +14,7 @@
#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_NOOPANALYSIS_H
#include "clang/AST/ASTContext.h"
#include "clang/AST/Stmt.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
#include "clang/Analysis/FlowSensitive/NoopLattice.h"
@ -38,7 +38,7 @@ public:
static NoopLattice initialElement() { return {}; }
void transfer(const Stmt *S, NoopLattice &E, Environment &Env) {}
void transfer(const CFGElement *E, NoopLattice &L, Environment &Env) {}
};
} // namespace dataflow

View File

@ -11,6 +11,7 @@
#include "TestingSupport.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/FlowSensitive/NoopLattice.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/ArrayRef.h"
@ -117,8 +118,10 @@ public:
static NoopLattice initialElement() { return NoopLattice(); }
void transfer(const Stmt *S, NoopLattice &, Environment &Env) {
M.transfer(S, Env);
void transfer(const CFGElement *E, NoopLattice &, Environment &Env) {
if (auto S = E->getAs<CFGStmt>()) {
M.transfer(S->getStmt(), Env);
}
}
private:

View File

@ -19,6 +19,7 @@
#include "clang/AST/Stmt.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
@ -132,8 +133,12 @@ public:
return ConstantPropagationLattice::bottom();
}
void transfer(const Stmt *S, ConstantPropagationLattice &Vars,
void transfer(const CFGElement *E, ConstantPropagationLattice &Vars,
Environment &Env) {
auto CS = E->getAs<CFGStmt>();
if (!CS)
return;
auto S = CS->getStmt();
auto matcher =
stmt(anyOf(declStmt(hasSingleDecl(
varDecl(decl().bind(kVar), hasType(isInteger()),

View File

@ -19,10 +19,10 @@
#include "clang/AST/Stmt.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
@ -123,8 +123,12 @@ public:
return ConstantPropagationLattice::bottom();
}
void transfer(const Stmt *S, ConstantPropagationLattice &Element,
void transfer(const CFGElement *E, ConstantPropagationLattice &Element,
Environment &Env) {
auto CS = E->getAs<CFGStmt>();
if (!CS)
return;
auto S = CS->getStmt();
auto matcher = stmt(
anyOf(declStmt(hasSingleDecl(varDecl(hasType(isInteger()),
hasInitializer(expr().bind(kInit)))

View File

@ -111,7 +111,7 @@ public:
static NonConvergingLattice initialElement() { return {0}; }
void transfer(const Stmt *S, NonConvergingLattice &E, Environment &Env) {
void transfer(const CFGElement *, NonConvergingLattice &E, Environment &) {
++E.State;
}
};
@ -162,7 +162,11 @@ public:
static FunctionCallLattice initialElement() { return {}; }
void transfer(const Stmt *S, FunctionCallLattice &E, Environment &Env) {
void transfer(const CFGElement *Elt, FunctionCallLattice &E, Environment &) {
auto CS = Elt->getAs<CFGStmt>();
if (!CS)
return;
auto S = CS->getStmt();
if (auto *C = dyn_cast<CallExpr>(S)) {
if (auto *F = dyn_cast<FunctionDecl>(C->getCalleeDecl())) {
E.CalledFunctions.insert(F->getNameInfo().getAsString());
@ -314,7 +318,11 @@ public:
static NoopLattice initialElement() { return {}; }
void transfer(const Stmt *S, NoopLattice &, Environment &Env) {
void transfer(const CFGElement *Elt, NoopLattice &, Environment &Env) {
auto CS = Elt->getAs<CFGStmt>();
if (!CS)
return;
auto S = CS->getStmt();
auto SpecialBoolRecordDecl = recordDecl(hasName("SpecialBool"));
auto HasSpecialBoolType = hasType(SpecialBoolRecordDecl);
@ -466,7 +474,11 @@ public:
static NoopLattice initialElement() { return {}; }
void transfer(const Stmt *S, NoopLattice &, Environment &Env) {
void transfer(const CFGElement *Elt, NoopLattice &, Environment &Env) {
auto CS = Elt->getAs<CFGStmt>();
if (!CS)
return;
auto S = CS->getStmt();
auto OptionalIntRecordDecl = recordDecl(hasName("OptionalInt"));
auto HasOptionalIntType = hasType(OptionalIntRecordDecl);