From: Arthur Cohen <[email protected]>
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.
Tested on x86_64-pc-linux-gnu.
---
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 2495de0a5d3..30521bca579 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 afcb11e3708..1942f03fb4a 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" }
}
}
--
2.55.0