about summary refs log tree commit diff
path: root/src/test/ui/codegen
diff options
context:
space:
mode:
authorCaio <c410.f3r@gmail.com>2022-06-21 09:33:14 -0300
committerCaio <c410.f3r@gmail.com>2022-06-21 09:33:14 -0300
commitb6290debedf28aef1af2b8408b49431ccd9c3328 (patch)
tree6b4fcf3bd2f1d3bfe558d300593644b1e0debc81 /src/test/ui/codegen
parentabace0a1f17986d89aedf610819deab2b4afee56 (diff)
downloadrust-b6290debedf28aef1af2b8408b49431ccd9c3328.tar.gz
rust-b6290debedf28aef1af2b8408b49431ccd9c3328.zip
Move some tests to more reasonable directories
Diffstat (limited to 'src/test/ui/codegen')
-rw-r--r--src/test/ui/codegen/issue-28950.rs22
-rw-r--r--src/test/ui/codegen/issue-63787.rs36
2 files changed, 58 insertions, 0 deletions
diff --git a/src/test/ui/codegen/issue-28950.rs b/src/test/ui/codegen/issue-28950.rs
new file mode 100644
index 00000000000..8b55f42f3f4
--- /dev/null
+++ b/src/test/ui/codegen/issue-28950.rs
@@ -0,0 +1,22 @@
+// run-pass
+// ignore-emscripten no threads
+// compile-flags: -O
+
+// Tests that the `vec!` macro does not overflow the stack when it is
+// given data larger than the stack.
+
+// FIXME(eddyb) Improve unoptimized codegen to avoid the temporary,
+// and thus run successfully even when compiled at -C opt-level=0.
+
+const LEN: usize = 1 << 15;
+
+use std::thread::Builder;
+
+fn main() {
+    assert!(Builder::new().stack_size(LEN / 2).spawn(|| {
+        // FIXME(eddyb) this can be vec![[0: LEN]] pending
+        // https://llvm.org/bugs/show_bug.cgi?id=28987
+        let vec = vec![unsafe { std::mem::zeroed::<[u8; LEN]>() }];
+        assert_eq!(vec.len(), 1);
+    }).unwrap().join().is_ok());
+}
diff --git a/src/test/ui/codegen/issue-63787.rs b/src/test/ui/codegen/issue-63787.rs
new file mode 100644
index 00000000000..cba079b2315
--- /dev/null
+++ b/src/test/ui/codegen/issue-63787.rs
@@ -0,0 +1,36 @@
+// run-pass
+// compile-flags: -O
+
+// Make sure that `Ref` and `RefMut` do not make false promises about aliasing,
+// because once they drop, their reference/pointer can alias other writes.
+
+// Adapted from comex's proof of concept:
+// https://github.com/rust-lang/rust/issues/63787#issuecomment-523588164
+
+use std::cell::RefCell;
+use std::ops::Deref;
+
+pub fn break_if_r_is_noalias(rc: &RefCell<i32>, r: impl Deref<Target = i32>) -> i32 {
+    let ptr1 = &*r as *const i32;
+    let a = *r;
+    drop(r);
+    *rc.borrow_mut() = 2;
+    let r2 = rc.borrow();
+    let ptr2 = &*r2 as *const i32;
+    if ptr2 != ptr1 {
+        panic!();
+    }
+    // If LLVM knows the pointers are the same, and if `r` was `noalias`,
+    // then it may replace this with `a + a`, ignoring the earlier write.
+    a + *r2
+}
+
+fn main() {
+    let mut rc = RefCell::new(1);
+    let res = break_if_r_is_noalias(&rc, rc.borrow());
+    assert_eq!(res, 3);
+
+    *rc.get_mut() = 1;
+    let res = break_if_r_is_noalias(&rc, rc.borrow_mut());
+    assert_eq!(res, 3);
+}