LLVM 9.0.1 IR issue

Hi everyone!

I'm experimenting with LLVM intermediate representation and I've found that IR produced with cargo rustc --release -- --emit=llvm-ir can not be compiled with llc from the LLVM 9.0.1 toolset when using rust >=1.45.0

Steps to reproduce:

  1. cargo init --bin hello-world
  2. cd hello-world
  3. echo "1.45.0" > rust-toolchain
  4. cargo rustc --release -- --emit=llvm-ir
  5. /path/to/llvm9/bin/llc target/release/deps/hello_world-*.ll

I'm getting the following error:

/opt/llvm90/bin/llc: error: /opt/llvm90/bin/llc: target/release/deps/hello_world-cc4e086f6fa63c22.ll:99:22: error: expected ')' at end of argument list
define i32 @main(i32 %0, i8** %1) unnamed_addr #4 {
                     ^

When using rust 1.44.0 or below, everything compiles smoothly. I believe that %# notation in function arguments has been added to LLVM since version 10, but I'm not sure about that.

So, the question is, has rustc dropped support of LLVM 9.0.1 in 1.45.0? I can't find any notice on that though. Or am I doing something wrong?..
If not, can I somehow force rustc to produce IR that is compatible with LLVM 9.0.1?

P.S.
Unfortunately, using LLVM 10 is not an option for my experiments.

Thanks!!

Rust 1.45.0 uses LLVM 10, but LLVM 9 is still supported. You need to manually build rustc against the LLVM version you want to use though.

2 Likes

Thanks @jschievink! Will it change "automatically" the IR generated by the rustc?

The IR is printed by LLVM, so if you change its version, the IR output will change accordingly

Great, thanks! I was under the wrong impression that IR is somehow generated directly by the rustc.

It is, but rustc only constructs the in-memory representation of the IR. LLVM is what prints that representation as text.

1 Like

There are sometimes differences in how we have to generate that in-memory IR, but we do that dynamically to match the running LLVM version.

1 Like