From 9b8be8a0dc11bdbcad507329f1b3f24613824e17 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 14 Jul 2026 08:20:53 -0400 Subject: [PATCH 1/4] 1.97.1 release * Bump version * Re-import release notes and add 1.97.1 notes --- RELEASES.md | 20 ++++++++++++++++---- src/version | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index ecc5f5adab06d..81310c20c5ef9 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,13 @@ +Version 1.97.1 (2026-07-16) +========================== + + + +- [rustc: Fix miscompilation in LLVM optimization](https://github.com/rust-lang/rust/issues/159035) + This backports an LLVM submodule bump to include the LLVM-side fix and a + revert of the rustc change that is one known trigger for the bug. The rustc + side revert should not be strictly necessary but is done out of abundance of caution. + Version 1.97.0 (2026-07-09) ========================== @@ -35,14 +45,14 @@ Stabilized APIs - [`Send for std::fs::File` on UEFI](https://github.com/rust-lang/rust/pull/154003) - [`<{integer}>::isolate_highest_one`](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.isolate_highest_one) - [`<{integer}>::isolate_lowest_one`](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.isolate_lowest_one) +- [`<{integer}>::highest_one`](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.highest_one) +- [`<{integer}>::lowest_one`](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.lowest_one) +- [`<{integer}>::bit_width`](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.bit_width) - [`NonZero<{integer}>::isolate_highest_one`](https://doc.rust-lang.org/stable/std/num/struct.NonZero.html#method.isolate_highest_one) - [`NonZero<{integer}>::isolate_lowest_one`](https://doc.rust-lang.org/stable/std/num/struct.NonZero.html#method.isolate_lowest_one) -- [`<{integer}>::bit_width`](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.bit_width) -- [`<{integer}>::lowest_one`](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.lowest_one) -- [`<{integer}>::highest_one`](https://doc.rust-lang.org/stable/std/primitive.u32.html#method.highest_one) -- [`NonZero<{integer}>::bit_width`](https://doc.rust-lang.org/stable/std/num/struct.NonZero.html#method.bit_width) - [`NonZero<{integer}>::highest_one`](https://doc.rust-lang.org/stable/std/num/struct.NonZero.html#method.highest_one) - [`NonZero<{integer}>::lowest_one`](https://doc.rust-lang.org/stable/std/num/struct.NonZero.html#method.lowest_one) +- [`NonZero<{integer}>::bit_width`](https://doc.rust-lang.org/stable/std/num/struct.NonZero.html#method.bit_width) These previously stable APIs are now stable in const contexts: @@ -66,6 +76,8 @@ Rustdoc ----- - [Stabilize `--emit` flag](https://github.com/rust-lang/rust/pull/146220) - [Stabilize `--remap-path-prefix`](https://github.com/rust-lang/rust/pull/155307) + + Compatibility Notes diff --git a/src/version b/src/version index acbb747ac540f..4d00f49dadcc8 100644 --- a/src/version +++ b/src/version @@ -1 +1 @@ -1.97.0 +1.97.1 From eabe5e433d90c301e0c7bbfa701582e498a9ea0b Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Thu, 9 Jul 2026 17:59:32 -0700 Subject: [PATCH 2/4] Add regression test for enum miscompilation --- tests/ui/codegen/dont-miscompile-enums.rs | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/ui/codegen/dont-miscompile-enums.rs diff --git a/tests/ui/codegen/dont-miscompile-enums.rs b/tests/ui/codegen/dont-miscompile-enums.rs new file mode 100644 index 0000000000000..f31a70bf754d6 --- /dev/null +++ b/tests/ui/codegen/dont-miscompile-enums.rs @@ -0,0 +1,43 @@ +//@ run-pass + +// Bad regression test for https://github.com/rust-lang/rust/issues/159035 +// This should probably be replaced with a codegen test, though that might need to be in LLVM, +// as it seems that the miscompilation may occur on correct IR misoptimized by SimplifyCFG. + +#![allow(dead_code)] + +enum Inner { + A(u32), + B(u32), +} +struct Big { + _pad: u64, + inner: Inner, +} +struct Small { + a: u16, + b: u16, + _f: fn(), +} +enum Checksum { + X(Big), + Y(Small), +} +impl Checksum { + fn finalize(self) -> u32 { + match self { + Checksum::X(h) => match h.inner { + Inner::A(s) => s, + Inner::B(s) => s, + }, + Checksum::Y(s) => (u32::from(s.b) << 16) | u32::from(s.a), + } + } +} +#[inline(never)] +fn run(c: Option) -> Option { + c.map(|c| c.finalize()) +} +fn main() { + println!("{:?}", run(std::hint::black_box(None))); +} From e641feae5ee2a3c393d78546fc056c60c9e623fa Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Thu, 9 Jul 2026 17:55:24 -0700 Subject: [PATCH 3/4] Revert "Only exclude the 155473 change for 1-byte bool-likes" This reverts commit 569ad9986443503f23c534d6c4d9f34e823f5c69. The PR widened the effect of this from enums with the 0..=1 range to those with any range if they had more than 1 byte. Unfortunately, our LLVMIR now incurs miscompilations, so revert until we find a better fix. --- compiler/rustc_abi/src/lib.rs | 3 +-- tests/codegen-llvm/function-arguments.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 5e1a95d620f2a..47ab63a899d08 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -2063,8 +2063,7 @@ impl Niche { let distance_end_zero = max_value - v.end; // FIXME: this ought to work for `bool` too, but that seems to be hitting a miscompilation // - let is_bool = size.bytes() == 1 && v == WrappingRange { start: 0, end: 1 }; - if count == 1 && !is_bool { + if count == 1 && v != (WrappingRange { start: 0, end: 1 }) { // We only need one, so just pick the one closest to zero. // Not only does that obviously use zero if it's possible, but it also // simplifies testing things like `Option`, since looking for `-1` diff --git a/tests/codegen-llvm/function-arguments.rs b/tests/codegen-llvm/function-arguments.rs index 6eab9a58b47ad..667e4f79df8c5 100644 --- a/tests/codegen-llvm/function-arguments.rs +++ b/tests/codegen-llvm/function-arguments.rs @@ -282,7 +282,7 @@ pub fn return_slice(x: &[u16]) -> &[u16] { x } -// CHECK: { i16, i16 } @enum_id_1(i16 noundef{{( range\(i16 -1, 2\))?}} %x.0, i16 %x.1) +// CHECK: { i16, i16 } @enum_id_1(i16 noundef{{( range\(i16 0, 3\))?}} %x.0, i16 %x.1) #[no_mangle] pub fn enum_id_1(x: Option>) -> Option> { x From 979b2d35681d832e25e09ae839be320755d9cf42 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Tue, 14 Jul 2026 08:32:20 -0400 Subject: [PATCH 4/4] Backport fix for 159035 This backports more than just the small fix as the original base has moved on main too. --- src/llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm-project b/src/llvm-project index 08c84e69a84d9..dcc3606807c98 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 08c84e69a84d95936296dfcab0e38b34100725d5 +Subproject commit dcc3606807c989700e0ac1cac18c31741bcd40d9