Skip to content

Commit 9df93f6

Browse files
committed
fix ICE in release builds from aggressive inlining
1 parent e951f47 commit 9df93f6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

compiler/rustc_codegen_ssa/src/mir/analyze.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'b, 'tcx>> LocalAnalyzer<'a, 'b, 'tcx, Bx>
156156
}
157157
}
158158
}
159-
debug_assert!(
160-
!self.fx.cx.is_backend_ref(layout),
161-
"Post-projection {place_ref:?} layout should be non-Ref, but it's {layout:?}",
162-
);
159+
// After projection, if the layout is still a backend ref (e.g., field projection
160+
// on multi-variant enums), we need to use Memory instead of SSA.
161+
if self.fx.cx.is_backend_ref(layout) {
162+
self.locals[place_ref.local] = LocalKind::Memory;
163+
return;
164+
}
163165
}
164166

165167
// Even with supported projections, we still need to have `visit_local`

compiler/rustc_traits/src/codegen.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ pub(crate) fn codegen_select_candidate<'tcx>(
2626
key: PseudoCanonicalInput<'tcx, ty::TraitRef<'tcx>>,
2727
) -> Result<&'tcx ImplSource<'tcx, ()>, CodegenObligationError> {
2828
let PseudoCanonicalInput { typing_env, value: trait_ref } = key;
29-
// We expect the input to be fully normalized.
30-
debug_assert_eq!(trait_ref, tcx.normalize_erasing_regions(typing_env, trait_ref));
29+
// We expect the input to be fully normalized, but in some cases (particularly with
30+
// aggressive inlining in release builds), it may not be. Ensure we normalize it here.
31+
let trait_ref = tcx.normalize_erasing_regions(typing_env, trait_ref);
3132

3233
// Do the initial selection for the obligation. This yields the
3334
// shallow result we are looking for -- that is, what specific impl.
@@ -41,6 +42,11 @@ pub(crate) fn codegen_select_candidate<'tcx>(
4142
Ok(Some(selection)) => selection,
4243
Ok(None) => return Err(CodegenObligationError::Ambiguity),
4344
Err(SelectionError::Unimplemented) => return Err(CodegenObligationError::Unimplemented),
45+
// SignatureMismatch can occur with complex associated type projections
46+
// in generic contexts during aggressive inlining. Treat as unimplemented.
47+
Err(SelectionError::SignatureMismatch(_)) => {
48+
return Err(CodegenObligationError::Unimplemented)
49+
}
4450
Err(e) => {
4551
bug!("Encountered error `{:?}` selecting `{:?}` during codegen", e, trait_ref)
4652
}

0 commit comments

Comments
 (0)