cdisselkoen / llvm-ir

LLVM IR in natural Rust data structures
MIT License
539 stars 45 forks source link

Support for LLVM 15? #24

Closed woodruffw closed 1 year ago

woodruffw commented 1 year ago

First of all, thank you for maintaining this crate -- it's been incredibly useful on some of our projects!

Recent versions of rustc have upgraded to LLVM 15, meaning that the IR generated by rustc can't be used with this crate's bindings by default.

Would it be possible to add LLVM 15 support to this crate? I'm happy to take a stab at it first as well, if it's easier for you to review changes 🙂

cdisselkoen commented 1 year ago

Yes, I will work on LLVM 15 support (or if you want to take the first stab, feel free). LLVM 15 has some major changes which will affect us -- in particular the move to opaque pointers, but also the removal of a number of constant expressions.

woodruffw commented 1 year ago

I'm happy to take a first stab! I can at least do the boilerplate bits, and I'm somewhat familiar with the IR-level opaque pointer changes.

woodruffw commented 1 year ago

Opened #25 as a start.

theScrabi commented 1 year ago

@woodruffw thank you for start adding support for LLVM 15. I may need this sooner or later. But because of this I'm interested: What is the current state of the LLVM 15 branch?

cdisselkoen commented 1 year ago

More discussion at #25. I've added a bunch to @woodruffw's start, and there is now an llvm-15 branch in this repo which represents the latest progress as far as I'm aware. Unfortunately there is a segfault when running our test suite on the llvm-15 branch, which I haven't had time to track down yet. (My time for this project is limited, apologies.)

another-rex commented 1 year ago

Spent some time looking into this, the segfault seems to be caused by this line:

https://github.com/cdisselkoen/llvm-ir/blob/02c844fc7eae19954bf5a43888c53306c39dc522/src/function.rs#L327

because in llvm15 now uses opaque pointers by default: https://releases.llvm.org/15.0.0/docs/ReleaseNotes.html#changes-to-the-llvm-ir

Following the migration doc I replaced that line with:

let functy = unsafe { LLVMGlobalGetValueType(func) };

which seems to work.

Most of the tests still need to be migrated, and still need to replace the LLVMGetElementType usages in types.rs.

cdisselkoen commented 1 year ago

Thanks @another-rex! I pushed this to the llvm-15 branch and am working on the remaining test failures.

cdisselkoen commented 1 year ago

Merged and also published to crates.io as 0.9.0. Tests are passing (for all LLVM versions) in --release mode; in debug mode I believe they're afflicted by #15, which is just a known-bug at this point. Thanks for everyone's contributions!

woodruffw commented 1 year ago

Thanks @cdisselkoen, and everyone else as well! I'm excited to use these changes on our tools 🙂