Skip to content

Commit

Permalink
CFI: Fix encode_ty: unexpected 'CoroutineWitness'
Browse files Browse the repository at this point in the history
Fix rust-lang#122705 by adding support for encoding `ty:CoroutineClosure`.
  • Loading branch information
rcvalle committed Mar 22, 2024
1 parent 9841385 commit 3ce4204
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,13 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
);
}

ty::CoroutineClosure(_, args) => {
// Transform async closures into function pointers
let fn_ptr = args.as_coroutine_closure().signature_parts_ty();
// Transform fn_sig inputs and output
ty = transform_ty(tcx, fn_ptr, options);
}

ty::Ref(region, ty0, ..) => {
// Remove references from function items, closures, and Fn trait objects
if ty0.is_fn_def() || ty0.is_closure() || is_dynamic_fn_trait(tcx, *ty0) {
Expand Down Expand Up @@ -1362,7 +1369,6 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio

ty::Bound(..)
| ty::Error(..)
| ty::CoroutineClosure(..)
| ty::CoroutineWitness(..)
| ty::Infer(..)
| ty::Placeholder(..) => {
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/sanitizer/cfi-async-closure-issue-122705.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Verifies that using async closure works.
//
//@ needs-sanitizer-cfi
//@ compile-flags: -Clto -Cprefer-dynamic=off -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0 --edition=2021
//@ run-pass

#![feature(async_closure)]

#[inline(never)]
fn foo<T>(_: T) {}

fn main() {
let a = async move |_: i32, _: i32| {};
foo(a);
}

0 comments on commit 3ce4204

Please sign in to comment.