Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit afd4a8d

Browse files
authoredAug 2, 2024
Unrolled build for rust-lang#128453
Rollup merge of rust-lang#128453 - RalfJung:raw_eq, r=saethlin raw_eq: using it on bytes with provenance is not UB (outside const-eval) The current behavior of raw_eq violates provenance monotonicity. See rust-lang#124921 for an explanation of provenance monotonicity. It is violated in raw_eq because comparing bytes without provenance is well-defined, but adding provenance makes the operation UB. So remove the no-provenance requirement from raw_eq. However, the requirement stays in-place for compile-time invocations of raw_eq, that indeed cannot deal with provenance. Cc `@rust-lang/opsem`
2 parents 05e692a + f97aba2 commit afd4a8d

File tree

7 files changed

+9
-35
lines changed

7 files changed

+9
-35
lines changed
 

‎compiler/rustc_const_eval/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,6 @@ const_eval_range_upper = less or equal to {$hi}
316316
const_eval_range_wrapping = less or equal to {$hi}, or greater or equal to {$lo}
317317
const_eval_raw_bytes = the raw bytes of the constant (size: {$size}, align: {$align}) {"{"}{$bytes}{"}"}
318318
319-
const_eval_raw_eq_with_provenance =
320-
`raw_eq` on bytes with provenance
321-
322319
const_eval_raw_ptr_comparison =
323320
pointers cannot be reliably compared during const eval
324321
.note = see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information

‎compiler/rustc_const_eval/src/interpret/intrinsics.rs

-3
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
690690
// zero-sized access
691691
return Ok(&[]);
692692
};
693-
if alloc_ref.has_provenance() {
694-
throw_ub_custom!(fluent::const_eval_raw_eq_with_provenance);
695-
}
696693
alloc_ref.get_bytes_strip_provenance()
697694
};
698695

‎library/core/src/intrinsics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2436,11 +2436,13 @@ extern "rust-intrinsic" {
24362436
///
24372437
/// # Safety
24382438
///
2439-
/// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized or carry a
2440-
/// pointer value.
2439+
/// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized.
24412440
/// Note that this is a stricter criterion than just the *values* being
24422441
/// fully-initialized: if `T` has padding, it's UB to call this intrinsic.
24432442
///
2443+
/// At compile-time, it is furthermore UB to call this if any of the bytes
2444+
/// in `*a` or `*b` have provenance.
2445+
///
24442446
/// (The implementation is allowed to branch on the results of comparisons,
24452447
/// which is UB if any of their inputs are `undef`.)
24462448
#[rustc_const_unstable(feature = "const_intrinsic_raw_eq", issue = "none")]

‎src/tools/miri/tests/fail/intrinsics/raw_eq_on_ptr.rs

-10
This file was deleted.

‎src/tools/miri/tests/fail/intrinsics/raw_eq_on_ptr.stderr

-15
This file was deleted.

‎tests/ui/intrinsics/intrinsic-raw_eq-const-bad.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const RAW_EQ_PADDING: bool = unsafe {
1010
const RAW_EQ_PTR: bool = unsafe {
1111
std::intrinsics::raw_eq(&(&0), &(&1))
1212
//~^ ERROR evaluation of constant value failed
13-
//~| `raw_eq` on bytes with provenance
13+
//~| unable to turn pointer into integer
1414
};
1515

1616
pub fn main() {

‎tests/ui/intrinsics/intrinsic-raw_eq-const-bad.stderr

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ error[E0080]: evaluation of constant value failed
88
--> $DIR/intrinsic-raw_eq-const-bad.rs:11:5
99
|
1010
LL | std::intrinsics::raw_eq(&(&0), &(&1))
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `raw_eq` on bytes with provenance
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into integer
12+
|
13+
= help: this code performed an operation that depends on the underlying bytes representing a pointer
14+
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
1215

1316
error: aborting due to 2 previous errors
1417

0 commit comments

Comments
 (0)
Failed to load comments.