https://gcc.gnu.org/g:94d35ee54b5c08f33b7a20b63a828268f4051a94

commit r17-2250-g94d35ee54b5c08f33b7a20b63a828268f4051a94
Author: Lishin <[email protected]>
Date:   Fri Jun 26 17:54:46 2026 +0000

    gccrs: Add tests for local binding LIFO and nested block scopes
    
    The new tests verify that multiple local bindings in the
    same scope are dropped in LIFO order, and nested block scopes
    drop inner bindings before outer bindings.
    
    gcc/testsuite/ChangeLog:
    
            * rust/execute/drop-local-binding-lifo.rs: New test.
            * rust/execute/drop-nested-block-scope.rs: New test.
    
    Signed-off-by: Lishin <[email protected]>

Diff:
---
 .../rust/execute/drop-local-binding-lifo.rs        | 56 ++++++++++++++
 .../rust/execute/drop-nested-block-scope.rs        | 86 ++++++++++++++++++++++
 2 files changed, 142 insertions(+)

diff --git a/gcc/testsuite/rust/execute/drop-local-binding-lifo.rs 
b/gcc/testsuite/rust/execute/drop-local-binding-lifo.rs
new file mode 100644
index 000000000000..459c3738d4e5
--- /dev/null
+++ b/gcc/testsuite/rust/execute/drop-local-binding-lifo.rs
@@ -0,0 +1,56 @@
+// { dg-output "C\r*\nB\r*\nA\r*\n" }
+// { dg-additional-options "-w" }
+#![feature(no_core)]
+#![feature(lang_items)]
+#![no_core]
+
+extern "C" {
+    fn printf(s: *const i8, ...);
+}
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "drop"]
+pub trait Drop {
+    fn drop(&mut self);
+}
+
+struct A;
+struct B;
+struct C;
+
+impl Drop for A {
+    fn drop(&mut self) {
+        let msg = "A\n\0" as *const str as *const i8;
+        unsafe {
+            printf(msg);
+        }
+    }
+}
+
+impl Drop for B {
+    fn drop(&mut self) {
+        let msg = "B\n\0" as *const str as *const i8;
+        unsafe {
+            printf(msg);
+        }
+    }
+}
+
+impl Drop for C {
+    fn drop(&mut self) {
+        let msg = "C\n\0" as *const str as *const i8;
+        unsafe {
+            printf(msg);
+        }
+    }
+}
+
+fn main() -> i32 {
+    let _a = A;
+    let _b = B;
+    let _c = C;
+
+    0
+}
\ No newline at end of file
diff --git a/gcc/testsuite/rust/execute/drop-nested-block-scope.rs 
b/gcc/testsuite/rust/execute/drop-nested-block-scope.rs
new file mode 100644
index 000000000000..06fed6e0fd3d
--- /dev/null
+++ b/gcc/testsuite/rust/execute/drop-nested-block-scope.rs
@@ -0,0 +1,86 @@
+// { dg-output "inner\r*\nmiddle2\r*\nmiddle\r*\nouter2\r*\nouter\r*\n" }
+// { dg-additional-options "-w" }
+#![feature(no_core)]
+#![feature(lang_items)]
+#![no_core]
+
+extern "C" {
+    fn printf(s: *const i8, ...);
+}
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "drop"]
+pub trait Drop {
+    fn drop(&mut self);
+}
+
+struct Outer;
+struct Outer2;
+struct Middle;
+struct Middle2;
+struct Inner;
+
+impl Drop for Outer {
+    fn drop(&mut self) {
+        let msg = "outer\n\0" as *const str as *const i8;
+        unsafe {
+            printf(msg);
+        }
+    }
+}
+
+impl Drop for Outer2 {
+    fn drop(&mut self) {
+        let msg = "outer2\n\0" as *const str as *const i8;
+        unsafe {
+            printf(msg);
+        }
+    }
+}
+
+impl Drop for Middle {
+    fn drop(&mut self) {
+        let msg = "middle\n\0" as *const str as *const i8;
+        unsafe {
+            printf(msg);
+        }
+    }
+}
+
+impl Drop for Middle2 {
+    fn drop(&mut self) {
+        let msg = "middle2\n\0" as *const str as *const i8;
+        unsafe {
+            printf(msg);
+        }
+    }
+}
+
+impl Drop for Inner {
+    fn drop(&mut self) {
+        let msg = "inner\n\0" as *const str as *const i8;
+        unsafe {
+            printf(msg);
+        }
+    }
+}
+
+fn main() -> i32 {
+    let _outer = Outer;
+
+    {
+        let _middle = Middle;
+
+        {
+            let _inner = Inner;
+        }
+
+        let _middle2 = Middle2;
+    }
+
+    let _outer2 = Outer2;
+
+    0
+}

Reply via email to