summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/panic/no_std.rs
blob: bad425804dc0a66c5c8b45a27dbb0505cec4abc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#![feature(start, core_intrinsics)]
#![no_std]
//@compile-flags: -Cpanic=abort
// windows tls dtors go through libstd right now, thus this test
// cannot pass. When windows tls dtors go through the special magic
// windows linker section, we can run this test on windows again.
//@ignore-target-windows: no-std not supported on Windows

// Plumbing to let us use `writeln!` to host stderr:

extern "Rust" {
    fn miri_write_to_stderr(bytes: &[u8]);
}

struct HostErr;

use core::fmt::Write;

impl Write for HostErr {
    fn write_str(&mut self, s: &str) -> core::fmt::Result {
        unsafe {
            miri_write_to_stderr(s.as_bytes());
        }
        Ok(())
    }
}

// Aaaand the test:

#[start]
fn start(_: isize, _: *const *const u8) -> isize {
    panic!("blarg I am dead")
}

#[panic_handler]
fn panic_handler(panic_info: &core::panic::PanicInfo) -> ! {
    writeln!(HostErr, "{panic_info}").ok();
    core::intrinsics::abort(); //~ ERROR: the program aborted execution
}