Files
rust/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1.2 KiB
Rust
Raw Normal View History

2025-06-29 17:43:51 +05:00
//! Test that opt-level=z produces correct code on Windows MSVC targets.
//!
//! A previously outdated version of LLVM caused compilation failures and
//! generated invalid code on Windows specifically with optimization level `z`.
//! The bug manifested as corrupted base pointers due to incorrect register
//! usage in the generated assembly (e.g., `popl %esi` corrupting local variables).
//! After updating to a more recent LLVM version, this test ensures that
//! compilation and execution both succeed with opt-level=z.
//!
//! Regression test for <https://github.com/rust-lang/rust/issues/45034>.
2024-06-27 11:28:50 -04:00
//@ ignore-cross-compile
// Reason: the compiled binary is executed
//@ only-windows
2025-06-29 17:43:51 +05:00
// Reason: the observed bug only occurred on Windows MSVC targets
2024-06-27 11:28:50 -04:00
//@ run-pass
//@ compile-flags: -C opt-level=z
#![feature(test)]
extern crate test;
fn foo(x: i32, y: i32) -> i64 {
(x + y) as i64
}
#[inline(never)]
fn bar() {
let _f = Box::new(0);
2025-06-29 17:43:51 +05:00
// This call used to trigger an LLVM bug in opt-level=z where the base
// pointer gets corrupted due to incorrect register allocation
2024-06-27 11:28:50 -04:00
let y: fn(i32, i32) -> i64 = test::black_box(foo);
test::black_box(y(1, 2));
}
fn main() {
bar();
}