From: Enes Cevik Date: Tue, 26 May 2026 12:07:10 +0000 (+0300) Subject: gccrs: lang: Add lang item exchange_malloc X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=346d511fb443cf3d29e1eac680c80593476817ab;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc index 37bd85b6b67..21e2c81e9e6 100644 --- a/gcc/rust/util/rust-lang-item.cc +++ b/gcc/rust/util/rust-lang-item.cc @@ -120,6 +120,8 @@ const BiMap 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 diff --git a/gcc/rust/util/rust-lang-item.h b/gcc/rust/util/rust-lang-item.h index 90d53a4991a..5a765282b8c 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 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 00000000000..abfaabfb680 --- /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 +}