This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Add a lattice to track source locations.
ClosedPublic

Authored by ymandel on Mar 3 2022, 4:01 AM.

Details

Summary

This patch adds a simpe lattice used to collect source loctions. An intended application is to track errors found in code during an analysis.

Diff Detail

Event Timeline

ymandel created this revision.Mar 3 2022, 4:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 4:01 AM
ymandel requested review of this revision.Mar 3 2022, 4:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 4:01 AM
sgatev accepted this revision.Mar 3 2022, 4:36 AM
sgatev added inline comments.
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h
14

Remove the last _ for consistency with the other headers.

47

Add an empty line after this member to separate it from the next?

clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
46

Call this OS? It seems to be common.

This revision is now accepted and ready to land.Mar 3 2022, 4:36 AM
sgatev added inline comments.Mar 3 2022, 6:19 AM
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h
27

Doc comments start with ///.

56

Doc comments start with ///.

57

Can you please add tests for this too?

ymandel updated this revision to Diff 412701.Mar 3 2022, 6:38 AM

Address comments

ymandel marked 5 inline comments as done.Mar 3 2022, 6:40 AM
ymandel added inline comments.
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h
57

I'm not sure what I would test, since it (intentionally) has no guaranteed API. Do you have something particular in mind? I generally avoid testing things like DebugString because we don't want users to rely on them.

xazax.hun added a comment.EditedMar 3 2022, 9:07 AM

Is there anything special about SourceLocations? I wonder whether we just want a templated PowerSet lattice and instantiate it with SourceLocations.

Is there anything special about SourceLocations? I wonder whether we just want a templated PowerSet lattice and instantiate it with SourceLocations.

Not really. Just that we use this lattice in a bunch of analyses for "unsafe access", like std::optional and absl::Statusor and (eventually) pointers. So, it seems generally useful as is. I agree that we should have core powerset lattice, its just that doing so will require a little more design effort (similar to the map lattice I added). Happy to add that as a FIXME (which we plan to start tacking with github issues soon!), if that sounds good to you.

xazax.hun accepted this revision.Mar 3 2022, 9:21 AM

Is there anything special about SourceLocations? I wonder whether we just want a templated PowerSet lattice and instantiate it with SourceLocations.

Not really. Just that we use this lattice in a bunch of analyses for "unsafe access", like std::optional and absl::Statusor and (eventually) pointers. So, it seems generally useful as is. I agree that we should have core powerset lattice, its just that doing so will require a little more design effort (similar to the map lattice I added). Happy to add that as a FIXME (which we plan to start tacking with github issues soon!), if that sounds good to you.

Sounds good, thanks!

ymandel updated this revision to Diff 412747.Mar 3 2022, 9:39 AM

added FIXME

sgatev accepted this revision.Mar 3 2022, 9:49 AM
sgatev added inline comments.
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h
57

Fair point. Let's keep it as is.

This revision was landed with ongoing or failed builds.Mar 4 2022, 9:13 AM
This revision was automatically updated to reflect the committed changes.