about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-01-09 13:13:35 +0000
committerbors <bors@rust-lang.org>2023-01-09 13:13:35 +0000
commitd61d359d5ef5e3192611297805dbfbb52c55de8f (patch)
tree374888d2e6ddfc2006e9eb8dadc2f0d6214562e8 /src/test/codegen
parent87a202e6f23896f867457c0a26b31b367fa1c0e0 (diff)
parent236ae262bc80dabf67669a2763fda5034982b9b9 (diff)
downloadrust-d61d359d5ef5e3192611297805dbfbb52c55de8f.tar.gz
rust-d61d359d5ef5e3192611297805dbfbb52c55de8f.zip
Auto merge of #2753 - RalfJung:rustup, r=RalfJung
Rustup

Pulls in https://github.com/rust-lang/rust/pull/104658
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/box-maybe-uninit-llvm14.rs14
-rw-r--r--src/test/codegen/box-maybe-uninit.rs14
-rw-r--r--src/test/codegen/issue-86106.rs62
-rw-r--r--src/test/codegen/noalias-flag.rs23
-rw-r--r--src/test/codegen/zst-offset.rs9
5 files changed, 113 insertions, 9 deletions
diff --git a/src/test/codegen/box-maybe-uninit-llvm14.rs b/src/test/codegen/box-maybe-uninit-llvm14.rs
index bd1a6599c33..7b5ae894311 100644
--- a/src/test/codegen/box-maybe-uninit-llvm14.rs
+++ b/src/test/codegen/box-maybe-uninit-llvm14.rs
@@ -2,7 +2,7 @@
 
 // Once we're done with llvm 14 and earlier, this test can be deleted.
 
-#![crate_type="lib"]
+#![crate_type = "lib"]
 
 use std::mem::MaybeUninit;
 
@@ -17,8 +17,16 @@ pub fn box_uninitialized() -> Box<MaybeUninit<usize>> {
     Box::new(MaybeUninit::uninit())
 }
 
-// FIXME: add a test for a bigger box. Currently broken, see
-// https://github.com/rust-lang/rust/issues/58201.
+// https://github.com/rust-lang/rust/issues/58201
+#[no_mangle]
+pub fn box_uninitialized2() -> Box<MaybeUninit<[usize; 1024 * 1024]>> {
+    // CHECK-LABEL: @box_uninitialized2
+    // CHECK-NOT: store
+    // CHECK-NOT: alloca
+    // CHECK-NOT: memcpy
+    // CHECK-NOT: memset
+    Box::new(MaybeUninit::uninit())
+}
 
 // Hide the LLVM 15+ `allocalign` attribute in the declaration of __rust_alloc
 // from the CHECK-NOT above. We don't check the attributes here because we can't rely
diff --git a/src/test/codegen/box-maybe-uninit.rs b/src/test/codegen/box-maybe-uninit.rs
index e105e26f16a..c82b56a71f5 100644
--- a/src/test/codegen/box-maybe-uninit.rs
+++ b/src/test/codegen/box-maybe-uninit.rs
@@ -1,6 +1,6 @@
 // compile-flags: -O
 // min-llvm-version: 15.0
-#![crate_type="lib"]
+#![crate_type = "lib"]
 
 use std::mem::MaybeUninit;
 
@@ -15,8 +15,16 @@ pub fn box_uninitialized() -> Box<MaybeUninit<usize>> {
     Box::new(MaybeUninit::uninit())
 }
 
-// FIXME: add a test for a bigger box. Currently broken, see
-// https://github.com/rust-lang/rust/issues/58201.
+// https://github.com/rust-lang/rust/issues/58201
+#[no_mangle]
+pub fn box_uninitialized2() -> Box<MaybeUninit<[usize; 1024 * 1024]>> {
+    // CHECK-LABEL: @box_uninitialized2
+    // CHECK-NOT: store
+    // CHECK-NOT: alloca
+    // CHECK-NOT: memcpy
+    // CHECK-NOT: memset
+    Box::new(MaybeUninit::uninit())
+}
 
 // Hide the `allocalign` attribute in the declaration of __rust_alloc
 // from the CHECK-NOT above, and also verify the attributes got set reasonably.
