about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/asm/avr-clobbers.rs2
-rw-r--r--tests/codegen/autodiff.rs2
-rw-r--r--tests/codegen/avr/avr-func-addrspace.rs2
-rw-r--r--tests/codegen/box-default-debug-copies.rs28
-rw-r--r--tests/codegen/gep-index.rs8
-rw-r--r--tests/codegen/intrinsics/nearby.rs18
-rw-r--r--tests/codegen/intrinsics/offset.rs2
-rw-r--r--tests/codegen/intrinsics/ptr_metadata.rs2
-rw-r--r--tests/codegen/issues/str-to-string-128690.rs10
-rw-r--r--tests/codegen/ptr-arithmetic.rs2
-rw-r--r--tests/codegen/simd-intrinsic/simd-intrinsic-float-pow.rs87
-rw-r--r--tests/codegen/simd-intrinsic/simd-intrinsic-float-powi.rs87
-rw-r--r--tests/codegen/slice-iter-nonnull.rs6
-rw-r--r--tests/codegen/uninhabited-transparent-return-abi.rs44
14 files changed, 91 insertions, 209 deletions
diff --git a/tests/codegen/asm/avr-clobbers.rs b/tests/codegen/asm/avr-clobbers.rs
index 56218cd7bcf..9451127bf04 100644
--- a/tests/codegen/asm/avr-clobbers.rs
+++ b/tests/codegen/asm/avr-clobbers.rs
@@ -1,6 +1,6 @@
 //@ add-core-stubs
 //@ assembly-output: emit-asm
-//@ compile-flags: --target avr-unknown-gnu-atmega328
+//@ compile-flags: --target avr-none -C target-cpu=atmega328p
 //@ needs-llvm-components: avr
 
 #![crate_type = "rlib"]
diff --git a/tests/codegen/autodiff.rs b/tests/codegen/autodiff.rs
index abf7fcf3e4b..cace0edb2b5 100644
--- a/tests/codegen/autodiff.rs
+++ b/tests/codegen/autodiff.rs
@@ -1,4 +1,4 @@
-//@ compile-flags: -C opt-level=3  -Clto=fat
+//@ compile-flags: -Zautodiff=Enable -C opt-level=3  -Clto=fat
 //@ no-prefer-dynamic
 //@ needs-enzyme
 #![feature(autodiff)]
diff --git a/tests/codegen/avr/avr-func-addrspace.rs b/tests/codegen/avr/avr-func-addrspace.rs
index ed8acccb1ad..2ec7c86b5f4 100644
--- a/tests/codegen/avr/avr-func-addrspace.rs
+++ b/tests/codegen/avr/avr-func-addrspace.rs
@@ -1,4 +1,4 @@
-//@ compile-flags: -Copt-level=3 --target=avr-unknown-gnu-atmega328 --crate-type=rlib -C panic=abort
+//@ compile-flags: -Copt-level=3 --target=avr-none -C target-cpu=atmega328p --crate-type=rlib -C panic=abort
 //@ needs-llvm-components: avr
 
 // This test validates that function pointers can be stored in global variables
