Clang-extdef-mapping and AST files

Hi,

I am working on implementing static analyzing into our product with CTU analysis. To do this properly we first have to dump ASTs of the sources with -emit-ast and then run clang-extdef-mapping on the source files before we can start the analysis. Both these processes can be pretty slow - so I am looking into any way to eliminate or reduce one of the steps.

I have two thoughts:

  • Maybe clang-extdef-mapping could process the AST files directly - I think that would lead to less processing since the front-end already have done most of the heavy parsing. This would also be a natural way to handle the file name in the mapping file (i.e. not have to replace .cpp with .ast).
  • Maybe we could output the mapping file from clang when creating the ast file, all parsing should already be done and we don’t have to do it again in this case.

Any thoughts on these changes? I’ll also appriciate any pointers to the API’s for opening the .ast files and getting the AST loaded?

Btw - I know about CodeChecker, and I’ll use the reporting tool of that, but I can’t integrate that into our build setup.

Hi Tobias!

I believe you could fuse/chain the different AST consuming parts.
I’m not really an ASTImporter expert, but from my point of view, each of these tools is just ASTConsumers.
There are a couple interesting files for you:

  • clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp, especially the CrossTranslationUnitContext member. HandleTopLevelDecl is AFAIK the callback provided by the ASTConsumer class which is likely important as well.
  • clang/include/clang/AST/ASTConsumer.h
  • clang/include/clang/CrossTU/CrossTranslationUnit.h
  • clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp
  • clang/include/clang/Frontend/FrontendActions.h
  • clang/include/clang/Frontend/MultiplexConsumer.h This one looks really interesting, grep for usages to see if it does the right thing. GeneratePCHAction is one example.

Btw - I know about CodeChecker, and I’ll use the reporting tool of that, but I can’t integrate that into our build setup.

Sad. What’s the blocker for that? Folks there might be interested in fixing that.