]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: lang: Add lang item exchange_malloc
authorEnes Cevik <enes@nsvke.com>
Tue, 26 May 2026 12:07:10 +0000 (15:07 +0300)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 25 Jun 2026 17:21:26 +0000 (19:21 +0200)
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 <enes@nsvke.com>
gcc/rust/util/rust-lang-item.cc
gcc/rust/util/rust-lang-item.h
gcc/testsuite/rust/compile/exchange_malloc.rs [new file with mode: 0644]

index 37bd85b6b67390d0b5bead21e19132f2a87e0526..21e2c81e9e696474ecdb0f4fc728bc0dd8f03d99 100644 (file)
@@ -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>
index 90d53a4991ad4a0e957a421a9eb17868269416f9..5a765282b8cd16b9c2ad53d6fb173315fc116d4b 100644 (file)
@@ -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 (file)
index 0000000..abfaabf
--- /dev/null
@@ -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
+}