diff --git a/tests/codegen/box-default-debug-copies.rs b/tests/codegen/box-default-debug-copies.rs
new file mode 100644
index 00000000000..06cc41b21c0
--- /dev/null
+++ b/tests/codegen/box-default-debug-copies.rs
@@ -0,0 +1,28 @@
+//@ compile-flags: -Copt-level=0
+
+// Test to make sure that `<Box<T>>::default` does not create too many copies of `T` on the stack.
+// in debug mode. This regressed in dd0620b86721ae8cae86736443acd3f72ba6fc32 to
+// four `T` allocas.
+//
+// See https://github.com/rust-lang/rust/issues/136043 for more context.
+//
+// FIXME: This test only wants to ensure that there are at most two allocas of `T` created, instead
+// of checking for exactly two.
+
+#![crate_type = "lib"]
+
+#[allow(dead_code)]
+pub struct Thing([u8; 1000000]);
+
+impl Default for Thing {
+    fn default() -> Self {
+        Thing([0; 1000000])
+    }
+}
+
+// CHECK-COUNT-2: %{{.*}} = alloca {{.*}}1000000
+// CHECK-NOT: %{{.*}} = alloca {{.*}}1000000
+#[no_mangle]
+pub fn box_default_single_copy() -> Box<Thing> {
+    Box::default()
+}
diff --git a/tests/codegen/gep-index.rs b/tests/codegen/gep-index.rs
index 1f5e8855910..bfb2511af87 100644
--- a/tests/codegen/gep-index.rs
+++ b/tests/codegen/gep-index.rs
@@ -11,27 +11,27 @@ struct Foo(i32, i32);
 // CHECK-LABEL: @index_on_struct(
 #[no_mangle]
 fn index_on_struct(a: &[Foo], index: usize) -> &Foo {
-    // CHECK: getelementptr inbounds %Foo, ptr %a.0, {{i64|i32}} %index
+    // CHECK: getelementptr inbounds{{( nuw)?}} %Foo, ptr %a.0, {{i64|i32}} %index
     &a[index]
 }
 
 // CHECK-LABEL: @offset_on_struct(
 #[no_mangle]
 fn offset_on_struct(a: *const Foo, index: usize) -> *const Foo {
-    // CHECK: getelementptr inbounds %Foo, ptr %a, {{i64|i32}} %index
+    // CHECK: getelementptr inbounds{{( nuw)?}} %Foo, ptr %a, {{i64|i32}} %index
     unsafe { a.add(index) }
 }
 
 // CHECK-LABEL: @index_on_i32(
 #[no_mangle]
 fn index_on_i32(a: &[i32], index: usize) -> &i32 {
-    // CHECK: getelementptr inbounds i32, ptr %a.0, {{i64|i32}} %index
+    // CHECK: getelementptr inbounds{{( nuw)?}} i32, ptr %a.0, {{i64|i32}} %index
     &a[index]
 }
 
 // CHECK-LABEL: @offset_on_i32(
 #[no_mangle]
 fn offset_on_i32(a: *const i32, index: usize) -> *const i32 {
-    // CHECK: getelementptr inbounds i32, ptr %a, {{i64|i32}} %index
+    // CHECK: getelementptr inbounds{{( nuw)?}} i32, ptr %a, {{i64|i32}} %index
     unsafe { a.add(index) }
 }
