[cfe-dev] Code Transformations and using llvm with clang

Eli Friedman eli.friedman at gmail.com
Thu Mar 12 23:03:36 PDT 2009


On Thu, Mar 12, 2009 at 10:37 PM, George Patsilaras
<gpatsilaras at hotmail.com> wrote:
> 1st question: Is there anyway to use the clang uninitialized variable
> detection analysis with a llvm pass?

clang -> llvm is a one-way transformation; LLVM can't reason about
clang-level stuff.  You could possibly insert annotations into the
generated code, but the clang code generator isn't oriented around
that.

> If not, can I write a clang
> transformation that takes some C code and outputs C code in order to be able
> to use some of llvm's existing passes?

You can use the rewriter for that.  There are some working examples of
complex rewriters in the Driver directory; that said, I don't think we
have a simple example of rewriting AST-level constructs.

> 2nd question:  Part of the project I am working on is to insert a monitor
> function call in the code. Can anyone point me to an example of such a code
> transformation using clang?

Also can be done using the rewriter.

> 3rd question: Can clang use passes written for llvm (for example the
> anderson alias analysis pass)?

Basically, no: LLVM can't reason about the clang AST, and the clang
analyzer doesn't know anything about LLVM IR.

-Eli




More information about the cfe-dev mailing list