https://gcc.gnu.org/g:346d511fb443cf3d29e1eac680c80593476817ab

commit r17-1864-g346d511fb443cf3d29e1eac680c80593476817ab
Author: Enes Cevik <[email protected]>
Date:   Tue May 26 15:07:10 2026 +0300

    gccrs: lang: Add lang item exchange_malloc
    
    This patch introduces the `exchange_malloc` lang item to compiler.
    This lang item is a strict prerequisite for the `owned_box` lang item
    and box expressions.
    
    gcc/rust/ChangeLog:
    
            * util/rust-lang-item.cc (Rust::LangItem::lang_items): Register
            exchange_malloc to BiMap.
            * util/rust-lang-item.h (LangItem::Kind): Add EXCHANGE_MALLOC.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/exchange_malloc.rs: New test.
    
    Signed-off-by: Enes Cevik <[email protected]>

Diff:
---
 gcc/rust/util/rust-lang-item.cc               | 2 ++
 gcc/rust/util/rust-lang-item.h                | 2 ++
 gcc/testsuite/rust/compile/exchange_malloc.rs | 7 +++++++
 3 files changed, 11 insertions(+)

diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index 37bd85b6b673..21e2c81e9e69 100644
--- a/gcc/rust/util/rust-lang-item.cc
+++ b/gcc/rust/util/rust-lang-item.cc
@@ -120,6 +120,8 @@ const BiMap<std::string, LangItem::Kind> 
Rust::LangItem::lang_items = {{
   {"discriminant_kind", Kind::DISCRIMINANT_KIND},
   {"discriminant_type", Kind::DISCRIMINANT_TYPE},
   {"manually_drop", Kind::MANUALLY_DROP},
+
+  {"exchange_malloc", Kind::EXCHANGE_MALLOC},
 }};
 
 tl::optional<LangItem::Kind>
diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h
index 90d53a4991ad..5a765282b8cd 100644
--- a/gcc/rust/util/rust-lang-item.h
+++ b/gcc/rust/util/rust-lang-item.h
@@ -156,6 +156,8 @@ public:
     DISCRIMINANT_KIND,
 
     MANUALLY_DROP,
+
+    EXCHANGE_MALLOC
   };
 
   static const BiMap<std::string, Kind> lang_items;
diff --git a/gcc/testsuite/rust/compile/exchange_malloc.rs 
b/gcc/testsuite/rust/compile/exchange_malloc.rs
new file mode 100644
index 000000000000..abfaabfb6805
--- /dev/null
+++ b/gcc/testsuite/rust/compile/exchange_malloc.rs
@@ -0,0 +1,7 @@
+#![feature(no_core,lang_items)]
+#![no_core]
+
+#[lang = "exchange_malloc"]
+unsafe fn _allocate(_size: usize, _align: usize) -> *mut u8 {
+    0 as *mut u8
+}

Reply via email to