diff --git a/tests/codegen/intrinsics/nearby.rs b/tests/codegen/intrinsics/nearby.rs
deleted file mode 100644
index 520fe2f1886..00000000000
--- a/tests/codegen/intrinsics/nearby.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-#![crate_type = "lib"]
-#![feature(core_intrinsics)]
-
-use std::intrinsics;
-
-// CHECK-LABEL: @nearbyintf32
-#[no_mangle]
-pub unsafe fn nearbyintf32(a: f32) -> f32 {
-    // CHECK: llvm.nearbyint.f32
-    intrinsics::nearbyintf32(a)
-}
-
-// CHECK-LABEL: @nearbyintf64
-#[no_mangle]
-pub unsafe fn nearbyintf64(a: f64) -> f64 {
-    // CHECK: llvm.nearbyint.f64
-    intrinsics::nearbyintf64(a)
-}
diff --git a/tests/codegen/intrinsics/offset.rs b/tests/codegen/intrinsics/offset.rs
index d76d3e705ab..cf0c7c7ac7d 100644
--- a/tests/codegen/intrinsics/offset.rs
+++ b/tests/codegen/intrinsics/offset.rs
@@ -27,7 +27,7 @@ pub unsafe fn offset_isize(p: *const u32, d: isize) -> *const u32 {
 // CHECK-SAME: (ptr noundef %p, [[SIZE]] noundef %d)
 #[no_mangle]
 pub unsafe fn offset_usize(p: *const u64, d: usize) -> *const u64 {
-    // CHECK: %[[R:.*]] = getelementptr inbounds i64, ptr %p, [[SIZE]] %d
+    // CHECK: %[[R:.*]] = getelementptr inbounds{{( nuw)?}} i64, ptr %p, [[SIZE]] %d
     // CHECK-NEXT: ret ptr %[[R]]
     offset(p, d)
 }
diff --git a/tests/codegen/intrinsics/ptr_metadata.rs b/tests/codegen/intrinsics/ptr_metadata.rs
index 87a32fa3d24..044dbc20486 100644
--- a/tests/codegen/intrinsics/ptr_metadata.rs
+++ b/tests/codegen/intrinsics/ptr_metadata.rs
@@ -28,7 +28,7 @@ pub unsafe fn dyn_byte_offset(
     p: *const dyn std::fmt::Debug,
     n: usize,
 ) -> *const dyn std::fmt::Debug {
-    // CHECK: %[[Q:.+]] = getelementptr inbounds i8, ptr %p.0, i64 %n
+    // CHECK: %[[Q:.+]] = getelementptr inbounds{{( nuw)?}} i8, ptr %p.0, i64 %n
     // CHECK: %[[TEMP1:.+]] = insertvalue { ptr, ptr } poison, ptr %[[Q]], 0
     // CHECK: %[[TEMP2:.+]] = insertvalue { ptr, ptr } %[[TEMP1]], ptr %p.1, 1
     // CHECK: ret { ptr, ptr } %[[TEMP2]]
diff --git a/tests/codegen/issues/str-to-string-128690.rs b/tests/codegen/issues/str-to-string-128690.rs
index 8b416306ba6..d9e69764be2 100644
--- a/tests/codegen/issues/str-to-string-128690.rs
+++ b/tests/codegen/issues/str-to-string-128690.rs
@@ -2,25 +2,27 @@
 #![crate_type = "lib"]
 
 //! Make sure str::to_string is specialized not to use fmt machinery.
+//!
+//! Note that the `CHECK-NOT`s here try to match on calls to functions under `core::fmt`.
 
 // CHECK-LABEL: define {{(dso_local )?}}void @one_ref
 #[no_mangle]
 pub fn one_ref(input: &str) -> String {
-    // CHECK-NOT: {{(call|invoke).*}}fmt
+    // CHECK-NOT: {{(call|invoke)}}{{.*}}@{{.*}}core{{.*}}fmt{{.*}}
     input.to_string()
 }
 
 // CHECK-LABEL: define {{(dso_local )?}}void @two_ref
 #[no_mangle]
 pub fn two_ref(input: &&str) -> String {
-    // CHECK-NOT: {{(call|invoke).*}}fmt
+    // CHECK-NOT: {{(call|invoke)}}{{.*}}@{{.*}}core{{.*}}fmt{{.*}}
     input.to_string()
 }
 
 // CHECK-LABEL: define {{(dso_local )?}}void @thirteen_ref
 #[no_mangle]
 pub fn thirteen_ref(input: &&&&&&&&&&&&&str) -> String {
-    // CHECK-NOT: {{(call|invoke).*}}fmt
+    // CHECK-NOT: {{(call|invoke)}}{{.*}}@{{.*}}core{{.*}}fmt{{.*}}
     input.to_string()
 }
 
@@ -31,6 +33,6 @@ pub fn thirteen_ref(input: &&&&&&&&&&&&&str) -> String {
 // CHECK-LABEL: define {{(dso_local )?}}void @fourteen_ref
 #[no_mangle]
 pub fn fourteen_ref(input: &&&&&&&&&&&&&&str) -> String {
-    // CHECK: {{(call|invoke).*}}fmt
+    // CHECK: {{(call|invoke)}}{{.*}}@{{.*}}core{{.*}}fmt{{.*}}
     input.to_string()
 }
diff --git a/tests/codegen/ptr-arithmetic.rs b/tests/codegen/ptr-arithmetic.rs
index ecb44b30f5c..fc4441ef448 100644
--- a/tests/codegen/ptr-arithmetic.rs
+++ b/tests/codegen/ptr-arithmetic.rs
@@ -6,7 +6,7 @@
 // CHECK-SAME: [[WORD:i[0-9]+]] noundef %n)
 #[no_mangle]
 pub unsafe fn i32_add(p: *const i32, n: usize) -> *const i32 {
-    // CHECK: %[[TEMP:.+]] = getelementptr inbounds i32, ptr %p, [[WORD]] %n
+    // CHECK: %[[TEMP:.+]] = getelementptr inbounds{{( nuw)?}} i32, ptr %p, [[WORD]] %n
     // CHECK: ret ptr %[[TEMP]]
     p.add(n)
 }
diff --git a/tests/codegen/simd-intrinsic/simd-intrinsic-float-pow.rs b/tests/codegen/simd-intrinsic/simd-intrinsic-float-pow.rs
deleted file mode 100644
index 3527f71c00b..00000000000
--- a/tests/codegen/simd-intrinsic/simd-intrinsic-float-pow.rs
+++ /dev/null
@@ -1,87 +0,0 @@
-//@ compile-flags: -C no-prepopulate-passes
-
-#![crate_type = "lib"]
-
-#![feature(repr_simd, intrinsics)]
-#![allow(non_camel_case_types)]
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f32x2(pub [f32; 2]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f32x4(pub [f32; 4]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f32x8(pub [f32; 8]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f32x16(pub [f32; 16]);
-
-extern "rust-intrinsic" {
-    fn simd_fpow<T>(x: T, b: T) -> T;
-}
-
-// CHECK-LABEL: @fpow_32x2
-#[no_mangle]
-pub unsafe fn fpow_32x2(a: f32x2, b: f32x2) -> f32x2 {
-    // CHECK: call <2 x float> @llvm.pow.v2f32
-    simd_fpow(a, b)
-}
-
-// CHECK-LABEL: @fpow_32x4
-#[no_mangle]
-pub unsafe fn fpow_32x4(a: f32x4, b: f32x4) -> f32x4 {
-    // CHECK: call <4 x float> @llvm.pow.v4f32
-    simd_fpow(a, b)
-}
-
-// CHECK-LABEL: @fpow_32x8
-#[no_mangle]
-pub unsafe fn fpow_32x8(a: f32x8, b: f32x8) -> f32x8 {
-    // CHECK: call <8 x float> @llvm.pow.v8f32
-    simd_fpow(a, b)
-}
-
-// CHECK-LABEL: @fpow_32x16
-#[no_mangle]
-pub unsafe fn fpow_32x16(a: f32x16, b: f32x16) -> f32x16 {
-    // CHECK: call <16 x float> @llvm.pow.v16f32
-    simd_fpow(a, b)
-}
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f64x2(pub [f64; 2]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f64x4(pub [f64; 4]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f64x8(pub [f64; 8]);
-
-// CHECK-LABEL: @fpow_64x4
-#[no_mangle]
-pub unsafe fn fpow_64x4(a: f64x4, b: f64x4) -> f64x4 {
-    // CHECK: call <4 x double> @llvm.pow.v4f64
-    simd_fpow(a, b)
-}
-
-// CHECK-LABEL: @fpow_64x2
-#[no_mangle]
-pub unsafe fn fpow_64x2(a: f64x2, b: f64x2) -> f64x2 {
-    // CHECK: call <2 x double> @llvm.pow.v2f64
-    simd_fpow(a, b)
-}
-
-// CHECK-LABEL: @fpow_64x8
-#[no_mangle]
-pub unsafe fn fpow_64x8(a: f64x8, b: f64x8) -> f64x8 {
-    // CHECK: call <8 x double> @llvm.pow.v8f64
-    simd_fpow(a, b)
-}
diff --git a/tests/codegen/simd-intrinsic/simd-intrinsic-float-powi.rs b/tests/codegen/simd-intrinsic/simd-intrinsic-float-powi.rs
deleted file mode 100644
index 4f0b5e4e01a..00000000000
--- a/tests/codegen/simd-intrinsic/simd-intrinsic-float-powi.rs
+++ /dev/null
@@ -1,87 +0,0 @@
-//@ compile-flags: -C no-prepopulate-passes
-
-#![crate_type = "lib"]
-
-#![feature(repr_simd, intrinsics)]
-#![allow(non_camel_case_types)]
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f32x2(pub [f32; 2]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f32x4(pub [f32; 4]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f32x8(pub [f32; 8]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f32x16(pub [f32; 16]);
-
-extern "rust-intrinsic" {
-    fn simd_fpowi<T>(x: T, b: i32) -> T;
-}
-
-// CHECK-LABEL: @fpowi_32x2
-#[no_mangle]
-pub unsafe fn fpowi_32x2(a: f32x2, b: i32) -> f32x2 {
-    // CHECK: call <2 x float> @llvm.powi.v2f32
-    simd_fpowi(a, b)
-}
-
-// CHECK-LABEL: @fpowi_32x4
-#[no_mangle]
-pub unsafe fn fpowi_32x4(a: f32x4, b: i32) -> f32x4 {
-    // CHECK: call <4 x float> @llvm.powi.v4f32
-    simd_fpowi(a, b)
-}
-
-// CHECK-LABEL: @fpowi_32x8
-#[no_mangle]
-pub unsafe fn fpowi_32x8(a: f32x8, b: i32) -> f32x8 {
-    // CHECK: call <8 x float> @llvm.powi.v8f32
-    simd_fpowi(a, b)
-}
-
-// CHECK-LABEL: @fpowi_32x16
-#[no_mangle]
-pub unsafe fn fpowi_32x16(a: f32x16, b: i32) -> f32x16 {
-    // CHECK: call <16 x float> @llvm.powi.v16f32
-    simd_fpowi(a, b)
-}
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f64x2(pub [f64; 2]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f64x4(pub [f64; 4]);
-
-#[repr(simd)]
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub struct f64x8(pub [f64; 8]);
-
-// CHECK-LABEL: @fpowi_64x4
-#[no_mangle]
-pub unsafe fn fpowi_64x4(a: f64x4, b: i32) -> f64x4 {
-    // CHECK: call <4 x double> @llvm.powi.v4f64
-    simd_fpowi(a, b)
-}
-
-// CHECK-LABEL: @fpowi_64x2
-#[no_mangle]
-pub unsafe fn fpowi_64x2(a: f64x2, b: i32) -> f64x2 {
-    // CHECK: call <2 x double> @llvm.powi.v2f64
-    simd_fpowi(a, b)
-}
-
-// CHECK-LABEL: @fpowi_64x8
-#[no_mangle]
-pub unsafe fn fpowi_64x8(a: f64x8, b: i32) -> f64x8 {
-    // CHECK: call <8 x double> @llvm.powi.v8f64
-    simd_fpowi(a, b)
-}
diff --git a/tests/codegen/slice-iter-nonnull.rs b/tests/codegen/slice-iter-nonnull.rs
index 98a1b961a64..87907e7ad0a 100644
--- a/tests/codegen/slice-iter-nonnull.rs
+++ b/tests/codegen/slice-iter-nonnull.rs
@@ -14,11 +14,11 @@
 // CHECK-LABEL: @slice_iter_next(
 #[no_mangle]
 pub fn slice_iter_next<'a>(it: &mut std::slice::Iter<'a, u32>) -> Option<&'a u32> {
-    // CHECK: %[[ENDP:.+]] = getelementptr inbounds{{( nuw)?}} i8, ptr %it, {{i32 4|i64 8}}
-    // CHECK: %[[END:.+]] = load ptr, ptr %[[ENDP]]
+    // CHECK: %[[START:.+]] = load ptr, ptr %it,
     // CHECK-SAME: !nonnull
     // CHECK-SAME: !noundef
-    // CHECK: %[[START:.+]] = load ptr, ptr %it,
+    // CHECK: %[[ENDP:.+]] = getelementptr inbounds{{( nuw)?}} i8, ptr %it, {{i32 4|i64 8}}
+    // CHECK: %[[END:.+]] = load ptr, ptr %[[ENDP]]
     // CHECK-SAME: !nonnull
     // CHECK-SAME: !noundef
     // CHECK: icmp eq ptr %[[START]], %[[END]]
diff --git a/tests/codegen/uninhabited-transparent-return-abi.rs b/tests/codegen/uninhabited-transparent-return-abi.rs
new file mode 100644
index 00000000000..6e8b1683163
--- /dev/null
+++ b/tests/codegen/uninhabited-transparent-return-abi.rs
@@ -0,0 +1,44 @@
+//@ compile-flags: -Copt-level=3
+
+// See https://github.com/rust-lang/rust/issues/135802
+
+#![crate_type = "lib"]
+
+enum Void {}
+
+// Should be ABI-compatible with T, but wasn't prior to the PR adding this test.
+#[repr(transparent)]
+struct NoReturn<T>(T, Void);
+
+// Returned by invisible reference (in most ABIs)
+#[allow(dead_code)]
+struct Large(u64, u64, u64);
+
+extern "Rust" {
+    fn opaque() -> NoReturn<Large>;
+    fn opaque_with_arg(rsi: u32) -> NoReturn<Large>;
+}
+
+// CHECK-LABEL: @test_uninhabited_ret_by_ref
+#[no_mangle]
+pub fn test_uninhabited_ret_by_ref() {
+    // CHECK: %_1 = alloca [24 x i8], align {{8|4}}
+    // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %_1)
+    // CHECK-NEXT: call void @opaque(ptr noalias nocapture noundef nonnull sret([24 x i8]) align {{8|4}} dereferenceable(24) %_1) #2
+    // CHECK-NEXT: unreachable
+    unsafe {
+        opaque();
+    }
+}
+
+// CHECK-LABEL: @test_uninhabited_ret_by_ref_with_arg
+#[no_mangle]
+pub fn test_uninhabited_ret_by_ref_with_arg(rsi: u32) {
+    // CHECK: %_2 = alloca [24 x i8], align {{8|4}}
+    // CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %_2)
+    // CHECK-NEXT: call void @opaque_with_arg(ptr noalias nocapture noundef nonnull sret([24 x i8]) align {{8|4}} dereferenceable(24) %_2, i32 noundef %rsi) #2
+    // CHECK-NEXT: unreachable
+    unsafe {
+        opaque_with_arg(rsi);
+    }
+}