From: Enes Cevik <[email protected]>

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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/16a37ba94b143f0f1e9987d0380fca1ae309406f

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4557

 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(+)
 create mode 100644 gcc/testsuite/rust/compile/exchange_malloc.rs

diff --git a/gcc/rust/util/rust-lang-item.cc b/gcc/rust/util/rust-lang-item.cc
index 37bd85b6b..21e2c81e9 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 90d53a499..5a765282b 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 000000000..abfaabfb6
--- /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
+}

base-commit: cd9103fd3fe8d3726d5b4c30d30c7da265f53da3
-- 
2.54.0

Reply via email to