This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Add convenience function for analysing and `FunctionDecl` and diagnosing it.
ClosedPublic

Authored by ymandel on Jul 25 2023, 11:26 AM.

Details

Summary

The convenience function captures running the analysis and then collecting
diagnostics based on a Diagnoser object. This pattern is valuable to
clang-tidy checks which analyze a function at a time, though it could be more
generally useful for analysis clients.

Diff Detail

Event Timeline

ymandel created this revision.Jul 25 2023, 11:26 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: martong. · View Herald Transcript
ymandel requested review of this revision.Jul 25 2023, 11:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 11:26 AM
mboehme accepted this revision.Jul 26 2023, 12:47 AM
mboehme added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
245

Can you document what the function signature for this should be?

Also, I'm wondering if DiagnoserT even needs to be a template argument. Shouldn't the Diagnostic type be the only "variable" in the type of DiagnoserT?

Or is it that you don't want to force the caller to pass a std::function for Diagnoser? In that case, you could consider `function_ref'.

246–247
260

Does this need to be passed by non-const reference?

std::function::operator() is const, so a const reference should be fine for that. Non-const reference looks like we might be assigning to the reference (which we aren't).

262–266
268–269

Nit: Of the two variables Solver and SolverView, Solver sounds like the more canonical name and the one to "go for". Granted, this is a short function with little potential for confusion, but maybe call the unique pointer OwnedSolver (or similar) and the raw pointer Solver?

This would also eliminate the "view", which to me sounds like there's more going on than just a simple pointer.

274–289
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
95–98
101–103

I think this gives us a stronger and more explicit check for little extra effort.

This revision is now accepted and ready to land.Jul 26 2023, 12:47 AM
ymandel updated this revision to Diff 544364.Jul 26 2023, 7:37 AM
ymandel marked an inline comment as done.

address comments

ymandel updated this revision to Diff 544367.Jul 26 2023, 7:39 AM
ymandel marked 4 inline comments as done.

address comment

ymandel marked 3 inline comments as done.Jul 26 2023, 7:40 AM
ymandel added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
262–266

Nice! I wasn't aware of moveInto. Sadly, though, it doesn't work because CFC lacks a default constructor.

clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
101–103

Agreed! Great suggestion.

This revision was landed with ongoing or failed builds.Jul 26 2023, 10:12 AM
This revision was automatically updated to reflect the committed changes.
ymandel marked an inline comment as done.