about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-21 19:48:22 +0000
committerbors <bors@rust-lang.org>2025-07-21 19:48:22 +0000
commit9748d87dc70a9a6725c5dbd76ce29d04752b4f90 (patch)
tree4cffbc92abe5995b0348e464ffe6a256f973e653 /tests/codegen
parent3f9f20f71dd945fe7d044e274094a53c90788269 (diff)
parent6628a4afb5d08555f09878a48f0c4179e7582aa2 (diff)
downloadrust-9748d87dc70a9a6725c5dbd76ce29d04752b4f90.tar.gz
rust-9748d87dc70a9a6725c5dbd76ce29d04752b4f90.zip
Auto merge of #144269 - jieyouxu:rollup-137ysl2, r=jieyouxu
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#142097 (gpu offload host code generation)
 - rust-lang/rust#143430 (Lower extra lifetimes before normal generic params.)
 - rust-lang/rust#143768 (Constify Try, From, TryFrom and relevant traits)
 - rust-lang/rust#143816 (Implement `check` for compiletest and RA using tool macro)
 - rust-lang/rust#143985 (rustc_public: de-StableMIR-ize)
 - rust-lang/rust#144027 (clippy: make tests work in stage 1)
 - rust-lang/rust#144080 (Mitigate `#[align]` name resolution ambiguity regression with a rename)
 - rust-lang/rust#144176 (Add approval blocking labels for new bors)
 - rust-lang/rust#144187 (fix handling of base address for TypeId allocations)
 - rust-lang/rust#144212 (Remove the ptr_unique lang item)
 - rust-lang/rust#144243 (Subtree update of `rust-analyzer`)
 - rust-lang/rust#144246 (Don't use another main test file as auxiliary)
 - rust-lang/rust#144251 (rustc-dev-guide subtree update)
 - rust-lang/rust#144254 (opt-dist: make `artifact-dir` an absolute path for `opt-dist local`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/align-fn.rs54
-rw-r--r--tests/codegen/gpu_offload/gpu_host.rs80
-rw-r--r--tests/codegen/min-function-alignment.rs6
-rw-r--r--tests/codegen/naked-fn/aligned.rs5
-rw-r--r--tests/codegen/naked-fn/min-function-alignment.rs6
5 files changed, 120 insertions, 31 deletions
diff --git a/tests/codegen/align-fn.rs b/tests/codegen/align-fn.rs
index fd572910c28..cbc24e2ae2e 100644
--- a/tests/codegen/align-fn.rs
+++ b/tests/codegen/align-fn.rs
@@ -3,11 +3,13 @@
 //@ ignore-wasm32 aligning functions is not currently supported on wasm (#143368)
 
 #![crate_type = "lib"]
+// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
+#![feature(rustc_attrs)]
 #![feature(fn_align)]
 
 // CHECK: align 16
 #[unsafe(no_mangle)]
-#[align(16)]
+#[rustc_align(16)]
 pub fn fn_align() {}
 
 pub struct A;
@@ -15,12 +17,12 @@ pub struct A;
 impl A {
     // CHECK: align 16
     #[unsafe(no_mangle)]
-    #[align(16)]
+    #[rustc_align(16)]
     pub fn method_align(self) {}
 
     // CHECK: align 16
     #[unsafe(no_mangle)]
-    #[align(16)]
+    #[rustc_align(16)]
     pub fn associated_fn() {}
 }
 
@@ -29,18 +31,18 @@ trait T: Sized {
 
     fn trait_method(self) {}
 
-    #[align(8)]
+    #[rustc_align(8)]
     fn trait_method_inherit_low(self);
 
-    #[align(32)]
+    #[rustc_align(32)]
     fn trait_method_inherit_high(self);
 
-    #[align(32)]
+    #[rustc_align(32)]
     fn trait_method_inherit_default(self) {}
 
-    #[align(4)]
-    #[align(128)]
-    #[align(8)]
+    #[rustc_align(4)]
+    #[rustc_align(128)]
+    #[rustc_align(8)]
     fn inherit_highest(self) {}
 }
 
