diff options
| author | Michael Goulet <michael@errs.io> | 2023-06-01 23:07:37 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-01 23:07:37 -0700 |
| commit | ceec2250a361ee3f84ba225bdbd882e0df859441 (patch) | |
| tree | 749f96e7382a4e1fab28b98687c52875ce44f0f6 | |
| parent | 24404e6409c0eb824bd7fe8204a2155a29d74887 (diff) | |
| parent | 76ff5ec88624ea61ae49b728ce4d382df8fb7fe3 (diff) | |
| download | rust-ceec2250a361ee3f84ba225bdbd882e0df859441.tar.gz rust-ceec2250a361ee3f84ba225bdbd882e0df859441.zip | |
Rollup merge of #111914 - rcvalle:rust-cfi-fix-111184, r=compiler-errors
CFI: Fix cfi with async: transform_ty: unexpected GeneratorWitness(Bi… Fixes https://github.com/rust-lang/rust/issues/111184 by encoding ty::Generator parent substs only.
| -rw-r--r-- | compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs | 29 | ||||
| -rw-r--r-- | tests/ui/sanitize/issue-111184-generator-witness.rs | 17 |
2 files changed, 41 insertions, 5 deletions
diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index b245742e533..497131ea79d 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -601,9 +601,7 @@ fn encode_ty<'tcx>( } // Function types - ty::FnDef(def_id, substs) - | ty::Closure(def_id, substs) - | ty::Generator(def_id, substs, ..) => { + ty::FnDef(def_id, substs) | ty::Closure(def_id, substs) => { // u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>, // as vendor extended type. let mut s = String::new(); @@ -614,6 +612,23 @@ fn encode_ty<'tcx>( typeid.push_str(&s); } + ty::Generator(def_id, substs, ..) => { + // u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>, + // as vendor extended type. + let mut s = String::new(); + let name = encode_ty_name(tcx, *def_id); + let _ = write!(s, "u{}{}", name.len(), &name); + // Encode parent substs only + s.push_str(&encode_substs( + tcx, + tcx.mk_substs(substs.as_generator().parent_substs()), + dict, + options, + )); + compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); + typeid.push_str(&s); + } + // Pointer types ty::Ref(region, ty0, ..) => { // [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 let mut ty = ty; match ty.kind() { - ty::Float(..) | ty::Char | ty::Str | ty::Never | ty::Foreign(..) => {} + ty::Float(..) + | ty::Char + | ty::Str + | ty::Never + | ty::Foreign(..) + | ty::GeneratorWitness(..) => {} ty::Bool => { if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) { @@ -915,7 +935,6 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio ty::Bound(..) | ty::Error(..) - | ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) | ty::Infer(..) | ty::Alias(..) diff --git a/tests/ui/sanitize/issue-111184-generator-witness.rs b/tests/ui/sanitize/issue-111184-generator-witness.rs new file mode 100644 index 00000000000..8f4118057ce --- /dev/null +++ b/tests/ui/sanitize/issue-111184-generator-witness.rs @@ -0,0 +1,17 @@ +// Regression test for issue 111184, where ty::GeneratorWitness were not expected to occur in +// encode_ty and caused the compiler to ICE. +// +// needs-sanitizer-cfi +// compile-flags: -Clto -Ctarget-feature=-crt-static -Zsanitizer=cfi --edition=2021 +// no-prefer-dynamic +// only-x86_64-unknown-linux-gnu +// run-pass + +use std::future::Future; + +async fn foo() {} +fn bar<T>(_: impl Future<Output = T>) {} + +fn main() { + bar(foo()); +} |
