[cfe-dev] C++ analysis with Clang?

Manuel Klimek klimek at google.com
Mon Jun 4 12:40:09 PDT 2012

On Sat, Jun 2, 2012 at 3:36 AM, Karl Mazurak <mazurak at cs.wisc.edu> wrote:

> Hi all -
> Our group is considering using Clang for some program analysis,
> primarily aimed at bug-hunting.  We're targeting C++, which I understand
> means the static analyzer isn't an option just yet, but it looks like
> there's still plenty there that could be useful - so much that I'm not
> sure what to start experimenting with.

There are basically 2 different ways to go here, depending on what you're
- finding single-TU analyzable bugs at compile: you want clang plugins, and
just run that as part of your normal build - if it's not very project
specific, consider contributing warnings to clang instead
- finding cross-TU analyzable bugs; you'll have a hard time doing that at
compile time, as clang is inherently TU-focused; for cross-TU stuff you'll
need to go through a TU independent layer; if you're after this, you can
either use LibClang or the Tooling infrastructure depending on how much
control over the AST you want (for a more in-depth comparison see

> The plugin tutorial uses a PluginASTAction and links to an example with
> a RecursiveASTVisitor, but of course we'd like to avoid reinventing the
> wheel (at coding time or at run time) as much as possible.  For
> instance, are CFGs pre-constructed somewhere?  Does the dataflow
> framework in Analysis/FlowSensitive work with C++?  Is this Sema of any
> use outside the path-sensitive analyzer?  And is there anything in Clang
> that could be useful in aggregating results together in whole program
> analysis?

I can only answer the last of your questions:
No, not to my knowledge. But we've not needed that so far - what we do is
outputting strings of (key, value) pairs from the analysis and later fold
those via an outside script; you can use python or somesuch for the
post-processing (we happen to use the MapReduce framework :)


> Thanks!
> --
> Karl
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120604/6f9531ee/attachment.html>

More information about the cfe-dev mailing list