Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raw_eq: using it on bytes with provenance is not UB (outside const-eval) #128453

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ const_eval_range_upper = less or equal to {$hi}
const_eval_range_wrapping = less or equal to {$hi}, or greater or equal to {$lo}
const_eval_raw_bytes = the raw bytes of the constant (size: {$size}, align: {$align}) {"{"}{$bytes}{"}"}

const_eval_raw_eq_with_provenance =
`raw_eq` on bytes with provenance

const_eval_raw_ptr_comparison =
pointers cannot be reliably compared during const eval
.note = see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// zero-sized access
return Ok(&[]);
};
if alloc_ref.has_provenance() {
throw_ub_custom!(fluent::const_eval_raw_eq_with_provenance);
}
alloc_ref.get_bytes_strip_provenance()
};

Expand Down
6 changes: 4 additions & 2 deletions library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2436,11 +2436,13 @@ extern "rust-intrinsic" {
///
/// # Safety
///
/// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized or carry a
/// pointer value.
/// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized.
/// Note that this is a stricter criterion than just the *values* being
/// fully-initialized: if `T` has padding, it's UB to call this intrinsic.
///
/// At compile-time, it is furthermore UB to call this if any of the bytes
/// in `*a` or `*b` have provenance.
///
/// (The implementation is allowed to branch on the results of comparisons,
/// which is UB if any of their inputs are `undef`.)
#[rustc_const_unstable(feature = "const_intrinsic_raw_eq", issue = "none")]
Expand Down
10 changes: 0 additions & 10 deletions src/tools/miri/tests/fail/intrinsics/raw_eq_on_ptr.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/tools/miri/tests/fail/intrinsics/raw_eq_on_ptr.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/intrinsics/intrinsic-raw_eq-const-bad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const RAW_EQ_PADDING: bool = unsafe {
const RAW_EQ_PTR: bool = unsafe {
std::intrinsics::raw_eq(&(&0), &(&1))
//~^ ERROR evaluation of constant value failed
//~| `raw_eq` on bytes with provenance
//~| unable to turn pointer into integer
};

pub fn main() {
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/intrinsics/intrinsic-raw_eq-const-bad.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ error[E0080]: evaluation of constant value failed
--> $DIR/intrinsic-raw_eq-const-bad.rs:11:5
|
LL | std::intrinsics::raw_eq(&(&0), &(&1))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `raw_eq` on bytes with provenance
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into integer
|
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported

error: aborting due to 2 previous errors

Expand Down
Loading