forked from rust-lang/rust
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Allocation before main Test that should fail currently
- Loading branch information
Showing
2 changed files
with
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// Helper for 'no-allocation-before-main'. | ||
/// | ||
/// This also contains a meta-test to make sure that the AbortingAllocator does indeed abort. | ||
//@ run-fail | ||
|
||
pub struct AbortingAllocator; | ||
|
||
unsafe impl std::alloc::GlobalAlloc for AbortingAllocator { | ||
unsafe fn alloc(&self, _: std::alloc::Layout) -> *mut u8 { | ||
std::process::abort() | ||
} | ||
|
||
unsafe fn dealloc(&self, _: *mut u8, _: std::alloc::Layout) { | ||
std::process::abort() | ||
} | ||
} | ||
|
||
#[global_allocator] | ||
static ALLOCATOR: AbortingAllocator = AbortingAllocator; | ||
|
||
fn main() { | ||
std::hint::black_box(Box::new(false)); | ||
} |
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,10 @@ | ||
//! Tests that a program with no body does not allocate. | ||
//! | ||
//! The initial runtime should not allocate for performance/binary size reasons. | ||
//@ run-pass | ||
|
||
#[allow(dead_code)] | ||
#[path = "aborting-alloc.rs"] | ||
mod aux; | ||
|
||
fn main() {} |