[cfe-dev] Static analyser for multiple files in clang

Manuel Klimek klimek at google.com
Mon Aug 20 09:31:29 PDT 2012


On Mon, Aug 20, 2012 at 8:36 AM, Nicholas Ng <nickng at doc.ic.ac.uk> wrote:
> Hi,
>
>
> I am writing a static analyser/type checker in clang, which needs to
> follow the control flow of the source code, including going into bodies
> of functions. It is currently implemented as an ASTConsumer and used as
> a clang plugin. However, from what I understood, it works only for one
> TranslationUnit/source file for each instance of the plugin, and I
> intend to make it work for multiple source files as one single
> program/AST.
>
> So I am writing to the list to see whether anyone has tackled this
> problem before and whether there are any 'best practices' or examples
> for building static analysis tool with similar requirements?
>
> I am looking at a few possibilities:
>
> 1. Merging ASTs from each source then run the analysis on the merged AST
> 2. Start analysing a 'main' AST and if something (eg. function body) is
> missing, try search/walk other ASTs
>
> Any directions would be much appreciated!

The way we handle that (and make it scale to static analysis on many
thousand TUs) is to output the relevant data from all the TUs first,
and then reduce it in a second step. That way you can fully
parallelize the expensive part (namely parsing C++).

You can also run the same ASTConsumer over multiple TUs via the
LibTooling stuff (http://clang.llvm.org/docs/LibTooling.html) in a
single process, thus at least allowing you to share results between
the runs. It'll still get you different ASTs though (type pointers etc
will not be reusable).

Cheers,
/Manuel

>
>
> Many thanks,
> Nicholas
> --
> Nicholas Ng
> PhD Student
> Department of Computing
> Imperial College London
> E: nickng at doc.ic.ac.uk
> W: http://www.doc.ic.ac.uk/~cn06
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list