Cherry-pick of upstreamed LLVM patch that fix MIPS int shift miscompilation #156
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR is a cherry-pick of an LLVM upstream patch that fixes the MIPS miscompilation reported in rust-lang/rust#116177.
Details
The Rust git master branch miscompiles the following program for
--target mips[el]-unknown-linux-gnu
. The program comes from the above Rust issue that reported the problem.main.rs
How to reproduce
To reproduce the miscompilation for MIPS with qemu on a Debian 12 x86_64 host with the Rust git master branch, do the following:
sudo apt install qemu-user gcc-mips-linux-gnu ./x build \ --set llvm.download-ci-llvm=false \ --set llvm.targets="Mips;X86" \ --target mips-unknown-linux-gnu ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc \ --target mips-unknown-linux-gnu \ -Clinker=mips-linux-gnu-gcc \ -Ctarget-feature=+crt-static \ main.rs qemu-mips ./main
The assert should pass, but it fails with:
How to fix
The miscompilation was fixed by the LLVM PR llvm#71149. This PR cherry-picks that commit. (The upstream LLVM issue that was fixed is llvm#71142. I believe it also fixed the LLVM issue llvm#64794 even though it is still open.)
I have confirmed that the Rust test program pass after applying the cherry-picked patch to the Rust LLVM fork and building with Rust git master.