about summary refs log tree commit diff
path: root/tests/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs
diff options
context:
space:
mode:
authorAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-05 09:13:28 +0100
committerAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-11 09:32:08 +0000
commitcf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch)
tree40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs
parentca855e6e42787ecd062d81d53336fe6788ef51a9 (diff)
downloadrust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz
rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip
Move /src/test to /tests
Diffstat (limited to 'tests/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs')
-rw-r--r--tests/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs b/tests/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs
new file mode 100644
index 00000000000..6cd3781b760
--- /dev/null
+++ b/tests/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs
@@ -0,0 +1,47 @@
+// run-pass
+// needs-unwind
+
+#![allow(unused_must_use)]
+#![allow(dead_code)]
+#![allow(unused_variables)]
+// Test cleanup of rvalue temporary that occurs while `box` construction
+// is in progress. This scenario revealed a rather terrible bug.  The
+// ingredients are:
+//
+// 1. Partial cleanup of `box` is in scope,
+// 2. cleanup of return value from `get_bar()` is in scope,
+// 3. do_it() panics.
+//
+// This led to a bug because `the top-most frame that was to be
+// cleaned (which happens to be the partial cleanup of `box`) required
+// multiple basic blocks, which led to us dropping part of the cleanup
+// from the top-most frame.
+//
+// It's unclear how likely such a bug is to recur, but it seems like a
+// scenario worth testing.
+
+// ignore-emscripten no threads support
+
+use std::thread;
+
+enum Conzabble {
+    Bickwick(Foo)
+}
+
+struct Foo { field: Box<usize> }
+
+fn do_it(x: &[usize]) -> Foo {
+    panic!()
+}
+
+fn get_bar(x: usize) -> Vec<usize> { vec![x * 2] }
+
+pub fn fails() {
+    let x = 2;
+    let mut y: Vec<Box<_>> = Vec::new();
+    y.push(Box::new(Conzabble::Bickwick(do_it(&get_bar(x)))));
+}
+
+pub fn main() {
+    thread::spawn(fails).join();
+}