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.
---
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/f1ae8b1553ca1bd264081bbbf5d63ff59bd37871
The commit has been mentioned in the following issue(s):
- Rust-GCC/gccrs#5003: https://github.com/Rust-GCC/gccrs/issues/5003
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/5004
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 2495de0a5..30521bca5 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 afcb11e37..1942f03fb 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" }
}
}
base-commit: 1802a910670dbde3560853f0a61f68b9d9f5a9b6
--
2.55.0