Skip to content

Commit

Permalink
WIP: Allocation before main Test that should fail currently
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Apr 6, 2024
1 parent 3f10032 commit 6f7be53
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/ui/runtime/aborting-alloc.rs
@@ -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));
}
10 changes: 10 additions & 0 deletions tests/ui/runtime/no-allocation-before-main.rs
@@ -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() {}

0 comments on commit 6f7be53

Please sign in to comment.