about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-04-07 12:58:15 +0000
committerbors <bors@rust-lang.org>2025-04-07 12:58:15 +0000
commite643f59f6da3a84f43e75dea99afaa5b041ea6bf (patch)
treea5449e907bcfbb64285463eaa9ab0d29775f8fe6 /tests/codegen
parent8fb32ab8e563124fe0968a2878b7f5b5d0e8d722 (diff)
parent6e0b67419c71b0adcd6108d268d7eda5330bd392 (diff)
downloadrust-e643f59f6da3a84f43e75dea99afaa5b041ea6bf.tar.gz
rust-e643f59f6da3a84f43e75dea99afaa5b041ea6bf.zip
Auto merge of #139482 - Zalathar:rollup-h2ht1y6, r=Zalathar
Rollup of 9 pull requests

Successful merges:

 - #139035 (Add new `PatKind::Missing` variants)
 - #139108 (Simplify `thir::PatKind::ExpandedConstant`)
 - #139112 (Implement `super let`)
 - #139365 (Default auto traits: fix perf)
 - #139397 (coverage: Build the CGU's global file table as late as possible)
 - #139455 ( Remove support for `extern "rust-intrinsic"` blocks)
 - #139461 (Stop calling `source_span` query in significant drop order code)
 - #139465 (add sret handling for scalar autodiff)
 - #139466 (Trivial tweaks to stop tracking source span directly)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/autodiff/batched.rs (renamed from tests/codegen/autodiffv.rs)0
-rw-r--r--tests/codegen/autodiff/scalar.rs (renamed from tests/codegen/autodiff.rs)0
-rw-r--r--tests/codegen/autodiff/sret.rs45
-rw-r--r--tests/codegen/avr/avr-func-addrspace.rs5
-rw-r--r--tests/codegen/emscripten-catch-unwind-js-eh.rs13
-rw-r--r--tests/codegen/emscripten-catch-unwind-wasm-eh.rs14
-rw-r--r--tests/codegen/intrinsic-no-unnamed-attr.rs6
-rw-r--r--tests/codegen/intrinsics/nontemporal.rs5
8 files changed, 64 insertions, 24 deletions
diff --git a/tests/codegen/autodiffv.rs b/tests/codegen/autodiff/batched.rs
index e0047116405..e0047116405 100644
--- a/tests/codegen/autodiffv.rs
+++ b/tests/codegen/autodiff/batched.rs
diff --git a/tests/codegen/autodiff.rs b/tests/codegen/autodiff/scalar.rs
index 85358f5fcb6..85358f5fcb6 100644
--- a/tests/codegen/autodiff.rs
+++ b/tests/codegen/autodiff/scalar.rs
diff --git a/tests/codegen/autodiff/sret.rs b/tests/codegen/autodiff/sret.rs
new file mode 100644
index 00000000000..5ead90041ed
--- /dev/null
+++ b/tests/codegen/autodiff/sret.rs
@@ -0,0 +1,45 @@
+//@ compile-flags: -Zautodiff=Enable -C opt-level=3  -Clto=fat
+//@ no-prefer-dynamic
+//@ needs-enzyme
+
+// This test is almost identical to the scalar.rs one,
+// but we intentionally add a few more floats.
+// `df` would ret `{ f64, f32, f32 }`, but is lowered as an sret.
+// We therefore use this test to verify some of our sret handling.
+
+#![feature(autodiff)]
+
+use std::autodiff::autodiff;
+
+#[no_mangle]
+#[autodiff(df, Reverse, Active, Active, Active)]
+fn primal(x: f32, y: f32) -> f64 {
+    (x * x * y) as f64
+}
+
+// CHECK:define internal fastcc void @_ZN4sret2df17h93be4316dd8ea006E(ptr dead_on_unwind noalias nocapture noundef nonnull writable writeonly align 8 dereferenceable(16) initializes((0, 16)) %_0, float noundef %x, float noundef %y)
+// CHECK-NEXT:start:
+// CHECK-NEXT:  %0 = tail call fastcc { double, float, float } @diffeprimal(float %x, float %y)
+// CHECK-NEXT:  %.elt = extractvalue { double, float, float } %0, 0
+// CHECK-NEXT:  store double %.elt, ptr %_0, align 8
+// CHECK-NEXT:  %_0.repack1 = getelementptr inbounds nuw i8, ptr %_0, i64 8
+// CHECK-NEXT:  %.elt2 = extractvalue { double, float, float } %0, 1
+// CHECK-NEXT:  store float %.elt2, ptr %_0.repack1, align 8
+// CHECK-NEXT:  %_0.repack3 = getelementptr inbounds nuw i8, ptr %_0, i64 12
+// CHECK-NEXT:  %.elt4 = extractvalue { double, float, float } %0, 2
+// CHECK-NEXT:  store float %.elt4, ptr %_0.repack3, align 4
+// CHECK-NEXT:  ret void
+// CHECK-NEXT:}
+
+fn main() {
+    let x = std::hint::black_box(3.0);
+    let y = std::hint::black_box(2.5);
+    let scalar = std::hint::black_box(1.0);
+    let (r1, r2, r3) = df(x, y, scalar);
+    // 3*3*1.5 = 22.5
+    assert_eq!(r1, 22.5);
+    // 2*x*y = 2*3*2.5 = 15.0
+    assert_eq!(r2, 15.0);
+    // x*x*1 = 3*3 = 9
+    assert_eq!(r3, 9.0);
+}
diff --git a/tests/codegen/avr/avr-func-addrspace.rs b/tests/codegen/avr/avr-func-addrspace.rs
index 2ae2f40d7b3..e0192f8b45a 100644
--- a/tests/codegen/avr/avr-func-addrspace.rs
+++ b/tests/codegen/avr/avr-func-addrspace.rs
@@ -17,9 +17,8 @@
 extern crate minicore;
 use minicore::*;
 
