https://gcc.gnu.org/g:9a99bd6ec4be60f865d322b51e0af5955aa3022f

commit r17-5704-g9a99bd6ec4be60f865d322b51e0af5955aa3022f
Author: Arthur Cohen <[email protected]>
Date:   Tue Oct 20 18:22:41 2026 +0200

    gccrs: intrinsics: Always warn on assert_zero_valid<T>
    
    We currently do not properly implement assert_zero_valid<T> and always emit
    a no-op, which is incorrect. Always warn that we are missing certain cases
    and that the function is currently not doing any asserts.
    
    Open Rust-GCC/gccrs#5003 to eventually fix it, and we will need to also
    implement easy cases such as uninhabited types which we can already check.
    
    gcc/rust/ChangeLog:
    
            * backend/rust-intrinsic-handlers.cc (assert_zero_valid_handler): 
Always warn when emitting
            the function that only a no-op will be emitted.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/assert_zero_valid.rs: Check for the warning.

Diff:
---
 gcc/rust/backend/rust-intrinsic-handlers.cc     | 3 +++
 gcc/testsuite/rust/compile/assert_zero_valid.rs | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/backend/rust-intrinsic-handlers.cc 
b/gcc/rust/backend/rust-intrinsic-handlers.cc
index 2495de0a5d38..30521bca5793 100644
--- a/gcc/rust/backend/rust-intrinsic-handlers.cc
+++ b/gcc/rust/backend/rust-intrinsic-handlers.cc
@@ -1724,6 +1724,9 @@ assert_zero_valid_handler (IntrinsicCtx &ctx)
   // TODO: Implement layout verification via template_parameter_type once
   // niche-filling and valid scalar ranges are supported in the layout engine.
   // If invalid, this should emit a panic.
+  rust_warning_at (ctx.loc, 0,
+                  "%<assert_zero_valid<T>%> is currently always emitted as a "
+                  "no-op and will not trigger");
 
   // we always return unit for now.
   auto return_statement
diff --git a/gcc/testsuite/rust/compile/assert_zero_valid.rs 
b/gcc/testsuite/rust/compile/assert_zero_valid.rs
index afcb11e37080..1942f03fb4ab 100644
--- a/gcc/testsuite/rust/compile/assert_zero_valid.rs
+++ b/gcc/testsuite/rust/compile/assert_zero_valid.rs
@@ -10,7 +10,7 @@ extern "rust-intrinsic" {
 
 fn main() {
     unsafe {
-        assert_zero_valid::<i32>();
-        assert_zero_valid::<&i32>();
+        assert_zero_valid::<i32>(); // { dg-warning "no-op" }
+        assert_zero_valid::<&i32>(); // { dg-warning "no-op" }
     }
 }

Reply via email to