Slightly refactor and optimize the code in preparation for implementing grouping parameters for a single fix-it.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/include/clang/Analysis/Analyses/UnsafeBufferUsage.h | ||
---|---|---|
26 | Use the VariableGroupsManager class as an interface to clients. It hides the details about how groups are implemented (which may involve several containers). | |
clang/lib/Analysis/UnsafeBufferUsage.cpp | ||
1182 | To make the order of variables in every group deterministic. | |
2313 | Instead of calling fixVariable to generate fix-its for group mates, directly copying those fix-its from the FixItsForVariable container. At this point, FixItsForVariable is complete. That is, it maps every variable to its own fix-its (excluding fix-its of group mates). | |
2332 | An implementation of VariableGroupsManager: keep a unique copy of each group in Groups and use their indexes for access. Note that getGroupOfVar assumes that Var must in the map. This is guaranteed by the changed made in D155524---only "Fixables" associated to variables in the final graph(es) will stay and be fixed. The key set of the VarGrpMap is the set of variables in the final graph(es). Therefore, after the graph(es) are computed and "Fixables" are pruned, VarGrpMap is the variable domain that we will deal with. | |
2470 | Use SetVector to make order deterministic. | |
2530 | I removed this guard so that VarGrpMap is complete---it has an entry for every variable that we need to deal with later. | |
2555 | Mapping variables to group indexes instead of groups themselves to avoid copies. | |
clang/lib/Sema/AnalysisBasedWarnings.cpp | ||
2180 | Factor this procedure out to a method for easy re-use later. |
clang/lib/Analysis/UnsafeBufferUsage.cpp | ||
---|---|---|
2313 | Do you mean "including fix-its of group mates"? If not, I might have misunderstood the changes and will take a look again. | |
2555 | I think this is a really clever optimization and believe it would save a bunch of time and space in code having significant variable grouping. |
clang/lib/Analysis/UnsafeBufferUsage.cpp | ||
---|---|---|
1182 | @NoQ I had an offline discussion with @ziqingluo-90 about this and we agreed (IIRC) that I would clean up the tests since I added those regexps. I plan to create a patch as soon as this lands. Does that make sense? |
clang/lib/Analysis/UnsafeBufferUsage.cpp | ||
---|---|---|
1182 | Yes sure SGTM! |
clang/lib/Analysis/UnsafeBufferUsage.cpp | ||
---|---|---|
2313 | No. The construction of FinalFixItsForVariable reads FixItsForVariable. Maybe I should have better names for these two variables. |
LGTM!
clang/lib/Analysis/UnsafeBufferUsage.cpp | ||
---|---|---|
2313 | Ah! That makes sense, I misread the FixItsForVariable as FinalFixItsForVariable in you comment. Thank you for explaining. |
Use the VariableGroupsManager class as an interface to clients. It hides the details about how groups are implemented (which may involve several containers).