Skip to content

Commit 86e1b7f

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 1edd4a7 commit 86e1b7f

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-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/scalable-vectors/async.rs

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