From a38c78c4616d6032af37739fad903e842a52e290 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sun, 29 Jun 2025 17:39:08 +0500 Subject: [PATCH 1/2] moved tests --- .../mono-respects-abi-alignment.rs} | 0 .../msvc-opt-level-z-no-corruption.rs} | 0 .../auxiliary/msvc-static-data-import-lib.rs} | 0 .../msvc-static-data-import.rs} | 0 .../{multiline-comment.rs => parser/multiline-comments-basic.rs} | 0 .../ui/{multibyte.rs => parser/unicode-multibyte-chars-no-ice.rs} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{monomorphize-abi-alignment.rs => codegen/mono-respects-abi-alignment.rs} (100%) rename tests/ui/{msvc-opt-minsize.rs => codegen/msvc-opt-level-z-no-corruption.rs} (100%) rename tests/ui/{auxiliary/msvc-data-only-lib.rs => linkage-attr/auxiliary/msvc-static-data-import-lib.rs} (100%) rename tests/ui/{msvc-data-only.rs => linkage-attr/msvc-static-data-import.rs} (100%) rename tests/ui/{multiline-comment.rs => parser/multiline-comments-basic.rs} (100%) rename tests/ui/{multibyte.rs => parser/unicode-multibyte-chars-no-ice.rs} (100%) diff --git a/tests/ui/monomorphize-abi-alignment.rs b/tests/ui/codegen/mono-respects-abi-alignment.rs similarity index 100% rename from tests/ui/monomorphize-abi-alignment.rs rename to tests/ui/codegen/mono-respects-abi-alignment.rs diff --git a/tests/ui/msvc-opt-minsize.rs b/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs similarity index 100% rename from tests/ui/msvc-opt-minsize.rs rename to tests/ui/codegen/msvc-opt-level-z-no-corruption.rs diff --git a/tests/ui/auxiliary/msvc-data-only-lib.rs b/tests/ui/linkage-attr/auxiliary/msvc-static-data-import-lib.rs similarity index 100% rename from tests/ui/auxiliary/msvc-data-only-lib.rs rename to tests/ui/linkage-attr/auxiliary/msvc-static-data-import-lib.rs diff --git a/tests/ui/msvc-data-only.rs b/tests/ui/linkage-attr/msvc-static-data-import.rs similarity index 100% rename from tests/ui/msvc-data-only.rs rename to tests/ui/linkage-attr/msvc-static-data-import.rs diff --git a/tests/ui/multiline-comment.rs b/tests/ui/parser/multiline-comments-basic.rs similarity index 100% rename from tests/ui/multiline-comment.rs rename to tests/ui/parser/multiline-comments-basic.rs diff --git a/tests/ui/multibyte.rs b/tests/ui/parser/unicode-multibyte-chars-no-ice.rs similarity index 100% rename from tests/ui/multibyte.rs rename to tests/ui/parser/unicode-multibyte-chars-no-ice.rs From 1e3a2b2d4aa0ae75f9331c950b7346b1a017d4d9 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Sun, 29 Jun 2025 17:43:51 +0500 Subject: [PATCH 2/2] cleaned up some tests --- .../ui/codegen/mono-respects-abi-alignment.rs | 40 ++++++++++--------- .../codegen/msvc-opt-level-z-no-corruption.rs | 20 ++++++---- .../linkage-attr/msvc-static-data-import.rs | 16 ++++++-- tests/ui/parser/multiline-comments-basic.rs | 8 +++- .../parser/unicode-multibyte-chars-no-ice.rs | 6 ++- 5 files changed, 57 insertions(+), 33 deletions(-) diff --git a/tests/ui/codegen/mono-respects-abi-alignment.rs b/tests/ui/codegen/mono-respects-abi-alignment.rs index 62df1aca357d7..045d82b761fdc 100644 --- a/tests/ui/codegen/mono-respects-abi-alignment.rs +++ b/tests/ui/codegen/mono-respects-abi-alignment.rs @@ -1,19 +1,20 @@ -//@ run-pass +//! Test that monomorphization correctly distinguishes types with different ABI alignment. +//! +//! On x86_64-linux-gnu and similar platforms, structs get 8-byte "preferred" +//! alignment, but their "ABI" alignment (what actually matters for data layout) +//! is the largest alignment of any field. If monomorphization incorrectly uses +//! "preferred" alignment instead of "ABI" alignment, it might unify types `A` +//! and `B` even though `S` and `S` have field `t` at different offsets, +//! leading to incorrect method dispatch for `unwrap()`. -#![allow(non_upper_case_globals)] -#![allow(dead_code)] -/*! - * On x86_64-linux-gnu and possibly other platforms, structs get 8-byte "preferred" alignment, - * but their "ABI" alignment (i.e., what actually matters for data layout) is the largest alignment - * of any field. (Also, `u64` has 8-byte ABI alignment; this is not always true). - * - * On such platforms, if monomorphize uses the "preferred" alignment, then it will unify - * `A` and `B`, even though `S` and `S` have the field `t` at different offsets, - * and apply the wrong instance of the method `unwrap`. - */ +//@ run-pass #[derive(Copy, Clone)] -struct S { i:u8, t:T } +struct S { + #[allow(dead_code)] + i: u8, + t: T, +} impl S { fn unwrap(self) -> T { @@ -22,14 +23,15 @@ impl S { } #[derive(Copy, Clone, PartialEq, Debug)] -struct A((u32, u32)); +struct A((u32, u32)); // Different ABI alignment than B #[derive(Copy, Clone, PartialEq, Debug)] -struct B(u64); +struct B(u64); // Different ABI alignment than A pub fn main() { - static Ca: S = S { i: 0, t: A((13, 104)) }; - static Cb: S = S { i: 0, t: B(31337) }; - assert_eq!(Ca.unwrap(), A((13, 104))); - assert_eq!(Cb.unwrap(), B(31337)); + static CA: S = S { i: 0, t: A((13, 104)) }; + static CB: S = S { i: 0, t: B(31337) }; + + assert_eq!(CA.unwrap(), A((13, 104))); + assert_eq!(CB.unwrap(), B(31337)); } diff --git a/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs b/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs index c1be168a05dde..ba97acec82228 100644 --- a/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs +++ b/tests/ui/codegen/msvc-opt-level-z-no-corruption.rs @@ -1,12 +1,18 @@ -// A previously outdated version of LLVM caused compilation failures on Windows -// specifically with optimization level `z`. After the update to a more recent LLVM -// version, this test checks that compilation and execution both succeed. -// See https://github.com/rust-lang/rust/issues/45034 +//! 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 . //@ ignore-cross-compile // Reason: the compiled binary is executed //@ only-windows -// Reason: the observed bug only occurs on Windows +// Reason: the observed bug only occurred on Windows MSVC targets //@ run-pass //@ compile-flags: -C opt-level=z @@ -20,8 +26,8 @@ fn foo(x: i32, y: i32) -> i64 { #[inline(never)] fn bar() { let _f = Box::new(0); - // This call used to trigger an LLVM bug in opt-level z where the base - // pointer gets corrupted, see issue #45034 + // This call used to trigger an LLVM bug in opt-level=z where the base + // pointer gets corrupted due to incorrect register allocation let y: fn(i32, i32) -> i64 = test::black_box(foo); test::black_box(y(1, 2)); } diff --git a/tests/ui/linkage-attr/msvc-static-data-import.rs b/tests/ui/linkage-attr/msvc-static-data-import.rs index 15d799085fecc..e53eb404ef6ee 100644 --- a/tests/ui/linkage-attr/msvc-static-data-import.rs +++ b/tests/ui/linkage-attr/msvc-static-data-import.rs @@ -1,8 +1,18 @@ +//! Test that static data from external crates can be imported on MSVC targets. +//! +//! On Windows MSVC targets, static data from external rlibs must be imported +//! through `__imp_` stubs to ensure proper linking. Without this, +//! the linker would fail with "unresolved external symbol" errors when trying +//! to reference static data from another crate. +//! +//! Regression test for . +//! Fixed in . + //@ run-pass -//@ aux-build:msvc-data-only-lib.rs +//@ aux-build:msvc-static-data-import-lib.rs -extern crate msvc_data_only_lib; +extern crate msvc_static_data_import_lib; fn main() { - println!("The answer is {} !", msvc_data_only_lib::FOO); + println!("The answer is {}!", msvc_static_data_import_lib::FOO); } diff --git a/tests/ui/parser/multiline-comments-basic.rs b/tests/ui/parser/multiline-comments-basic.rs index 9817488203221..1aa2a531f5cc2 100644 --- a/tests/ui/parser/multiline-comments-basic.rs +++ b/tests/ui/parser/multiline-comments-basic.rs @@ -1,6 +1,10 @@ +//! Test that basic multiline comments are parsed correctly. +//! +//! Feature implementation test for . + //@ run-pass /* - * This is a multi-line oldcomment. + * This is a multi-line comment. */ -pub fn main() { } +pub fn main() {} diff --git a/tests/ui/parser/unicode-multibyte-chars-no-ice.rs b/tests/ui/parser/unicode-multibyte-chars-no-ice.rs index d585a791fb9c1..b1bb0c66ae2bb 100644 --- a/tests/ui/parser/unicode-multibyte-chars-no-ice.rs +++ b/tests/ui/parser/unicode-multibyte-chars-no-ice.rs @@ -1,7 +1,9 @@ +//! Test that multibyte Unicode characters don't crash the compiler. +//! +//! Regression test for . + //@ run-pass -// -// Test that multibyte characters don't crash the compiler pub fn main() { println!("마이너스 사인이 없으면"); }