Skip to content

Commit 0956ead

Browse files
committed
Ban projecting into SIMD types [MCP838]
1 parent 0a977c7 commit 0956ead

File tree

4 files changed

+17
-46
lines changed

4 files changed

+17
-46
lines changed

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -329,20 +329,11 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
329329
let offset = self.layout.fields.offset(i);
330330

331331
if !bx.is_backend_ref(self.layout) && bx.is_backend_ref(field) {
332-
if let BackendRepr::SimdVector { count, .. } = self.layout.backend_repr
333-
&& let BackendRepr::Memory { sized: true } = field.backend_repr
334-
&& count.is_power_of_two()
335-
{
336-
assert_eq!(field.size, self.layout.size);
337-
// This is being deprecated, but for now stdarch still needs it for
338-
// Newtype vector of array, e.g. #[repr(simd)] struct S([i32; 4]);
339-
let place = PlaceRef::alloca(bx, field);
340-
self.val.store(bx, place.val.with_type(self.layout));
341-
return bx.load_operand(place);
342-
} else {
343-
// Part of https://github.com/rust-lang/compiler-team/issues/838
344-
bug!("Non-ref type {self:?} cannot project to ref field type {field:?}");
345-
}
332+
// Part of https://github.com/rust-lang/compiler-team/issues/838
333+
span_bug!(
334+
fx.mir.span,
335+
"Non-ref type {self:?} cannot project to ref field type {field:?}",
336+
);
346337
}
347338

348339
let val = if field.is_zst() {

compiler/rustc_mir_transform/src/validate.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
719719
);
720720
}
721721

722+
if adt_def.repr().simd() {
723+
self.fail(
724+
location,
725+
format!(
726+
"Projecting into SIMD type {adt_def:?} is banned by MCP#838"
727+
),
728+
);
729+
}
730+
722731
let var = parent_ty.variant_index.unwrap_or(FIRST_VARIANT);
723732
let Some(field) = adt_def.variant(var).fields.get(f) else {
724733
fail_out_of_bounds(self, location);

tests/codegen/simd/project-to-simd-array-field.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/ui/simd/issue-105439.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ struct i32x4([i32; 4]);
1010

1111
#[inline(always)]
1212
fn to_array(a: i32x4) -> [i32; 4] {
13-
a.0
13+
// This was originally just `a.0`, but that ended up being annoying enough
14+
// that it was banned by <https://github.com/rust-lang/compiler-team/issues/838>
15+
unsafe { std::mem::transmute(a) }
1416
}
1517

1618
fn main() {

0 commit comments

Comments
 (0)