Skip to content

Commit 3ce4204

Browse files
committed
CFI: Fix encode_ty: unexpected 'CoroutineWitness'
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
1 parent 9841385 commit 3ce4204

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,13 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
12761276
);
12771277
}
12781278

1279+
ty::CoroutineClosure(_, args) => {
1280+
// Transform async closures into function pointers
1281+
let fn_ptr = args.as_coroutine_closure().signature_parts_ty();
1282+
// Transform fn_sig inputs and output
1283+
ty = transform_ty(tcx, fn_ptr, options);
1284+
}
1285+
12791286
ty::Ref(region, ty0, ..) => {
12801287
// Remove references from function items, closures, and Fn trait objects
12811288
if ty0.is_fn_def() || ty0.is_closure() || is_dynamic_fn_trait(tcx, *ty0) {
@@ -1362,7 +1369,6 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
13621369

13631370
ty::Bound(..)
13641371
| ty::Error(..)
1365-
| ty::CoroutineClosure(..)
13661372
| ty::CoroutineWitness(..)
13671373
| ty::Infer(..)
13681374
| ty::Placeholder(..) => {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Verifies that using async closure works.
2+
//
3+
//@ needs-sanitizer-cfi
4+
//@ compile-flags: -Clto -Cprefer-dynamic=off -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 --edition=2021
5+
//@ run-pass
6+
7+
#![feature(async_closure)]
8+
9+
#[inline(never)]
10+
fn foo<T>(_: T) {}
11+
12+
fn main() {
13+
let a = async move |_: i32, _: i32| {};
14+
foo(a);
15+
}

0 commit comments

Comments
 (0)