-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
32 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,18 @@ | ||
//@ build-fail | ||
//@ compile-flags: --crate-type lib | ||
//@ only-32bit Layout computation rejects this layout for different reasons on 64-bit. | ||
//@ error-pattern: too big for the current architecture | ||
#![feature(core_intrinsics)] | ||
#![allow(internal_features)] | ||
|
||
// isize::MAX is fine, but with the padding for the unsized tail it is too big. | ||
#[repr(C)] | ||
pub struct Example([u8; isize::MAX as usize], [u16]); | ||
|
||
// We guarantee that with length 0, `size_of_val_raw` (which calls the `size_of_val` intrinsic) | ||
// is safe to call. The compiler aborts compilation if a length of 0 would overflow. | ||
// So let's construct a case where length 0 just barely overflows, and ensure that | ||
// does abort compilation. | ||
pub fn check(x: *const Example) -> usize { | ||
unsafe { std::intrinsics::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 | ||
|