@@ -48,27 +50,27 @@ impl T for A {
     // CHECK-LABEL: trait_fn
     // CHECK-SAME: align 16
     #[unsafe(no_mangle)]
-    #[align(16)]
+    #[rustc_align(16)]
     fn trait_fn() {}
 
     // CHECK-LABEL: trait_method
     // CHECK-SAME: align 16
     #[unsafe(no_mangle)]
-    #[align(16)]
+    #[rustc_align(16)]
     fn trait_method(self) {}
 
     // The prototype's align is ignored because the align here is higher.
     // CHECK-LABEL: trait_method_inherit_low
     // CHECK-SAME: align 16
     #[unsafe(no_mangle)]
-    #[align(16)]
+    #[rustc_align(16)]
     fn trait_method_inherit_low(self) {}
 
     // The prototype's align is used because it is higher.
     // CHECK-LABEL: trait_method_inherit_high
     // CHECK-SAME: align 32
     #[unsafe(no_mangle)]
-    #[align(16)]
+    #[rustc_align(16)]
     fn trait_method_inherit_high(self) {}
 
     // The prototype's align inherited.
@@ -81,8 +83,8 @@ impl T for A {
     // CHECK-LABEL: inherit_highest
     // CHECK-SAME: align 128
     #[unsafe(no_mangle)]
-    #[align(32)]
-    #[align(64)]
+    #[rustc_align(32)]
+    #[rustc_align(64)]
     fn inherit_highest(self) {}
 }
 
@@ -90,7 +92,7 @@ trait HasDefaultImpl: Sized {
     // CHECK-LABEL: inherit_from_default_method
     // CHECK-LABEL: inherit_from_default_method
     // CHECK-SAME: align 32
-    #[align(32)]
+    #[rustc_align(32)]
     fn inherit_from_default_method(self) {}
 }
 
@@ -101,35 +103,35 @@ impl HasDefaultImpl for InstantiateDefaultMethods {}
 // CHECK-LABEL: align_specified_twice_1
 // CHECK-SAME: align 64
 #[unsafe(no_mangle)]
-#[align(32)]
-#[align(64)]
+#[rustc_align(32)]
+#[rustc_align(64)]
 pub fn align_specified_twice_1() {}
 
 // CHECK-LABEL: align_specified_twice_2
 // CHECK-SAME: align 128
 #[unsafe(no_mangle)]
-#[align(128)]
-#[align(32)]
+#[rustc_align(128)]
+#[rustc_align(32)]
 pub fn align_specified_twice_2() {}
 
 // CHECK-LABEL: align_specified_twice_3
 // CHECK-SAME: align 256
 #[unsafe(no_mangle)]
-#[align(32)]
-#[align(256)]
+#[rustc_align(32)]
+#[rustc_align(256)]
 pub fn align_specified_twice_3() {}
 
 const _: () = {
     // CHECK-LABEL: align_unmangled
     // CHECK-SAME: align 256
     #[unsafe(no_mangle)]
-    #[align(32)]
-    #[align(256)]
+    #[rustc_align(32)]
+    #[rustc_align(256)]
     extern "C" fn align_unmangled() {}
 };
 
 unsafe extern "C" {
-    #[align(256)]
+    #[rustc_align(256)]
     fn align_unmangled();
 }
 
@@ -137,5 +139,5 @@ unsafe extern "C" {
 // CHECK-LABEL: async_align
 // CHECK-SAME: align 64
 #[unsafe(no_mangle)]
-#[align(64)]
+#[rustc_align(64)]
 pub async fn async_align() {}
diff --git a/tests/codegen/gpu_offload/gpu_host.rs b/tests/codegen/gpu_offload/gpu_host.rs
new file mode 100644
index 00000000000..513e27426bc
--- /dev/null
+++ b/tests/codegen/gpu_offload/gpu_host.rs
@@ -0,0 +1,80 @@
+//@ compile-flags: -Zoffload=Enable -Zunstable-options -C opt-level=3  -Clto=fat
+//@ no-prefer-dynamic
+//@ needs-enzyme
+
+// This test is verifying that we generate __tgt_target_data_*_mapper before and after a call to the
+// kernel_1. Better documentation to what each global or variable means is available in the gpu
+// offlaod code, or the LLVM offload documentation. This code does not launch any GPU kernels yet,
+// and will be rewritten once a proper offload frontend has landed.
+//
+// We currently only handle memory transfer for specific calls to functions named `kernel_{num}`,
+// when inside of a function called main. This, too, is a temporary workaround for not having a
+// frontend.
+
+#![no_main]
+
+#[unsafe(no_mangle)]
+fn main() {
+    let mut x = [3.0; 256];
+    kernel_1(&mut x);
+    core::hint::black_box(&x);
+}
+
+// CHECK: %struct.__tgt_offload_entry = type { i64, i16, i16, i32, ptr, ptr, i64, i64, ptr }
+// CHECK: %struct.__tgt_kernel_arguments = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, [3 x i32], [3 x i32], i32 }
+// CHECK: %struct.ident_t = type { i32, i32, i32, i32, ptr }
+// CHECK: %struct.__tgt_bin_desc = type { i32, ptr, ptr, ptr }
+
+// CHECK: @.offload_sizes.1 = private unnamed_addr constant [1 x i64] [i64 1024]
+// CHECK: @.offload_maptypes.1 = private unnamed_addr constant [1 x i64] [i64 3]
+// CHECK: @.kernel_1.region_id = weak unnamed_addr constant i8 0
+// CHECK: @.offloading.entry_name.1 = internal unnamed_addr constant [9 x i8] c"kernel_1\00", section ".llvm.rodata.offloading", align 1
+// CHECK: @.offloading.entry.kernel_1 = weak constant %struct.__tgt_offload_entry { i64 0, i16 1, i16 1, i32 0, ptr @.kernel_1.region_id, ptr @.offloading.entry_name.1, i64 0, i64 0, ptr null }, section ".omp_offloading_entries", align 1
+// CHECK: @my_struct_global2 = external global %struct.__tgt_kernel_arguments
+// CHECK: @0 = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00", align 1
+// CHECK: @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @0 }, align 8
+
+// CHECK:  Function Attrs:
+// CHECK-NEXT: define{{( dso_local)?}} void @main()
+// CHECK-NEXT: start:
+// CHECK-NEXT:   %0 = alloca [8 x i8], align 8
+// CHECK-NEXT:   %x = alloca [1024 x i8], align 16
+// CHECK-NEXT:   %EmptyDesc = alloca %struct.__tgt_bin_desc, align 8
+// CHECK-NEXT:   %.offload_baseptrs = alloca [1 x ptr], align 8
+// CHECK-NEXT:   %.offload_ptrs = alloca [1 x ptr], align 8
+// CHECK-NEXT:   %.offload_sizes = alloca [1 x i64], align 8
+// CHECK-NEXT:   %x.addr = alloca ptr, align 8
+// CHECK-NEXT:   store ptr %x, ptr %x.addr, align 8
+// CHECK-NEXT:   %1 = load ptr, ptr %x.addr, align 8
+// CHECK-NEXT:   %2 = getelementptr inbounds float, ptr %1, i32 0
+// CHECK:        call void @llvm.memset.p0.i64(ptr align 8 %EmptyDesc, i8 0, i64 32, i1 false)
+// CHECK-NEXT:   call void @__tgt_register_lib(ptr %EmptyDesc)
+// CHECK-NEXT:   call void @__tgt_init_all_rtls()
+// CHECK-NEXT:   %3 = getelementptr inbounds [1 x ptr], ptr %.offload_baseptrs, i32 0, i32 0
+// CHECK-NEXT:   store ptr %1, ptr %3, align 8
+// CHECK-NEXT:   %4 = getelementptr inbounds [1 x ptr], ptr %.offload_ptrs, i32 0, i32 0
+// CHECK-NEXT:   store ptr %2, ptr %4, align 8
+// CHECK-NEXT:   %5 = getelementptr inbounds [1 x i64], ptr %.offload_sizes, i32 0, i32 0
+// CHECK-NEXT:   store i64 1024, ptr %5, align 8
+// CHECK-NEXT:   %6 = getelementptr inbounds [1 x ptr], ptr %.offload_baseptrs, i32 0, i32 0
+// CHECK-NEXT:   %7 = getelementptr inbounds [1 x ptr], ptr %.offload_ptrs, i32 0, i32 0
+// CHECK-NEXT:   %8 = getelementptr inbounds [1 x i64], ptr %.offload_sizes, i32 0, i32 0
+// CHECK-NEXT:   call void @__tgt_target_data_begin_mapper(ptr @1, i64 -1, i32 1, ptr %6, ptr %7, ptr %8, ptr @.offload_maptypes.1, ptr null, ptr null)
+// CHECK-NEXT:   call void @kernel_1(ptr noalias noundef nonnull align 4 dereferenceable(1024) %x)
+// CHECK-NEXT:   %9 = getelementptr inbounds [1 x ptr], ptr %.offload_baseptrs, i32 0, i32 0
+// CHECK-NEXT:   %10 = getelementptr inbounds [1 x ptr], ptr %.offload_ptrs, i32 0, i32 0
+// CHECK-NEXT:   %11 = getelementptr inbounds [1 x i64], ptr %.offload_sizes, i32 0, i32 0
+// CHECK-NEXT:   call void @__tgt_target_data_end_mapper(ptr @1, i64 -1, i32 1, ptr %9, ptr %10, ptr %11, ptr @.offload_maptypes.1, ptr null, ptr null)
+// CHECK-NEXT:   call void @__tgt_unregister_lib(ptr %EmptyDesc)
+// CHECK:        store ptr %x, ptr %0, align 8
+// CHECK-NEXT:   call void asm sideeffect "", "r,~{memory}"(ptr nonnull %0)
+// CHECK:        ret void
+// CHECK-NEXT: }
+
+#[unsafe(no_mangle)]
+#[inline(never)]
+pub fn kernel_1(x: &mut [f32; 256]) {
+    for i in 0..256 {
+        x[i] = 21.0;
+    }
+}
diff --git a/tests/codegen/min-function-alignment.rs b/tests/codegen/min-function-alignment.rs
index 6a3843b0f4f..ea5f957e81f 100644
--- a/tests/codegen/min-function-alignment.rs
+++ b/tests/codegen/min-function-alignment.rs
@@ -5,6 +5,8 @@
 //@ ignore-wasm32 aligning functions is not currently supported on wasm (#143368)
 
 #![crate_type = "lib"]
+// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
+#![feature(rustc_attrs)]
 #![feature(fn_align)]
 
 // Functions without explicit alignment use the global minimum.
@@ -21,7 +23,7 @@ pub fn no_explicit_align() {}
 // align16: align 16
 // align1024: align 1024
 #[no_mangle]
-#[align(8)]
+#[rustc_align(8)]
 pub fn lower_align() {}
 
 // the higher value of min-function-alignment and the align attribute wins out
@@ -30,7 +32,7 @@ pub fn lower_align() {}
 // align16: align 32
 // align1024: align 1024
 #[no_mangle]
-#[align(32)]
+#[rustc_align(32)]
 pub fn higher_align() {}
 
 // cold functions follow the same rules as other functions
diff --git a/tests/codegen/naked-fn/aligned.rs b/tests/codegen/naked-fn/aligned.rs
index 2648b0213ca..d7281c4219a 100644
--- a/tests/codegen/naked-fn/aligned.rs
+++ b/tests/codegen/naked-fn/aligned.rs
@@ -4,12 +4,15 @@
 //@ ignore-wasm32 aligning functions is not currently supported on wasm (#143368)
 
 #![crate_type = "lib"]
+// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
+#![feature(rustc_attrs)]
 #![feature(fn_align)]
+
 use std::arch::naked_asm;
 
 // CHECK: .balign 16
 // CHECK-LABEL: naked_empty:
-#[align(16)]
+#[rustc_align(16)]
 #[no_mangle]
 #[unsafe(naked)]
 pub extern "C" fn naked_empty() {
diff --git a/tests/codegen/naked-fn/min-function-alignment.rs b/tests/codegen/naked-fn/min-function-alignment.rs
index 4ebaacd3eff..406e9334fa5 100644
--- a/tests/codegen/naked-fn/min-function-alignment.rs
+++ b/tests/codegen/naked-fn/min-function-alignment.rs
@@ -3,6 +3,8 @@
 //@ ignore-arm no "ret" mnemonic
 //@ ignore-wasm32 aligning functions is not currently supported on wasm (#143368)
 
+// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
+#![feature(rustc_attrs)]
 #![feature(fn_align)]
 #![crate_type = "lib"]
 
@@ -17,7 +19,7 @@ pub extern "C" fn naked_no_explicit_align() {
 
 // CHECK: .balign 16
 #[no_mangle]
-#[align(8)]
+#[rustc_align(8)]
 #[unsafe(naked)]
 pub extern "C" fn naked_lower_align() {
     core::arch::naked_asm!("ret")
@@ -25,7 +27,7 @@ pub extern "C" fn naked_lower_align() {
 
 // CHECK: .balign 32
 #[no_mangle]
-#[align(32)]
+#[rustc_align(32)]
 #[unsafe(naked)]
 pub extern "C" fn naked_higher_align() {
     core::arch::naked_asm!("ret")