Skip to content

Commit

Permalink
Add tests for unwind no_std.
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Apr 4, 2021
1 parent 9cdaea3 commit 48acdb7
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/test/ui/panic-runtime/unwind-msvc-no-std-link-to-libcmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// build-pass
// compile-flags: -C panic=unwind -C target-feature=+crt-static
// only-msvc
// Test that `no_std` with `panic=unwind` under MSVC toolchain
// doesn't cause error when linking to libcmt.

#![no_std]
#![no_main]
#![feature(alloc_error_handler)]
#![feature(panic_unwind)]

use core::alloc::{GlobalAlloc, Layout};

struct DummyAllocator;

unsafe impl GlobalAlloc for DummyAllocator {
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
core::ptr::null_mut()
}

unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
}

#[global_allocator]
static ALLOC: DummyAllocator = DummyAllocator;

#[alloc_error_handler]
fn rust_oom(_layout: Layout) -> ! {
panic!()
}

extern crate panic_unwind;

use core::panic::PanicInfo;

#[panic_handler]
fn handle_panic(_: &PanicInfo) -> ! {
loop {}
}

#[link(name = "libcmt")]
extern "C" {}

#[no_mangle]
pub extern "C" fn main() -> i32 {
panic!();
}
47 changes: 47 additions & 0 deletions src/test/ui/panic-runtime/unwind-msvc-no-std-link-to-msvcrt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// build-pass
// compile-flags: -C panic=unwind
// only-msvc
// Test that `no_std` with `panic=unwind` under MSVC toolchain
// doesn't cause error when linking to msvcrt.

#![no_std]
#![no_main]
#![feature(alloc_error_handler)]
#![feature(panic_unwind)]

use core::alloc::{GlobalAlloc, Layout};

struct DummyAllocator;

unsafe impl GlobalAlloc for DummyAllocator {
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
core::ptr::null_mut()
}

unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
}

#[global_allocator]
static ALLOC: DummyAllocator = DummyAllocator;

#[alloc_error_handler]
fn rust_oom(_layout: Layout) -> ! {
panic!()
}

extern crate panic_unwind;

use core::panic::PanicInfo;

#[panic_handler]
fn handle_panic(_: &PanicInfo) -> ! {
loop {}
}

#[link(name = "msvcrt")]
extern "C" {}

#[no_mangle]
pub extern "C" fn main() -> i32 {
panic!();
}

0 comments on commit 48acdb7

Please sign in to comment.