Skip to content

Commit 8ea28a4

Browse files
committed
Add test
1 parent 66982a3 commit 8ea28a4

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
include ../tools.mk
2+
3+
TARGET_LIBDIR = $$($(RUSTC) --print target-libdir)
4+
5+
all:
6+
$(RUSTC) foo.rs --crate-type bin --emit obj -Cpanic=abort
7+
ifdef IS_MSVC
8+
$(CC) $(CFLAGS) $(TMPDIR)/foo.o $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib $(call OUT_EXE,foo)
9+
$(call OUT_EXE,foo)
10+
else
11+
$(CC) $(CFLAGS) $(TMPDIR)/foo.o $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib -o $(call RUN_BINFILE,foo)
12+
$(call RUN_BINFILE,foo)
13+
endif
14+
15+
# Check that linking without __rust_no_alloc_shim_is_unstable defined fails
16+
$(RUSTC) foo.rs --crate-type bin --emit obj -Cpanic=abort --cfg check_feature_gate
17+
ifdef IS_MSVC
18+
$(CC) $(CFLAGS) $(TMPDIR)/foo.o $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib $(call OUT_EXE,foo) || exit 0 && exit 1
19+
else
20+
$(CC) $(CFLAGS) $(TMPDIR)/foo.o $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib -o $(call RUN_BINFILE,foo) || exit 0 && exit 1
21+
endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#![feature(default_alloc_error_handler)]
2+
#![no_std]
3+
#![no_main]
4+
5+
extern crate alloc;
6+
7+
use alloc::alloc::{GlobalAlloc, Layout};
8+
9+
#[panic_handler]
10+
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
11+
loop {}
12+
}
13+
14+
#[no_mangle]
15+
extern "C" fn rust_eh_personality() {
16+
loop {}
17+
}
18+
19+
#[global_allocator]
20+
static ALLOC: Alloc = Alloc;
21+
22+
struct Alloc;
23+
24+
unsafe impl GlobalAlloc for Alloc {
25+
unsafe fn alloc(&self, _: Layout) -> *mut u8 {
26+
core::ptr::null_mut()
27+
}
28+
unsafe fn dealloc(&self, _: *mut u8, _: Layout) {
29+
todo!()
30+
}
31+
}
32+
33+
#[cfg(not(check_feature_gate))]
34+
#[no_mangle]
35+
static __rust_no_alloc_shim_is_unstable: u8 = 0;
36+
37+
#[no_mangle]
38+
extern "C" fn main(_argc: usize, _argv: *const *const i8) -> i32 {
39+
unsafe {
40+
assert_eq!(alloc::alloc::alloc(Layout::new::<()>()), core::ptr::null_mut());
41+
}
42+
43+
0
44+
}

0 commit comments

Comments
 (0)