-extern "rust-intrinsic" {
-    pub fn transmute<Src, Dst>(src: Src) -> Dst;
-}
+#[rustc_intrinsic]
+pub unsafe fn transmute<Src, Dst>(src: Src) -> Dst;
 
 pub static mut STORAGE_FOO: fn(&usize, &mut u32) -> Result<(), ()> = arbitrary_black_box;
 pub static mut STORAGE_BAR: u32 = 12;
diff --git a/tests/codegen/emscripten-catch-unwind-js-eh.rs b/tests/codegen/emscripten-catch-unwind-js-eh.rs
index 018ad5454fc..3ab4b5c9c63 100644
--- a/tests/codegen/emscripten-catch-unwind-js-eh.rs
+++ b/tests/codegen/emscripten-catch-unwind-js-eh.rs
@@ -23,13 +23,12 @@ fn size_of<T>() -> usize {
     loop {}
 }
 
-extern "rust-intrinsic" {
-    fn catch_unwind(
-        try_fn: fn(_: *mut u8),
-        data: *mut u8,
-        catch_fn: fn(_: *mut u8, _: *mut u8),
-    ) -> i32;
-}
+#[rustc_intrinsic]
+unsafe fn catch_unwind(
+    try_fn: fn(_: *mut u8),
+    data: *mut u8,
+    catch_fn: fn(_: *mut u8, _: *mut u8),
+) -> i32;
 
 // CHECK-LABEL: @ptr_size
 #[no_mangle]
diff --git a/tests/codegen/emscripten-catch-unwind-wasm-eh.rs b/tests/codegen/emscripten-catch-unwind-wasm-eh.rs
index 0fc9ae96720..d0571e4df08 100644
--- a/tests/codegen/emscripten-catch-unwind-wasm-eh.rs
+++ b/tests/codegen/emscripten-catch-unwind-wasm-eh.rs
@@ -21,14 +21,12 @@ impl<T> Copy for *mut T {}
 fn size_of<T>() -> usize {
     loop {}
 }
-
-extern "rust-intrinsic" {
-    fn catch_unwind(
-        try_fn: fn(_: *mut u8),
-        data: *mut u8,
-        catch_fn: fn(_: *mut u8, _: *mut u8),
-    ) -> i32;
-}
+#[rustc_intrinsic]
+unsafe fn catch_unwind(
+    try_fn: fn(_: *mut u8),
+    data: *mut u8,
+    catch_fn: fn(_: *mut u8, _: *mut u8),
+) -> i32;
 
 // CHECK-LABEL: @ptr_size
 #[no_mangle]
diff --git a/tests/codegen/intrinsic-no-unnamed-attr.rs b/tests/codegen/intrinsic-no-unnamed-attr.rs
index fce0de80d7b..35eb025ab6b 100644
--- a/tests/codegen/intrinsic-no-unnamed-attr.rs
+++ b/tests/codegen/intrinsic-no-unnamed-attr.rs
@@ -2,9 +2,9 @@
 
 #![feature(intrinsics)]
 
-extern "rust-intrinsic" {
-    fn sqrtf32(x: f32) -> f32;
-}
+#[rustc_intrinsic]
+unsafe fn sqrtf32(x: f32) -> f32;
+
 // CHECK: @llvm.sqrt.f32(float) #{{[0-9]*}}
 
 fn main() {
diff --git a/tests/codegen/intrinsics/nontemporal.rs b/tests/codegen/intrinsics/nontemporal.rs
index 1d4fae83c29..a151d4bd297 100644
--- a/tests/codegen/intrinsics/nontemporal.rs
+++ b/tests/codegen/intrinsics/nontemporal.rs
@@ -18,9 +18,8 @@
 extern crate minicore;
 use minicore::*;
 
-extern "rust-intrinsic" {
-    pub fn nontemporal_store<T>(ptr: *mut T, val: T);
-}
+#[rustc_intrinsic]
+pub unsafe fn nontemporal_store<T>(ptr: *mut T, val: T);
 
 #[no_mangle]
 pub fn a(a: &mut u32, b: u32) {