|
| 1 | +//@ compile-flags: -C opt-level=3 |
| 2 | +#![crate_type = "lib"] |
| 3 | + |
| 4 | +mod foobar { |
| 5 | + use std::alloc::{GlobalAlloc, Layout}; |
| 6 | + |
| 7 | + struct Allocator; |
| 8 | + |
| 9 | + unsafe impl GlobalAlloc for Allocator { |
| 10 | + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { |
| 11 | + // CHECK-LABEL: ; __rustc::__rust_alloc |
| 12 | + // CHECK-NEXT: ; Function Attrs: {{.*}}allockind("alloc,uninitialized,aligned") allocsize(0){{.*}} |
| 13 | + // CHECK-NEXT: define noalias{{.*}} ptr @{{.*}}__rust_alloc(i[[SIZE:[0-9]+]] {{.*}}%size, i[[SIZE]] allocalign{{.*}} %align) |
| 14 | + panic!() |
| 15 | + } |
| 16 | + |
| 17 | + unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { |
| 18 | + // CHECK-LABEL: ; __rustc::__rust_dealloc |
| 19 | + // CHECK-NEXT: ; Function Attrs: {{.*}}allockind("free"){{.*}} |
| 20 | + // CHECK-NEXT: define void @{{.*}}__rust_dealloc(ptr allocptr{{.*}} %ptr, i[[SIZE]] {{.*}} %size, i[[SIZE]] {{.*}} %align) |
| 21 | + panic!() |
| 22 | + } |
| 23 | + |
| 24 | + unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { |
| 25 | + // CHECK-LABEL: ; __rustc::__rust_realloc |
| 26 | + // CHECK-NEXT: ; Function Attrs: {{.*}}allockind("realloc,aligned") allocsize(3){{.*}} |
| 27 | + // CHECK-NEXT: define noalias{{.*}} ptr @{{.*}}__rust_realloc(ptr allocptr{{.*}} %ptr, i[[SIZE]] {{.*}} %size, i[[SIZE]] allocalign{{.*}} %align, i[[SIZE]] {{.*}} %new_size) |
| 28 | + panic!() |
| 29 | + } |
| 30 | + |
| 31 | + unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { |
| 32 | + // CHECK-LABEL: ; __rustc::__rust_alloc_zeroed |
| 33 | + // CHECK-NEXT: ; Function Attrs: {{.*}}allockind("alloc,zeroed,aligned") allocsize(0){{.*}} |
| 34 | + // CHECK-NEXT: define noalias{{.*}} ptr @{{.*}}__rust_alloc_zeroed(i[[SIZE]] {{.*}} %size, i[[SIZE]] allocalign{{.*}} %align) |
| 35 | + panic!() |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + #[global_allocator] |
| 40 | + static GLOBAL: Allocator = Allocator; |
| 41 | +} |
0 commit comments