Skip to content

Commit 76ff5ec

Browse files
committed
CFI: Fix cfi with async: transform_ty: unexpected GeneratorWitness(Binde
Fixes #111184 by encoding ty::Generator parent substs only.
1 parent d569987 commit 76ff5ec

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+24-5
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,7 @@ fn encode_ty<'tcx>(
608608
}
609609

610610
// Function types
611-
ty::FnDef(def_id, substs)
612-
| ty::Closure(def_id, substs)
613-
| ty::Generator(def_id, substs, ..) => {
611+
ty::FnDef(def_id, substs) | ty::Closure(def_id, substs) => {
614612
// u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>,
615613
// as vendor extended type.
616614
let mut s = String::new();
@@ -621,6 +619,23 @@ fn encode_ty<'tcx>(
621619
typeid.push_str(&s);
622620
}
623621

622+
ty::Generator(def_id, substs, ..) => {
623+
// u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>,
624+
// as vendor extended type.
625+
let mut s = String::new();
626+
let name = encode_ty_name(tcx, *def_id);
627+
let _ = write!(s, "u{}{}", name.len(), &name);
628+
// Encode parent substs only
629+
s.push_str(&encode_substs(
630+
tcx,
631+
tcx.mk_substs(substs.as_generator().parent_substs()),
632+
dict,
633+
options,
634+
));
635+
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
636+
typeid.push_str(&s);
637+
}
638+
624639
// Pointer types
625640
ty::Ref(region, ty0, ..) => {
626641
// [U3mut]u3refI<element-type>E as vendor extended type qualifier and type
@@ -739,7 +754,12 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
739754
let mut ty = ty;
740755

741756
match ty.kind() {
742-
ty::Float(..) | ty::Char | ty::Str | ty::Never | ty::Foreign(..) => {}
757+
ty::Float(..)
758+
| ty::Char
759+
| ty::Str
760+
| ty::Never
761+
| ty::Foreign(..)
762+
| ty::GeneratorWitness(..) => {}
743763

744764
ty::Bool => {
745765
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
@@ -922,7 +942,6 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
922942

923943
ty::Bound(..)
924944
| ty::Error(..)
925-
| ty::GeneratorWitness(..)
926945
| ty::GeneratorWitnessMIR(..)
927946
| ty::Infer(..)
928947
| ty::Alias(..)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Regression test for issue 111184, where ty::GeneratorWitness were not expected to occur in
2+
// encode_ty and caused the compiler to ICE.
3+
//
4+
// needs-sanitizer-cfi
5+
// compile-flags: -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi --edition=2021
6+
// no-prefer-dynamic
7+
// only-x86_64-unknown-linux-gnu
8+
// run-pass
9+
10+
use std::future::Future;
11+
12+
async fn foo() {}
13+
fn bar<T>(_: impl Future<Output = T>) {}
14+
15+
fn main() {
16+
bar(foo());
17+
}

0 commit comments

Comments
 (0)