Skip to content

Commit b0c996a

Browse files
authored
Rollup merge of #117277 - RalfJung:too-big-with-padding, r=oli-obk
fix failure to detect a too-big-type after adding padding Fixes #117265
2 parents 7e3f63e + 2ef5897 commit b0c996a

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

compiler/rustc_abi/src/layout.rs

+5
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ pub trait LayoutCalculator {
539539
// Align the maximum variant size to the largest alignment.
540540
size = size.align_to(align.abi);
541541

542+
// FIXME(oli-obk): deduplicate and harden these checks
542543
if size.bytes() >= dl.obj_size_bound() {
543544
return None;
544545
}
@@ -1103,6 +1104,10 @@ fn univariant<
11031104
inverse_memory_index.into_iter().map(|it| it.index() as u32).collect()
11041105
};
11051106
let size = min_size.align_to(align.abi);
1107+
// FIXME(oli-obk): deduplicate and harden these checks
1108+
if size.bytes() >= dl.obj_size_bound() {
1109+
return None;
1110+
}
11061111
let mut layout_of_single_non_zst_field = None;
11071112
let mut abi = Abi::Aggregate { sized };
11081113
// Try to make this a Scalar/ScalarPair.

compiler/rustc_ty_utils/src/layout_sanity_check.rs

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub(super) fn sanity_check_layout<'tcx>(
1919
if layout.size.bytes() % layout.align.abi.bytes() != 0 {
2020
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
2121
}
22+
if layout.size.bytes() >= cx.tcx.data_layout.obj_size_bound() {
23+
bug!("size is too large, in the following layout:\n{layout:#?}");
24+
}
2225

2326
if !cfg!(debug_assertions) {
2427
// Stop here, the rest is kind of expensive.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// build-fail
2+
// compile-flags: --target i686-unknown-linux-gnu --crate-type lib
3+
// needs-llvm-components: x86
4+
#![feature(no_core, lang_items)]
5+
#![allow(internal_features)]
6+
#![no_std]
7+
#![no_core]
8+
9+
// 0x7fffffff is fine, but after rounding up it becomes too big
10+
#[repr(C, align(2))]
11+
pub struct Example([u8; 0x7fffffff]);
12+
13+
pub fn lib(_x: Example) {} //~ERROR: too big for the current architecture
14+
15+
#[lang = "sized"]
16+
pub trait Sized {}
17+
#[lang = "copy"]
18+
pub trait Copy: Sized {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: values of the type `Example` are too big for the current architecture
2+
--> $DIR/too-big-with-padding.rs:13:1
3+
|
4+
LL | pub fn lib(_x: Example) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)