Skip to content
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

[WIP] compiler: dont try to compile impossible alignment on 16-bit #131276

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_hir as hir;
use rustc_index::bit_set::BitSet;
use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::bug;
use rustc_middle::mir::interpret::PointerArithmetic;
use rustc_middle::mir::{CoroutineLayout, CoroutineSavedLocal};
use rustc_middle::query::Providers;
use rustc_middle::ty::layout::{
Expand Down Expand Up @@ -562,6 +563,13 @@ fn layout_of_uncached<'tcx>(
));
}

// we're on a 16-bit target and this alignment is too big
if let Some(align) = def.repr().align {
if align.bytes() > (cx.target_isize_max() as u64) {
return Err(error(cx, LayoutError::SizeOverflow(ty)));
}
}

let get_discriminant_type =
|min, max| Integer::repr_discr(tcx, ty, &def.repr(), min, max);

Expand Down
4 changes: 4 additions & 0 deletions tests/ui/repr/16-bit-align-too-big.msp430.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: values of the type `Hello16BitAlign` are too big for the target architecture

error: aborting due to 1 previous error

38 changes: 38 additions & 0 deletions tests/ui/repr/16-bit-align-too-big.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// We should fail to compute alignment for types aligned higher than usize::MAX.
// We can't handle alignments that require all 32 bits, so this only affects 16-bit.

//@ revisions: msp430 aarch32
//@ [msp430] build-fail
//@ [msp430] needs-llvm-components: msp430
//@ [msp430] compile-flags: --target=msp430-none-elf
//@ [msp430] error-pattern: values of the type `Hello16BitAlign` are too big for the target architecture

Check failure on line 8 in tests/ui/repr/16-bit-align-too-big.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check-tidy

line longer than 100 chars

//@ [aarch32] build-pass
//@ [aarch32] needs-llvm-components: arm
//@ [aarch32] compile-flags: --target=thumbv7m-none-eabi

#![feature(no_core, lang_items, intrinsics, staged_api, rustc_attrs)]
#![no_core]
#![crate_type = "lib"]
#![stable(feature = "intrinsics_for_test", since = "3.3.3")]
#![allow(dead_code)]

extern "rust-intrinsic" {
#[stable(feature = "intrinsics_for_test", since = "3.3.3")]
#[rustc_const_stable(feature = "intrinsics_for_test", since = "3.3.3")]
#[rustc_safe_intrinsic]
fn min_align_of<T>() -> usize;
}

#[lang="sized"]
trait Sized {}
#[lang="copy"]
trait Copy {}

#[repr(align(65536))]
#[stable(feature = "intrinsics_for_test", since = "3.3.3")]
pub struct Hello16BitAlign;


#[stable(feature = "intrinsics_for_test", since = "3.3.3")]
pub fn bar() -> usize { min_align_of::<Hello16BitAlign>() }
Loading