Skip to content

Commit 26362fb

Browse files
committed
mir_transform: prohibit scalable vectors in async
Scalable vectors cannot be members of ADTs and thus cannot be kept over await points in async functions.
1 parent 080b5de commit 26362fb

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,11 @@ fn check_must_not_suspend_ty<'tcx>(
18561856
SuspendCheckData { descr_pre: &format!("{}allocator ", data.descr_pre), ..data },
18571857
)
18581858
}
1859+
ty::Adt(def, _) if def.repr().scalable() => {
1860+
tcx.dcx()
1861+
.span_err(data.source_span, "scalable vectors cannot be held over await points");
1862+
true
1863+
}
18591864
ty::Adt(def, _) => check_must_not_suspend_def(tcx, def.did(), hir_id, data),
18601865
// FIXME: support adding the attribute to TAITs
18611866
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {

tests/ui/simd/scalable/async.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//@ only-aarch64
2+
//@ edition:2021
3+
4+
#![allow(incomplete_features, internal_features)]
5+
#![feature(
6+
core_intrinsics,
7+
repr_simd,
8+
repr_scalable,
9+
simd_ffi,
10+
link_llvm_intrinsics
11+
)]
12+
13+
use core::intrinsics::simd::simd_reinterpret;
14+
15+
#[repr(simd, scalable(4))]
16+
#[allow(non_camel_case_types)]
17+
pub struct svint32_t {
18+
_ty: [i32],
19+
}
20+
21+
#[target_feature(enable = "sve")]
22+
pub unsafe fn svdup_n_s32(op: i32) -> svint32_t {
23+
extern "C" {
24+
#[cfg_attr(target_arch = "aarch64", link_name = "llvm.aarch64.sve.dup.x.nxv4i32")]
25+
fn _svdup_n_s32(op: i32) -> svint32_t;
26+
}
27+
unsafe { _svdup_n_s32(op) }
28+
}
29+
30+
async fn another() -> i32 {
31+
42
32+
}
33+
34+
#[no_mangle]
35+
pub async fn test_function() {
36+
unsafe {
37+
let x = svdup_n_s32(1); //~ ERROR: scalable vectors cannot be held over await points
38+
let temp = another().await;
39+
let y: svint32_t = simd_reinterpret(x);
40+
}
41+
}
42+
43+
fn main() {
44+
let _ = test_function();
45+
}

tests/ui/simd/scalable/async.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: scalable vectors cannot be held over await points
2+
--> $DIR/async.rs:37:13
3+
|
4+
LL | let x = svdup_n_s32(1);
5+
| ^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)