about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-09-05 14:46:46 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-09-06 13:31:41 +0000
commit9239d141dc4e9435b036d34cf8b2cb1e37b9f454 (patch)
treece369ad3fe7c3838af3437189afe69ba84e52d89
parent027135976849da34250d7638502bcc2a24f741d7 (diff)
downloadrust-9239d141dc4e9435b036d34cf8b2cb1e37b9f454.tar.gz
rust-9239d141dc4e9435b036d34cf8b2cb1e37b9f454.zip
Add test that __rg_oom doesn't get internalized during LTO
Co-Authored-By: Rémy Rakic <remy.rakic+github@gmail.com>
-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;