From 7834ffbebe48d05848985634975f543d96cd6145 Mon Sep 17 00:00:00 2001 From: lena Date: Wed, 9 Aug 2023 22:06:46 +0200 Subject: [PATCH] fix #114275 this ICE was caused by `transform_ty` in compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs encountering an unevaluated const, while expecting it to already be evaluated. add a regression test Update tests/ui/sanitize/issue-114275-cfi-const-expr-in-arry-len.rs Co-authored-by: Michael Goulet Update tests/ui/sanitize/issue-114275-cfi-const-expr-in-arry-len.rs Co-authored-by: Michael Goulet fix test compiling for targets with -crt-static and failing this was causign https://github.com/rust-lang/rust/pull/114686 to fail --- .../src/typeid/typeid_itanium_cxx_abi.rs | 7 ++----- .../issue-114275-cfi-const-expr-in-arry-len.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 tests/ui/sanitize/issue-114275-cfi-const-expr-in-arry-len.rs 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 845b5791161..d345368d552 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 @@ -824,11 +824,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio } ty::Array(ty0, len) => { - let len = len - .try_to_scalar() - .unwrap() - .to_u64() - .unwrap_or_else(|_| panic!("failed to convert length to u64")); + let len = len.eval_target_usize(tcx, ty::ParamEnv::reveal_all()); + ty = Ty::new_array(tcx, transform_ty(tcx, *ty0, options), len); } diff --git a/tests/ui/sanitize/issue-114275-cfi-const-expr-in-arry-len.rs b/tests/ui/sanitize/issue-114275-cfi-const-expr-in-arry-len.rs new file mode 100644 index 00000000000..8f870be1372 --- /dev/null +++ b/tests/ui/sanitize/issue-114275-cfi-const-expr-in-arry-len.rs @@ -0,0 +1,15 @@ +// Regression test for issue 114275 `typeid::typeid_itanium_cxx_abi::transform_ty` +// was expecting array type lengths to be evaluated, this was causing an ICE. +// +// build-pass +// compile-flags: -Ccodegen-units=1 -Clto -Zsanitizer=cfi -Ctarget-feature=-crt-static +// needs-sanitizer-cfi + +#![crate_type = "lib"] + +#[repr(transparent)] +pub struct Array([u8; 1 * 1]); + +pub extern "C" fn array() -> Array { + loop {} +}