]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_gcc/example/alloc_example.rs
Merge commit '0c89065b934397b62838fe3e4ef6f6352fc52daf' into libgccjit-codegen
[rust.git] / compiler / rustc_codegen_gcc / example / alloc_example.rs
1 #![feature(start, box_syntax, core_intrinsics, alloc_prelude, alloc_error_handler)]
2 #![no_std]
3
4 extern crate alloc;
5 extern crate alloc_system;
6
7 use alloc::prelude::v1::*;
8
9 use alloc_system::System;
10
11 #[global_allocator]
12 static ALLOC: System = System;
13
14 #[link(name = "c")]
15 extern "C" {
16     fn puts(s: *const u8) -> i32;
17 }
18
19 #[panic_handler]
20 fn panic_handler(_: &core::panic::PanicInfo) -> ! {
21     unsafe {
22         core::intrinsics::abort();
23     }
24 }
25
26 #[alloc_error_handler]
27 fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
28     unsafe {
29         core::intrinsics::abort();
30     }
31 }
32
33 #[start]
34 fn main(_argc: isize, _argv: *const *const u8) -> isize {
35     let world: Box<&str> = box "Hello World!\0";
36     unsafe {
37         puts(*world as *const str as *const u8);
38     }
39
40     0
41 }