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 21, 2024
1 parent a7c84cf commit 8e9dd83
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 @@ -1275,6 +1275,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 @@ -1361,7 +1368,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 8e9dd83

Please sign in to comment.