-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
size_of_val_raw: for length 0 this is safe to call
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//@ build-fail | ||
//@ compile-flags: --target i686-unknown-linux-gnu --crate-type lib | ||
//@ needs-llvm-components: x86 | ||
//@ error-pattern: too big for the current architecture | ||
#![feature(no_core, lang_items, intrinsics)] | ||
#![allow(internal_features)] | ||
#![no_std] | ||
#![no_core] | ||
|
||
#[lang = "sized"] | ||
pub trait Sized {} | ||
#[lang = "copy"] | ||
pub trait Copy: Sized {} | ||
|
||
// 0x7fffffff is fine, but with the padding for the unsized tail it is too big. | ||
#[repr(C)] | ||
pub struct Example([u8; 0x7fffffff], [u16]); | ||
|
||
extern "rust-intrinsic" { | ||
pub fn size_of_val<T: ?Sized>(_: *const T) -> usize; | ||
} | ||
|
||
// We guarantee that with length 0, `size_of_val_raw` (which calls the `size_of_val` intrinsic) | ||
// is safe to call. The compiler aborts execution if a length of 0 would overflow. | ||
// So let's construct a case where length 0 just barely overflows, and ensure that | ||
// does abort execution. | ||
pub fn check(x: *const Example) { | ||
unsafe { size_of_val(x); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
error: values of the type `Example` are too big for the current architecture | ||
|
||
error: aborting due to 1 previous error | ||
|