Skip to content

Commit

Permalink
[clang][dataflow] Make the type of the post visit callback consistent
Browse files Browse the repository at this point in the history
Make the types of the post visit callbacks in `transferBlock` and
`runTypeErasedDataflowAnalysis` consistent.

Differential Revision: https://reviews.llvm.org/D131014

Reviewed-by: ymandel, xazax.hun, gribozavr2
  • Loading branch information
sgatev committed Aug 3, 2022
1 parent 7e8bf0a commit c44c718
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
Expand Up @@ -59,10 +59,11 @@ analyzeFunction(const FunctionDecl &FuncDecl, ASTContext &ASTCtx) {
BlockToOutputState = dataflow::runDataflowAnalysis(
*Context, Analysis, Env,
[&ASTCtx, &Diagnoser, &Diagnostics](
const Stmt *Stmt,
const CFGStmt &Stmt,
const DataflowAnalysisState<UncheckedOptionalAccessModel::Lattice>
&State) mutable {
auto StmtDiagnostics = Diagnoser.diagnose(ASTCtx, Stmt, State.Env);
auto StmtDiagnostics =
Diagnoser.diagnose(ASTCtx, Stmt.getStmt(), State.Env);
llvm::move(StmtDiagnostics, std::back_inserter(Diagnostics));
});
if (!BlockToOutputState)
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
Expand Up @@ -125,14 +125,14 @@ llvm::Expected<std::vector<
runDataflowAnalysis(
const ControlFlowContext &CFCtx, AnalysisT &Analysis,
const Environment &InitEnv,
std::function<void(const Stmt *, const DataflowAnalysisState<
typename AnalysisT::Lattice> &)>
std::function<void(const CFGStmt &, const DataflowAnalysisState<
typename AnalysisT::Lattice> &)>
PostVisitStmt = nullptr) {
std::function<void(const Stmt *, const TypeErasedDataflowAnalysisState &)>
std::function<void(const CFGStmt &, const TypeErasedDataflowAnalysisState &)>
PostVisitStmtClosure = nullptr;
if (PostVisitStmt != nullptr) {
PostVisitStmtClosure = [&PostVisitStmt](
const Stmt *Stmt,
const CFGStmt &Stmt,
const TypeErasedDataflowAnalysisState &State) {
auto *Lattice =
llvm::any_cast<typename AnalysisT::Lattice>(&State.Lattice.Value);
Expand Down
Expand Up @@ -138,7 +138,8 @@ llvm::Expected<std::vector<llvm::Optional<TypeErasedDataflowAnalysisState>>>
runTypeErasedDataflowAnalysis(
const ControlFlowContext &CFCtx, TypeErasedDataflowAnalysis &Analysis,
const Environment &InitEnv,
std::function<void(const Stmt *, const TypeErasedDataflowAnalysisState &)>
std::function<void(const CFGStmt &,
const TypeErasedDataflowAnalysisState &)>
PostVisitStmt = nullptr);

} // namespace dataflow
Expand Down
12 changes: 5 additions & 7 deletions clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
Expand Up @@ -333,7 +333,8 @@ llvm::Expected<std::vector<llvm::Optional<TypeErasedDataflowAnalysisState>>>
runTypeErasedDataflowAnalysis(
const ControlFlowContext &CFCtx, TypeErasedDataflowAnalysis &Analysis,
const Environment &InitEnv,
std::function<void(const Stmt *, const TypeErasedDataflowAnalysisState &)>
std::function<void(const CFGStmt &,
const TypeErasedDataflowAnalysisState &)>
PostVisitStmt) {
PostOrderCFGView POV(&CFCtx.getCFG());
ForwardDataflowWorklist Worklist(CFCtx.getCFG(), &POV);
Expand Down Expand Up @@ -398,12 +399,9 @@ runTypeErasedDataflowAnalysis(
// Skip blocks that were not evaluated.
if (!BlockStates[Block->getBlockID()])
continue;
transferBlock(
CFCtx, BlockStates, *Block, InitEnv, Analysis,
[&PostVisitStmt](const clang::CFGStmt &Stmt,
const TypeErasedDataflowAnalysisState &State) {
PostVisitStmt(Stmt.getStmt(), State);
});

transferBlock(CFCtx, BlockStates, *Block, InitEnv, Analysis,
PostVisitStmt);
}
}

Expand Down
6 changes: 3 additions & 3 deletions clang/unittests/Analysis/FlowSensitive/TestingSupport.h
Expand Up @@ -76,7 +76,7 @@ llvm::Error checkDataflow(
llvm::StringRef Code,
ast_matchers::internal::Matcher<FunctionDecl> TargetFuncMatcher,
std::function<AnalysisT(ASTContext &, Environment &)> MakeAnalysis,
std::function<void(ASTContext &, const Stmt *,
std::function<void(ASTContext &, const CFGStmt &,
const TypeErasedDataflowAnalysisState &)>
PostVisitStmt,
std::function<void(AnalysisData)> VerifyResults, ArrayRef<std::string> Args,
Expand Down Expand Up @@ -112,11 +112,11 @@ llvm::Error checkDataflow(
Environment Env(DACtx, *F);
auto Analysis = MakeAnalysis(Context, Env);

std::function<void(const Stmt *, const TypeErasedDataflowAnalysisState &)>
std::function<void(const CFGStmt &, const TypeErasedDataflowAnalysisState &)>
PostVisitStmtClosure = nullptr;
if (PostVisitStmt != nullptr) {
PostVisitStmtClosure = [&PostVisitStmt, &Context](
const Stmt *Stmt,
const CFGStmt &Stmt,
const TypeErasedDataflowAnalysisState &State) {
PostVisitStmt(Context, Stmt, State);
};
Expand Down
Expand Up @@ -1245,9 +1245,10 @@ class UncheckedOptionalAccessTest
return UncheckedOptionalAccessModel(Ctx, Options);
},
[&Diagnostics, Diagnoser = UncheckedOptionalAccessDiagnoser(Options)](
ASTContext &Ctx, const Stmt *Stmt,
ASTContext &Ctx, const CFGStmt &Stmt,
const TypeErasedDataflowAnalysisState &State) mutable {
auto StmtDiagnostics = Diagnoser.diagnose(Ctx, Stmt, State.Env);
auto StmtDiagnostics =
Diagnoser.diagnose(Ctx, Stmt.getStmt(), State.Env);
llvm::move(StmtDiagnostics, std::back_inserter(Diagnostics));
},
[&Diagnostics](AnalysisData AnalysisData) {
Expand Down

0 comments on commit c44c718

Please sign in to comment.