Skip to content

Commit 53ed526

Browse files
committed
CFI: Fix encode_ty: unexpected 'CoroutineWitness'
Fix #122705 by adding support for encoding `ty:CoroutineClosure`.
1 parent 6eabc40 commit 53ed526

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

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

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

14401447
ty::Bound(..)
14411448
| ty::Error(..)
1442-
| ty::CoroutineClosure(..)
14431449
| ty::CoroutineWitness(..)
14441450
| ty::Infer(..)
14451451
| ty::Placeholder(..) => {

Diff for: tests/ui/sanitizer/cfi-async-closure-issue-122705.rs

+15
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)