This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Add an API for dataflow "models" -- reusable analysis components.
ClosedPublic

Authored by ymandel on Mar 16 2022, 5:56 AM.

Details

Summary

This patch introduces DataflowModel, an abstract base class for dataflow
"models": reusable analysis components that model a particular aspect of program
semantics.

Diff Detail

Event Timeline

ymandel created this revision.Mar 16 2022, 5:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 5:56 AM
ymandel requested review of this revision.Mar 16 2022, 5:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 5:56 AM
sgatev accepted this revision.Mar 16 2022, 6:43 AM
sgatev added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
148–149

Do we want to compose models that have different lattice types? Do we want to have models with no lattices that only use Environment? If we don't know this yet, I suggest replacing this with a FIXME to explore model composability at a later point when we have answers to these questions.

153

LatticeT for consistency with the code above.

This revision is now accepted and ready to land.Mar 16 2022, 6:43 AM
gribozavr2 added inline comments.Mar 16 2022, 6:57 AM
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
139

DYM "Abstract base class"?

ymandel updated this revision to Diff 415817.Mar 16 2022, 7:08 AM

Address comments.

ymandel marked 3 inline comments as done.Mar 16 2022, 7:09 AM
ymandel added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
139

Indeed.

xazax.hun added inline comments.Mar 16 2022, 8:45 AM
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
150–151

I think supporting different lattice types is a must for a good composability model. E.g., in an ideal world when we have a lattice for constant propagation of integers and we have a model for std::optional, it would be great if we could do constant propagation to/from non-empty optionals of integers.

152

The Clang Static Analyzer is full of modeling that has no dedicated state, it will just update the equivalent of an environment (e.g., adding a range to the returned values): https://github.com/llvm/llvm-project/blob/main/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp#L1208

Once we have a framework that can reason about integers, I think having something similar (or even better, somehow being able to reuse these summaries across CSA and dataflow) would be awesome.

159

In the Clang Static Analyzer the process of modelling is more conversational between the "modeling checks" and the framework. There, a return value indicates whether a particular function call was modeled and the first time someone wants to model a function call it will short circuit the whole process. This ensures that only one model will be applied.

I'm not 100% sure whether this would be the best model here. But I'd strongly suggest to add a bool return value here, because it might be useful for the framework to know in the future if some modeling was done at all (potentially skipping some default modeling based ont he return value).

ymandel updated this revision to Diff 415926.Mar 16 2022, 11:48 AM
ymandel marked an inline comment as done.

adjust API in response to comments.

ymandel edited the summary of this revision. (Show Details)Mar 16 2022, 11:52 AM
ymandel marked 3 inline comments as done.Mar 16 2022, 12:04 PM
ymandel added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
150–151

Agreed. And, fwiw, my stacked patch with a very small model does not involve the lattice. For the optional checker, we plan to split it into a model and a separate analysis which handles the lattice.

152

I removed the lattice dependency and reworded the description to focus on the environment.

xazax.hun accepted this revision.Mar 16 2022, 12:39 PM

Thanks!

This revision was landed with ongoing or failed builds.Mar 16 2022, 12:48 PM
This revision was automatically updated to reflect the committed changes.
ymandel marked 2 inline comments as done.