-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix ICE in CMSE type validation #130064
fix ICE in CMSE type validation #130064
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,9 @@ pub(crate) fn validate_cmse_abi<'tcx>( | |||||||||||||||
abi: abi::Abi, | ||||||||||||||||
fn_sig: ty::PolyFnSig<'tcx>, | ||||||||||||||||
) { | ||||||||||||||||
// this type is only used for layout computation, which does not rely on regions | ||||||||||||||||
let fn_sig = tcx.instantiate_bound_regions_with_erased(fn_sig); | ||||||||||||||||
|
||||||||||||||||
if let abi::Abi::CCmseNonSecureCall = abi { | ||||||||||||||||
let hir_node = tcx.hir_node(hir_id); | ||||||||||||||||
let hir::Node::Ty(hir::Ty { | ||||||||||||||||
|
@@ -67,13 +70,13 @@ pub(crate) fn validate_cmse_abi<'tcx>( | |||||||||||||||
/// Returns whether the inputs will fit into the available registers | ||||||||||||||||
fn is_valid_cmse_inputs<'tcx>( | ||||||||||||||||
tcx: TyCtxt<'tcx>, | ||||||||||||||||
fn_sig: ty::PolyFnSig<'tcx>, | ||||||||||||||||
fn_sig: ty::FnSig<'tcx>, | ||||||||||||||||
) -> Result<Result<(), usize>, &'tcx LayoutError<'tcx>> { | ||||||||||||||||
let mut span = None; | ||||||||||||||||
let mut accum = 0u64; | ||||||||||||||||
|
||||||||||||||||
for (index, arg_def) in fn_sig.inputs().iter().enumerate() { | ||||||||||||||||
let layout = tcx.layout_of(ParamEnv::reveal_all().and(*arg_def.skip_binder()))?; | ||||||||||||||||
for (index, ty) in fn_sig.inputs().iter().enumerate() { | ||||||||||||||||
let layout = tcx.layout_of(ParamEnv::reveal_all().and(*ty))?; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side-note: this param-env is not right, so it'll probably ICE in other cases... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, #130104 was just reported and is not fixed by this branch (currently). How do we get a correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually that second ICE is due to encountering rust/compiler/rustc_ty_utils/src/layout.rs Lines 677 to 683 in 263a3ae
Moving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, that is 100% not the right fix. the problem here is that we need to delay the calculation of these layouts until after type-checking is done for types that show up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here #127814 (comment) is where some discussion around the current design happened. Is there an existing way to perform that traversal after type checking to perform this layout check? |
||||||||||||||||
|
||||||||||||||||
let align = layout.layout.align().abi.bytes(); | ||||||||||||||||
let size = layout.layout.size().bytes(); | ||||||||||||||||
|
@@ -96,9 +99,9 @@ fn is_valid_cmse_inputs<'tcx>( | |||||||||||||||
/// Returns whether the output will fit into the available registers | ||||||||||||||||
fn is_valid_cmse_output<'tcx>( | ||||||||||||||||
tcx: TyCtxt<'tcx>, | ||||||||||||||||
fn_sig: ty::PolyFnSig<'tcx>, | ||||||||||||||||
fn_sig: ty::FnSig<'tcx>, | ||||||||||||||||
) -> Result<bool, &'tcx LayoutError<'tcx>> { | ||||||||||||||||
let mut ret_ty = fn_sig.output().skip_binder(); | ||||||||||||||||
let mut ret_ty = fn_sig.output(); | ||||||||||||||||
let layout = tcx.layout_of(ParamEnv::reveal_all().and(ret_ty))?; | ||||||||||||||||
let size = layout.layout.size().bytes(); | ||||||||||||||||
|
||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tweak -- can you change this back to
PolyFnSig
and do the binder instantiate call inside this fn?