Skip to content

Commit 3e8c2eb

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

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,13 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
13501350
ty = transform_ty(tcx, fn_ptr, options);
13511351
}
13521352

1353+
ty::CoroutineClosure(_, args) => {
1354+
// Transform async closures into function pointers
1355+
let fn_ptr = args.as_coroutine_closure().signature_parts_ty();
1356+
// Transform fn_sig inputs and output
1357+
ty = transform_ty(tcx, fn_ptr, options);
1358+
}
1359+
13531360
ty::Ref(region, ty0, ..) => {
13541361
// Remove references from function items, closures, Fn trait and Fn subtrait objects
13551362
if ty0.is_fn_def()
@@ -1440,7 +1447,6 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
14401447

14411448
ty::Bound(..)
14421449
| ty::Error(..)
1443-
| ty::CoroutineClosure(..)
14441450
| ty::CoroutineWitness(..)
14451451
| ty::Infer(..)
14461452
| ty::Placeholder(..) => {
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)