This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Use diagnosis API in optional checker
ClosedPublic

Authored by samestep on Jun 22 2022, 8:56 AM.

Details

Summary

Followup to D127898. This patch updates bugprone-unchecked-optional-access to use the new diagnoseCFG function instead of just looking at the exit block.

A followup to this will update the optional model itself to use a noop lattice rather than redundantly computing the diagnostics in both phases of the analysis.

Diff Detail

Event Timeline

samestep created this revision.Jun 22 2022, 8:56 AM
samestep requested review of this revision.Jun 22 2022, 8:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2022, 8:56 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
samestep updated this revision to Diff 439042.Jun 22 2022, 8:59 AM

Remove unnecessary ExitBlock code

sgatev added inline comments.Jun 22 2022, 9:10 AM
clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
58

I think the typed API should still be preferred unless we make a call to drop it. The type-erased API is only used internally in the dataflow analysis framework. I suggest taking a DataflowAnalysisState<Lattice> in diagnoseCFG instead of TypeErasedDataflowAnalysisState for now. Would that work?

samestep added inline comments.Jun 22 2022, 9:14 AM
clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
58

That wouldn't be easy to do, because checkDataflow in TestingSupport.h uses the type-erased API. But if you know how to change that to use the non-type-erased API, then we could probably change the signature of diagnoseCFG. I don't know how to do that, though.

samestep updated this revision to Diff 439052.Jun 22 2022, 9:16 AM
  • Merge branch 'diagnose-api' into optional-check-diagnose
samestep updated this revision to Diff 439373.Jun 23 2022, 6:26 AM
  • Merge branch 'diagnose-api' into optional-check-diagnose
samestep updated this revision to Diff 439413.Jun 23 2022, 8:27 AM
  • Merge branch 'diagnose-api' into optional-check-diagnose
samestep updated this revision to Diff 440702.Jun 28 2022, 11:17 AM
  • Merge branch 'diagnose-api' into optional-check-diagnose
  • Use the updated API
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2022, 11:17 AM
ymandel accepted this revision.Jun 28 2022, 11:24 AM

Nice!

This revision is now accepted and ready to land.Jun 28 2022, 11:24 AM
xazax.hun accepted this revision.Jun 28 2022, 11:47 AM
gribozavr2 accepted this revision.Jun 28 2022, 1:38 PM
gribozavr2 added inline comments.
clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
66

Please use the range-based llvm;:move() from llvm-project/llvm/include/llvm/ADT/STLExtras.h.

sgatev accepted this revision.Jun 28 2022, 11:41 PM
sgatev added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
126–129 ↗(On Diff #440702)
samestep marked an inline comment as done.Jun 29 2022, 12:12 PM
samestep added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
126–129 ↗(On Diff #440702)

I tried this but it doesn't seem to work; I get this error:

llvm-project/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h:130:13: error: non-const lvalue reference to type 'clang::dataflow::SourceLocationsLattice' cannot bind to a temporary of type 'clang::dataflow::SourceLocationsLattice'
      auto &Lattice =
samestep updated this revision to Diff 441117.Jun 29 2022, 12:13 PM
  • Merge branch 'diagnose-api' into optional-check-diagnose
  • Update using review comments
This revision was landed with ongoing or failed builds.Jun 29 2022, 12:20 PM
This revision was automatically updated to reflect the committed changes.