From: Lishin <[email protected]>

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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/95a37ea1f0e451c769072130e1893706cd2bcdad

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4632

 .../rust/execute/drop-local-binding-lifo.rs   | 56 ++++++++++++
 .../rust/execute/drop-nested-block-scope.rs   | 86 +++++++++++++++++++
 2 files changed, 142 insertions(+)
 create mode 100644 gcc/testsuite/rust/execute/drop-local-binding-lifo.rs
 create mode 100644 gcc/testsuite/rust/execute/drop-nested-block-scope.rs

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 000000000..459c3738d
--- /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 000000000..06fed6e0f
--- /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
+}

base-commit: ed80bf43fba235fdb53ea6522df261599c318b94
-- 
2.54.0

Reply via email to