From: Arthur Cohen <[email protected]>

Unless we realize in the future that we absolutely need to implement this 
intrinsic, we might
as well not do it since it got removed in 2025 - per rust-lang/rust#91971

gcc/rust/ChangeLog:

        * util/rust-intrinsic-values.h: New value for pref_align_of.
        * backend/rust-compile-intrinsic.cc: Add the sorry handler for it.
        * typecheck/rust-hir-type-check-intrinsic.cc: Add tychk information for 
it.

gcc/testsuite/ChangeLog:

        * rust/compile/pref_align_of.rs: New test.
---
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/77478667378d49bdb2f0a0251490568af66174ce

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/5008

 gcc/rust/backend/rust-compile-intrinsic.cc    |  1 +
 .../rust-hir-type-check-intrinsic.cc          |  3 +++
 gcc/rust/util/rust-intrinsic-values.h         |  2 ++
 gcc/testsuite/rust/compile/pref_align_of.rs   | 21 +++++++++++++++++++
 4 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/pref_align_of.rs

diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc 
b/gcc/rust/backend/rust-compile-intrinsic.cc
index 5cdee95aa..881c03cc6 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -92,6 +92,7 @@ static const std::map<std::string, Intrinsic::CompileFn> 
intrinsics = {
   {IValue::FLOAT_TO_INT_UNCHECKED, handlers::float_to_int_unchecked},
   {IValue::EXACT_DIV, handlers::exact_div_handler},
   {IValue::BREAKPOINT, handlers::breakpoint},
+  {IValue::PREF_ALIGN_OF, handlers::sorry},
   {IValue::ASSERT_ZERO_VALID, handlers::type_assert (TyAssert::ZeroValid)},
   {IValue::ASSERT_INHABITED, handlers::type_assert (TyAssert::Inhabited)},
   {IValue::ASSERT_UNINIT_VALID, handlers::type_assert (TyAssert::UninitValid)},
diff --git a/gcc/rust/typecheck/rust-hir-type-check-intrinsic.cc 
b/gcc/rust/typecheck/rust-hir-type-check-intrinsic.cc
index 9914a2928..69424e053 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-intrinsic.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-intrinsic.cc
@@ -315,6 +315,9 @@ const std::unordered_map<std::string, IntrinsicRules>
     // fn breakpoint()
     {IValue::BREAKPOINT, {0, {}, IRT::Unit}},
 
+    // fn pref_align_of<T>()
+    {IValue::PREF_ALIGN_OF, {1, {}, IRT::Unit}},
+
     // pub fn assert_zero_valid<T>();
     {IValue::ASSERT_ZERO_VALID, {1, {}, IRT::Unit}},
     // fn assert_inhabited<T>();
diff --git a/gcc/rust/util/rust-intrinsic-values.h 
b/gcc/rust/util/rust-intrinsic-values.h
index e748616eb..1308444b8 100644
--- a/gcc/rust/util/rust-intrinsic-values.h
+++ b/gcc/rust/util/rust-intrinsic-values.h
@@ -177,6 +177,8 @@ public:
 
   static constexpr auto &BREAKPOINT = "breakpoint";
 
+  static constexpr auto &PREF_ALIGN_OF = "pref_align_of";
+
   static constexpr auto &ASSERT_ZERO_VALID = "assert_zero_valid";
   static constexpr auto &ASSERT_INHABITED = "assert_inhabited";
   static constexpr auto &ASSERT_UNINIT_VALID = "assert_uninit_valid";
diff --git a/gcc/testsuite/rust/compile/pref_align_of.rs 
b/gcc/testsuite/rust/compile/pref_align_of.rs
new file mode 100644
index 000000000..0387e9bee
--- /dev/null
+++ b/gcc/testsuite/rust/compile/pref_align_of.rs
@@ -0,0 +1,21 @@
+#![feature(no_core)]
+#![feature(intrinsics)]
+#![feature(lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+trait Sized {}
+
+extern "rust-intrinsic" {
+    fn pref_align_of<T>();
+}
+
+fn foo() {
+    unsafe {
+        let _ = pref_align_of::<i32>(); // { dg-message "sorry, unimplemented" 
}
+    };
+}
+
+fn main() {
+    foo();
+}
-- 
2.55.0

Reply via email to