This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Add unit tests for PostOrderCFGView
AcceptedPublic

Authored by sgatev on Nov 29 2021, 9:51 AM.

Details

Summary

This adds unit tests for the PostOrderCFGView class which will be
used as part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Diff Detail

Event Timeline

sgatev created this revision.Nov 29 2021, 9:51 AM
sgatev requested review of this revision.Nov 29 2021, 9:51 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 29 2021, 9:51 AM

Looks good, but why split the test into its own directory? I see that the implementation file is in clang/lib/Analysis and, in general, the lib and unittest directories are often flatter than the corresponding include directories. Maybe just put it directly into unittests/Analysis?

I don't have strong opinions, just some small preferences, feel free to ignore them:

  • Using ASTMatchers feels a bit heavy weight for this task to me. Simply enumerating the function definitions in the TranslationUnitDecl should be sufficient for these tests.
  • The tests might be a bit too strict, but this might be by design. In fact, there are more than one (reverse) post orders traversals of the same Cfg. Do we want to bake that particular order into the tests? This makes it harder to do changes but makes sure the tests notify us about such changes. Alternatively, we could do property-based testing, and verify that the view has the fundamental property we are interested in. Namely, if we visit nodes in the right order, we always visit all the predecessors of a node first (before visiting the node itself). Property-based tests are resilient to changes in which order we pick, and they can also make it somewhat easier to write tests (we no longer need to know about basic block IDs).
clang/unittests/Analysis/Analyses/PostOrderCFGViewTest.cpp
23

We could use using namespace here.

gribozavr2 accepted this revision.Nov 29 2021, 11:46 AM
This revision is now accepted and ready to land.Nov 29 2021, 11:46 AM