This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Use `StringMap` for storing analysis states at annotated points instead of `vector<pair<string, StateT>>`.
ClosedPublic

Authored by wyt on Aug 26 2022, 2:49 PM.

Diff Detail

Event Timeline

wyt created this revision.Aug 26 2022, 2:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2022, 2:49 PM
wyt requested review of this revision.Aug 26 2022, 2:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2022, 2:49 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gribozavr2 accepted this revision.Aug 26 2022, 3:57 PM
gribozavr2 added inline comments.
clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
124
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
287–288
330–333

Could you add an assert that insert reported that it indeed inserted an element (didn't overwrite)?

387–388

Would a range-based for loop work?

for (const auto &P : AnnotationStates)

389–392

Would make_pair work? It allows to omit explicit template arguments.

394–396

Please use llvm::sort. You also don't need to specify the comparator, the default comparator for strings is exactly the same.

This revision is now accepted and ready to land.Aug 26 2022, 3:57 PM
wyt updated this revision to Diff 456308.Aug 29 2022, 4:55 AM
wyt marked 6 inline comments as done.

Address comments.

clang/unittests/Analysis/FlowSensitive/TestingSupport.h
394–396

Used llvm::sort.

The default comparator for pairs also tries to compare the second field which is undefined for DataflowAnalysisState. And considering that annotations are unique here, it should be sufficient to just compare the strings here - hence the specified comparator that just checks the first of the pair.

gribozavr2 accepted this revision.Aug 29 2022, 5:21 AM
gribozavr2 added inline comments.
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
332

Please add (void)InsertSuccess; to silence an "unused variable" warning in release builds.

wyt updated this revision to Diff 456323.Aug 29 2022, 5:44 AM
wyt marked an inline comment as done.

Address comment.

gribozavr2 accepted this revision.Aug 29 2022, 5:47 AM
sgatev accepted this revision.Aug 30 2022, 8:45 AM
ymandel accepted this revision.Aug 30 2022, 9:02 AM
ymandel added inline comments.
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
652–653

Given that its now a map, should we use UnorderedElementsAre? Or, does StringMap guarantee ordering?

wyt added inline comments.Aug 30 2022, 9:28 AM
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
652–653

StringMap is not yet exposed to the tests in this patch.

Some ordering is currently required to correctly retrieve the states in the tests. Hence, the conversion from StringMap to vector<pair<string, StateT>> (in deprecated checkDataflow) orders the elements alphabetically on the annotations.

Future refactoring will expose StringMap in the tests, where we will then not need to maintain an ordering since we can retrieve elements by keys, we can then use UnorderedElementsAre.

wyt updated this revision to Diff 456983.Aug 31 2022, 8:59 AM

Propagate change from parent patch.

gribozavr2 accepted this revision.Aug 31 2022, 9:08 AM