Code Transformations and using llvm with clang

Hello list,

I am new to LLVM and have very limited knowledge on clang so I would to ask some questions.

1st question: Is there anyway to use the clang uninitialized variable detection analysis with a llvm pass? 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?

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?

An example of what I m trying to do is this:

int foo(int y){
int x = 10;

return x;
}

and I would like to transform it to:

int foo(int y){
int x;
monitor (&x);

return x;
}

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

I feel like llvm has parts of what I need to use for my project and clang has some more advanced things (uninitialized variable detection) that I would have to implement otherwise in llvm so I am trying to see if there is anyway to combine some of these analysis tools.

Thanks,

George

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