Skip to content

Commit 802343f

Browse files
authored
Rollup merge of rust-lang#146485 - zachs18:store_fn_arg-no-unsized, r=davidtwco
Remove unsized arg handling in `ArgAbiBuilderMethods::store_fn_arg` implementations ... since it is unreachable and would ICE anyway. These branches are unreachable with how `store_fn_arg` is currently used (where it is called, unsized arguments are either: 1. not (yet) supported, or 2. handled differently)[^1], and even if they were reachable, they would ICE anyway, since they call [`OperandValue::store`](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_codegen_ssa/mir/operand.rs.html#855-861), which calls [`OperandValue::store_with_flags`](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_codegen_ssa/mir/operand.rs.html#887-926) which [panics on any unsized layout](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_codegen_ssa/mir/operand.rs.html#900-903). Also updates the `bug!` message in `store_arg` to not suggest `store_fn_arg` for unsized args. [^1]: `store_fn_arg` is only nontrivially[^2] called in `compiler/rustc_codegen_ssa/src/mir/mod.rs` for: Line 428 `extern "rust-call"` tuple (un)splitting, which does not support unsized arguments, Line 496 which is only for sized `PassMode::Indirect` (`meta_attrs: None`) arguments, and Line 521 which is only for non-`PassMode::Indirect` arguments which can never be unsized. [^2]: `<Bx as ArgAbiBuilderMethods>::store_fn_arg` is what is actually called, but codegen_llvm and codegen_gcc's builders both delegate to their own `codegen_crate::ArgAbiExt::store_fn_arg`, which contain the actual implementations that are changed in this PR.
2 parents 0a2be63 + baed55c commit 802343f

File tree

2 files changed

+5
-15
lines changed
  • compiler
    • rustc_codegen_gcc/src/intrinsic
    • rustc_codegen_llvm/src

2 files changed

+5
-15
lines changed

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
730730
if self.is_sized_indirect() {
731731
OperandValue::Ref(PlaceValue::new_sized(val, self.layout.align.abi)).store(bx, dst)
732732
} else if self.is_unsized_indirect() {
733-
bug!("unsized `ArgAbi` must be handled through `store_fn_arg`");
733+
bug!("unsized `ArgAbi` cannot be stored");
734734
} else if let PassMode::Cast { ref cast, .. } = self.mode {
735735
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
736736
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
@@ -797,12 +797,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
797797
OperandValue::Pair(next(), next()).store(bx, dst);
798798
}
799799
PassMode::Indirect { meta_attrs: Some(_), .. } => {
800-
let place_val = PlaceValue {
801-
llval: next(),
802-
llextra: Some(next()),
803-
align: self.layout.align.abi,
804-
};
805-
OperandValue::Ref(place_val).store(bx, dst);
800+
bug!("unsized `ArgAbi` cannot be stored");
806801
}
807802
PassMode::Direct(_)
808803
| PassMode::Indirect { meta_attrs: None, .. }

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
215215
let align = attrs.pointee_align.unwrap_or(self.layout.align.abi);
216216
OperandValue::Ref(PlaceValue::new_sized(val, align)).store(bx, dst);
217217
}
218-
// Unsized indirect qrguments
218+
// Unsized indirect arguments cannot be stored
219219
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
220-
bug!("unsized `ArgAbi` must be handled through `store_fn_arg`");
220+
bug!("unsized `ArgAbi` cannot be stored");
221221
}
222222
PassMode::Cast { cast, pad_i32: _ } => {
223223
// The ABI mandates that the value is passed as a different struct representation.
@@ -272,12 +272,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
272272
OperandValue::Pair(next(), next()).store(bx, dst);
273273
}
274274
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
275-
let place_val = PlaceValue {
276-
llval: next(),
277-
llextra: Some(next()),
278-
align: self.layout.align.abi,
279-
};
280-
OperandValue::Ref(place_val).store(bx, dst);
275+
bug!("unsized `ArgAbi` cannot be stored");
281276
}
282277
PassMode::Direct(_)
283278
| PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ }

0 commit comments

Comments
 (0)