File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -539,6 +539,7 @@ pub trait LayoutCalculator {
539
539
// Align the maximum variant size to the largest alignment.
540
540
size = size.align_to(align.abi);
541
541
542
+ // FIXME(oli-obk): deduplicate and harden these checks
542
543
if size.bytes() >= dl.obj_size_bound() {
543
544
return None;
544
545
}
@@ -1103,6 +1104,10 @@ fn univariant<
1103
1104
inverse_memory_index.into_iter().map(|it| it.index() as u32).collect()
1104
1105
};
1105
1106
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
+ }
1106
1111
let mut layout_of_single_non_zst_field = None;
1107
1112
let mut abi = Abi::Aggregate { sized };
1108
1113
// Try to make this a Scalar/ScalarPair.
Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ pub(super) fn sanity_check_layout<'tcx>(
19
19
if layout.size.bytes() % layout.align.abi.bytes() != 0 {
20
20
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
21
21
}
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
+ }
22
25
23
26
if !cfg!(debug_assertions) {
24
27
// Stop here, the rest is kind of expensive.
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments