A question about running Clang after LLVM passes

Hello,

Clang is used before LLVM to generate IR, and is it possible to use it in a reverse way, i.e., after running LLVM passes, we can run clang again to use LLVM pass results? If so, should I write clang functions in LLVM passes, or write LLVM pass requirements in clang?

Thank you in advance!

Padefic

Clang does not consume LLVM IR, so the answer is no. What are you trying to
do?

Eli

However, LLVM can output using the C back end … which you can then feed into Clang.

I am doing a research project. I want to run the DSA pass of LLVM, and use its result in Clang for automatic fixing. I have to use Clang because the line numbers in Clang are accurate so that I can change code accordingly, while LLVM IR seems to lose the information.

I need to access the objects created in LLVM pass to get information. Thank Bruce for your advice, could you explain more about how to output using the C backend? Does it mean to output to files, which then input into Clang? I would appreciate any reference on this problem.

In addition, it seems that by directly running command “clang -Xclang -load -Xclang mypass.so”, we can run llvm pass with clang automatically. So is it a possible way to hack into clang and do something after the LLVM-pass-related code?

Thanks!

If I understand what you’re saying, you’re building a refactoring tool that does some analysis on the program and then changes the original program’s source code. Is this correct? I do not think that this is a good idea. DSA operates on the LLVM IR. Not only will you have the headache of making DSA’s results available to Clang, but Clang “sees” the program at the Clang AST level while DSA “sees” the program at the LLVM IR level. Mapping DSA’s results from the LLVM IR back to the AST that Clang creates will be painful in the best case and will probably not work reliably at all in the worst case. I think your best option is to build a points-to analysis that works at the Clang AST level and put it into clang directly. There might be the issue of how to build an inter-procedural points-to analysis with Clang, but I think there either is a way for Clang to do that, or there is work to make Clang do that. The C Backend generates C code instead of native assembly code. The C code it generates is ugly and looks almost nothing like the original C source code that was compiled. Again, if you’re building a refactoring tool, this is probably not what you want. Regards, John Criswell

The C Backend generates C code instead of native assembly code. The C code
it generates is ugly and looks almost nothing like the original C source
code that was compiled. Again, if you're building a refactoring tool, this
is probably not what you want.

It's also been extinct for a couple of years, hasn't it?

Cheers.

Tim.

The C Backend generates C code instead of native assembly code. The C code
it generates is ugly and looks almost nothing like the original C source
code that was compiled. Again, if you're building a refactoring tool, this
is probably not what you want.

It's also been extinct for a couple of years, hasn't it?

I think someone might be in the process of bringing it back to life (or might have already done so).

In any event, even if it does exist in modern LLVM, I don't think it's the solution for Padefic's issue.

Regards,

John Criswell