compilationclangclang++llvm-clangllvm-ir

Is there a way to make Clang output LLVM IR alongside executable?


I know that you can make clang output LLVM IR using -emit-llvm option, however this makes it the sole output.

I was wondering if there is some combination of compiler options that would make clang function exactly as before, but also produce .ll files as a byproduct?

The problem I'm facing right now is a project with a very complicated cmake-based build, for which I can only change clang compile options. I want to generate llvm IR files for it, but unfortunately, if I just pass -emit-llvm, CMake fails, since it's compiler tests/sanity checks don't pass (since .ll file is generated instead of the valid executable).

Is there some way to make clang generate both exe/object and .ll files? Or somehow workaround this issue in other ways?


Solution

  • Apart from using -emit-llvm you can also use --save-temps. That will generate .ll, .ii, .o and .s files