Skip to content

Commit ceec225

Browse files
Rollup merge of rust-lang#111914 - rcvalle:rust-cfi-fix-111184, r=compiler-errors
CFI: Fix cfi with async: transform_ty: unexpected GeneratorWitness(Bi… Fixes rust-lang#111184 by encoding ty::Generator parent substs only.
2 parents 24404e6 + 76ff5ec commit ceec225

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,7 @@ fn encode_ty<'tcx>(
601601
}
602602

603603
// Function types
604-
ty::FnDef(def_id, substs)
605-
| ty::Closure(def_id, substs)
606-
| ty::Generator(def_id, substs, ..) => {
604+
ty::FnDef(def_id, substs) | ty::Closure(def_id, substs) => {
607605
// u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>,
608606
// as vendor extended type.
609607
let mut s = String::new();
@@ -614,6 +612,23 @@ fn encode_ty<'tcx>(
614612
typeid.push_str(&s);
615613
}
616614

615+
ty::Generator(def_id, substs, ..) => {
616+
// u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>,
617+
// as vendor extended type.
618+
let mut s = String::new();
619+
let name = encode_ty_name(tcx, *def_id);
620+
let _ = write!(s, "u{}{}", name.len(), &name);
621+
// Encode parent substs only
622+
s.push_str(&encode_substs(
623+
tcx,
624+
tcx.mk_substs(substs.as_generator().parent_substs()),
625+
dict,
626+
options,
627+
));
628+
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
629+
typeid.push_str(&s);
630+
}
631+
617632
// Pointer types
618633
ty::Ref(region, ty0, ..) => {
619634
// [U3mut]u3refI<element-type>E as vendor extended type qualifier and type
@@ -732,7 +747,12 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
732747
let mut ty = ty;
733748

734749
match ty.kind() {
735-
ty::Float(..) | ty::Char | ty::Str | ty::Never | ty::Foreign(..) => {}
750+
ty::Float(..)
751+
| ty::Char
752+
| ty::Str
753+
| ty::Never
754+
| ty::Foreign(..)
755+
| ty::GeneratorWitness(..) => {}
736756

737757
ty::Bool => {
738758
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
@@ -915,7 +935,6 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
915935

916936
ty::Bound(..)
917937
| ty::Error(..)
918-
| ty::GeneratorWitness(..)
919938
| ty::GeneratorWitnessMIR(..)
920939
| ty::Infer(..)
921940
| ty::Alias(..)
Lines changed: 17 additions & 0 deletions
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)