diff --git a/src/test/codegen/issue-86106.rs b/src/test/codegen/issue-86106.rs
new file mode 100644
index 00000000000..9ccbcb24f56
--- /dev/null
+++ b/src/test/codegen/issue-86106.rs
@@ -0,0 +1,62 @@
+// min-llvm-version: 15.0
+// compile-flags: -C opt-level=3 -Z merge-functions=disabled
+
+// The below two functions ensure that both `String::new()` and `"".to_string()`
+// produce the identical code.
+
+#![crate_type = "lib"]
+
+// CHECK-LABEL: define void @string_new
+#[no_mangle]
+pub fn string_new() -> String {
+    // CHECK-NOT: load i8
+    // CHECK: store i{{32|64}}
+    // CHECK-NEXT: getelementptr
+    // CHECK-NEXT: store ptr
+    // CHECK-NEXT: getelementptr
+    // CHECK-NEXT: store i{{32|64}}
+    // CHECK-NEXT: ret void
+    String::new()
+}
+
+// CHECK-LABEL: define void @empty_to_string
+#[no_mangle]
+pub fn empty_to_string() -> String {
+    // CHECK-NOT: load i8
+    // CHECK: store i{{32|64}}
+    // CHECK-NEXT: getelementptr
+    // CHECK-NEXT: store ptr
+    // CHECK-NEXT: getelementptr
+    // CHECK-NEXT: store i{{32|64}}
+    // CHECK-NEXT: ret void
+    "".to_string()
+}
+
+// The below two functions ensure that both `vec![]` and `vec![].clone()`
+// produce the identical code.
+
+// CHECK-LABEL: @empty_vec
+#[no_mangle]
+pub fn empty_vec() -> Vec<u8> {
+    // CHECK: store i{{32|64}}
+    // CHECK-NOT: load i8
+    // CHECK-NEXT: getelementptr
+    // CHECK-NEXT: store ptr
+    // CHECK-NEXT: getelementptr
+    // CHECK-NEXT: store i{{32|64}}
+    // CHECK-NEXT: ret void
+    vec![]
+}
+
+// CHECK-LABEL: @empty_vec_clone
+#[no_mangle]
+pub fn empty_vec_clone() -> Vec<u8> {
+    // CHECK: store i{{32|64}}
+    // CHECK-NOT: load i8
+    // CHECK-NEXT: getelementptr
+    // CHECK-NEXT: store ptr
+    // CHECK-NEXT: getelementptr
+    // CHECK-NEXT: store i{{32|64}}
+    // CHECK-NEXT: ret void
+    vec![].clone()
+}
diff --git a/src/test/codegen/noalias-flag.rs b/src/test/codegen/noalias-flag.rs
new file mode 100644
index 00000000000..a9ec61e286d
--- /dev/null
+++ b/src/test/codegen/noalias-flag.rs
@@ -0,0 +1,23 @@
+// compile-flags: -O -Zmutable-noalias=no
+
+#![crate_type = "lib"]
+
+// `-Zmutable-noalias=no` should disable noalias on mut refs...
+
+// CHECK-LABEL: @test_mut_ref(
+// CHECK-NOT: noalias
+// CHECK-SAME: %x
+#[no_mangle]
+pub fn test_mut_ref(x: &mut i32) -> &mut i32 {
+    x
+}
+
+// ...but not on shared refs
+
+// CHECK-LABEL: @test_ref(
+// CHECK-SAME: noalias
+// CHECK-SAME: %x
+#[no_mangle]
+pub fn test_ref(x: &i32) -> &i32 {
+    x
+}
diff --git a/src/test/codegen/zst-offset.rs b/src/test/codegen/zst-offset.rs
index 29d2a1754a3..844d5870a84 100644
--- a/src/test/codegen/zst-offset.rs
+++ b/src/test/codegen/zst-offset.rs
@@ -15,7 +15,7 @@ pub fn helper(_: usize) {
 pub fn scalar_layout(s: &(u64, ())) {
 // CHECK: getelementptr i8, {{.+}}, [[USIZE]] 8
     let x = &s.1;
-    &x; // keep variable in an alloca
+    witness(&x); // keep variable in an alloca
 }
 
 // Check that we correctly generate a GEP for a ZST that is not included in ScalarPair layout
@@ -24,7 +24,7 @@ pub fn scalar_layout(s: &(u64, ())) {
 pub fn scalarpair_layout(s: &(u64, u32, ())) {
 // CHECK: getelementptr i8, {{.+}}, [[USIZE]] 12
     let x = &s.2;
-    &x; // keep variable in an alloca
+    witness(&x); // keep variable in an alloca
 }
 
 #[repr(simd)]
@@ -36,5 +36,8 @@ pub struct U64x4(u64, u64, u64, u64);
 pub fn vector_layout(s: &(U64x4, ())) {
 // CHECK: getelementptr i8, {{.+}}, [[USIZE]] 32
     let x = &s.1;
-    &x; // keep variable in an alloca
+    witness(&x); // keep variable in an alloca
 }
+
+#[inline(never)]
+fn witness(_: &impl Sized) {}