This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] NFC: Legalize state manager factory injection.
ClosedPublic

Authored by NoQ on Aug 28 2018, 3:56 PM.

Details

Summary

When a checker maintains a program state trait that isn't a simple list/set/map, but is a combination of multiple lists/sets/maps (eg., a multimap - which may be implemented as a map from something to set of something), ProgramStateManager only contains the factory for the trait itself. All auxiliary lists/sets/maps need a factory to be provided by the checker, which is annoying.

So far two checkers wanted a multimap, and both decided to trick the ProgramStateManager into keeping the auxiliary factory within itself by pretending that it's some sort of trait they're interested in, but then never using this trait but only using the factory.

I decided to make it legal because this functionality seems useful and i didn't want to dig deeply into the template magic around state traits when there's already a one-liner solution, though i agree that it should be possible to implement this in a more straightforward manner.

One thing that becomes apparent once all pieces are put together is that these two checkers are in fact using the same factory, because the type that identifies it, ImmutableMap<const MemRegion *, ImmutableSet<SymbolRef>>, is the same. This situation is different from two checkers registering similar traits.

I also moved stuff around a bit because it always bothered me.

Diff Detail

Event Timeline

NoQ created this revision.Aug 28 2018, 3:56 PM
NoQ retitled this revision from [analyzer] Legalize state manager factory injection. to [analyzer] NFC: Legalize state manager factory injection..Aug 28 2018, 3:57 PM
george.karpenkov accepted this revision.Sep 5 2018, 11:22 AM
george.karpenkov added inline comments.
include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h
33

What happened to the comment about multiple TUs?
One still has to be very careful here, right?

This revision is now accepted and ready to land.Sep 5 2018, 11:22 AM
This revision was automatically updated to reflect the committed changes.
NoQ added inline comments.Oct 5 2018, 3:22 PM
include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h
33