about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/lto/lto-global-allocator.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/ui/lto/lto-global-allocator.rs b/tests/ui/lto/lto-global-allocator.rs
new file mode 100644
index 00000000000..03f11709c90
--- /dev/null
+++ b/tests/ui/lto/lto-global-allocator.rs
@@ -0,0 +1,19 @@
+//@ compile-flags: --crate-type cdylib -C lto
+//@ build-pass
+//@ no-prefer-dynamic
+//@ needs-crate-type: cdylib
+
+use std::alloc::{GlobalAlloc, Layout};
+
+struct MyAllocator;
+
+unsafe impl GlobalAlloc for MyAllocator {
+    unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
+        todo!()
+    }
+
+    unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
+}
+
+#[global_allocator]
+static GLOBAL: MyAllocator = MyAllocator;