about summary refs log tree commit diff
path: root/tests/ui/codegen
diff options
context:
space:
mode:
authorTrevor Gross <t.gross35@gmail.com>2025-07-10 03:23:55 -0400
committerGitHub <noreply@github.com>2025-07-10 03:23:55 -0400
commit7ad90964dd5a9be0e0eff29a63499eae8e822ec8 (patch)
tree3bb15d7543159b3e18790f159633e0c250d34554 /tests/ui/codegen
parenta2fe1bcf7024cdc2e522b65ede1de4f6f9187e55 (diff)
parent7c2cc2ce40f962edeb7badc50172c5b6ff280f12 (diff)
downloadrust-7ad90964dd5a9be0e0eff29a63499eae8e822ec8.tar.gz
rust-7ad90964dd5a9be0e0eff29a63499eae8e822ec8.zip
Rollup merge of #143298 - Kivooeo:tf23, r=tgross35
`tests/ui`: A New Order [23/N]

> [!NOTE]
>
> Intermediate commits are intended to help review, but will be squashed prior to merge.

Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895.

r? ``@tgross35``
Diffstat (limited to 'tests/ui/codegen')
-rw-r--r--tests/ui/codegen/output-slot-init-vs-noninit.rs78
-rw-r--r--tests/ui/codegen/remark-flag-functionality.rs30
-rw-r--r--tests/ui/codegen/shift-right-operand-mutation.rs19
-rw-r--r--tests/ui/codegen/sret-aliasing-rules.rs28
4 files changed, 155 insertions, 0 deletions
diff --git a/tests/ui/codegen/output-slot-init-vs-noninit.rs b/tests/ui/codegen/output-slot-init-vs-noninit.rs
new file mode 100644
index 00000000000..55586843740
--- /dev/null
+++ b/tests/ui/codegen/output-slot-init-vs-noninit.rs
@@ -0,0 +1,78 @@
+//! Check that output slots work correctly for both initializing and non-initializing assignments.
+//!
+//! Regression test for <https://github.com/rust-lang/rust/issues/24>.
+
+//@ run-pass
+
+#![allow(dead_code)]
+#![allow(unused_assignments)]
+#![allow(unknown_lints)]
+#![allow(dead_assignment)]
+#![allow(unused_variables)]
+
+struct A {
+    a: isize,
+    b: isize,
+}
+
+struct Abox {
+    a: Box<isize>,
+    b: Box<isize>,
+}
+
+fn ret_int_i() -> isize {
+    10
+}
+
+fn ret_ext_i() -> Box<isize> {
+    Box::new(10)
+}
+
+fn ret_int_rec() -> A {
+    A { a: 10, b: 10 }
+}
+
+fn ret_ext_rec() -> Box<A> {
+    Box::new(A { a: 10, b: 10 })
+}
+
+fn ret_ext_mem() -> Abox {
+    Abox { a: Box::new(10), b: Box::new(10) }
+}
+
+fn ret_ext_ext_mem() -> Box<Abox> {
+    Box::new(Abox { a: Box::new(10), b: Box::new(10) })
+}
+
+pub fn main() {
+    let mut int_i: isize;
+    let mut ext_i: Box<isize>;
+    let mut int_rec: A;
+    let mut ext_rec: Box<A>;
+    let mut ext_mem: Abox;
+    let mut ext_ext_mem: Box<Abox>;
+
+    int_i = ret_int_i(); // initializing
+    int_i = ret_int_i(); // non-initializing
+    int_i = ret_int_i(); // non-initializing
+
+    ext_i = ret_ext_i(); // initializing
+    ext_i = ret_ext_i(); // non-initializing
+    ext_i = ret_ext_i(); // non-initializing
+
+    int_rec = ret_int_rec(); // initializing
+    int_rec = ret_int_rec(); // non-initializing
+    int_rec = ret_int_rec(); // non-initializing
+
+    ext_rec = ret_ext_rec(); // initializing
+    ext_rec = ret_ext_rec(); // non-initializing
+    ext_rec = ret_ext_rec(); // non-initializing
+
+    ext_mem = ret_ext_mem(); // initializing
+    ext_mem = ret_ext_mem(); // non-initializing
+    ext_mem = ret_ext_mem(); // non-initializing
+
+    ext_ext_mem = ret_ext_ext_mem(); // initializing
+    ext_ext_mem = ret_ext_ext_mem(); // non-initializing
+    ext_ext_mem = ret_ext_ext_mem(); // non-initializing
+}
diff --git a/tests/ui/codegen/remark-flag-functionality.rs b/tests/ui/codegen/remark-flag-functionality.rs
new file mode 100644
index 00000000000..797c55ba830
--- /dev/null
+++ b/tests/ui/codegen/remark-flag-functionality.rs
@@ -0,0 +1,30 @@
+//! Check that `-Cremark` flag correctly emits LLVM optimization remarks.
+//!
+//! Regression test for <https://github.com/rust-lang/rust/issues/90924>.
+
+//@ build-pass
+//@ ignore-pass
+//@ revisions: all inline merge1 merge2
+//@ compile-flags: --crate-type=lib -Cdebuginfo=1 -Copt-level=2
+
+// Check that remarks can be enabled individually or with "all":
+//@ [all]    compile-flags: -Cremark=all
+//@ [inline] compile-flags: -Cremark=inline
+
+// Check that values of -Cremark flag are accumulated:
+//@ [merge1] compile-flags: -Cremark=all    -Cremark=giraffe
+//@ [merge2] compile-flags: -Cremark=inline -Cremark=giraffe
+
+//@ dont-check-compiler-stderr
+//@ dont-require-annotations: NOTE
+
+#[no_mangle]
+#[inline(never)]
+pub fn f() {}
+
+#[no_mangle]
+pub fn g() {
+    f();
+}
+
+//~? NOTE inline (missed): 'f' not inlined into 'g'
diff --git a/tests/ui/codegen/shift-right-operand-mutation.rs b/tests/ui/codegen/shift-right-operand-mutation.rs
new file mode 100644
index 00000000000..b37a0baa6f8
--- /dev/null
+++ b/tests/ui/codegen/shift-right-operand-mutation.rs
@@ -0,0 +1,19 @@
+//! Ensure shift operations don't mutate their right operand.
+//!
+//! This test checks that expressions like `0 << b` don't accidentally
+//! modify the variable `b` due to codegen issues with virtual registers.
+//!
+//! Regression test for <https://github.com/rust-lang/rust/issues/152>.
+
+//@ run-pass
+
+pub fn main() {
+    let mut b: usize = 1;
+    while b < size_of::<usize>() {
+        // This shift operation should not mutate `b`
+        let _ = 0_usize << b;
+        b <<= 1;
+        std::hint::black_box(b);
+    }
+    assert_eq!(size_of::<usize>(), b);
+}
diff --git a/tests/ui/codegen/sret-aliasing-rules.rs b/tests/ui/codegen/sret-aliasing-rules.rs
new file mode 100644
index 00000000000..f35e722f764
--- /dev/null
+++ b/tests/ui/codegen/sret-aliasing-rules.rs
@@ -0,0 +1,28 @@
+//! Check that functions with sret results don't violate aliasing rules.
+//!
+//! When `foo = func(&mut foo)` is called, the compiler must avoid creating
+//! two mutable references to the same variable simultaneously (one for the
+//! parameter and one for the hidden sret out-pointer).
+//!
+//! Regression test for <https://github.com/rust-lang/rust/pull/18250>.
+
+//@ run-pass
+
+#[derive(Copy, Clone)]
+pub struct Foo {
+    f1: isize,
+    _f2: isize,
+}
+
+#[inline(never)]
+pub fn foo(f: &mut Foo) -> Foo {
+    let ret = *f;
+    f.f1 = 0;
+    ret
+}
+
+pub fn main() {
+    let mut f = Foo { f1: 8, _f2: 9 };
+    f = foo(&mut f);
+    assert_eq!(f.f1, 8);
+}