Skip to content

Commit 13877a9

Browse files
committed
prune raw pointer read and write methods from Miri backtraces
1 parent 2b269ca commit 13877a9

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

library/core/src/intrinsics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,7 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
26152615
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
26162616
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
26172617
#[inline]
2618+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
26182619
pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
26192620
extern "rust-intrinsic" {
26202621
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]

library/core/src/ptr/const_ptr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ impl<T: ?Sized> *const T {
11441144
#[stable(feature = "pointer_methods", since = "1.26.0")]
11451145
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
11461146
#[inline]
1147+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
11471148
pub const unsafe fn read(self) -> T
11481149
where
11491150
T: Sized,
@@ -1164,6 +1165,7 @@ impl<T: ?Sized> *const T {
11641165
/// [`ptr::read_volatile`]: crate::ptr::read_volatile()
11651166
#[stable(feature = "pointer_methods", since = "1.26.0")]
11661167
#[inline]
1168+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
11671169
pub unsafe fn read_volatile(self) -> T
11681170
where
11691171
T: Sized,
@@ -1183,6 +1185,7 @@ impl<T: ?Sized> *const T {
11831185
#[stable(feature = "pointer_methods", since = "1.26.0")]
11841186
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
11851187
#[inline]
1188+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
11861189
pub const unsafe fn read_unaligned(self) -> T
11871190
where
11881191
T: Sized,

library/core/src/ptr/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
10951095
#[inline]
10961096
#[stable(feature = "rust1", since = "1.0.0")]
10971097
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
1098+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10981099
pub const unsafe fn read<T>(src: *const T) -> T {
10991100
// We are calling the intrinsics directly to avoid function calls in the generated code
11001101
// as `intrinsics::copy_nonoverlapping` is a wrapper function.
@@ -1194,6 +1195,7 @@ pub const unsafe fn read<T>(src: *const T) -> T {
11941195
#[inline]
11951196
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
11961197
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
1198+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
11971199
pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
11981200
let mut tmp = MaybeUninit::<T>::uninit();
11991201
// SAFETY: the caller must guarantee that `src` is valid for reads.
@@ -1290,6 +1292,7 @@ pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
12901292
#[inline]
12911293
#[stable(feature = "rust1", since = "1.0.0")]
12921294
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1295+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12931296
pub const unsafe fn write<T>(dst: *mut T, src: T) {
12941297
// We are calling the intrinsics directly to avoid function calls in the generated code
12951298
// as `intrinsics::copy_nonoverlapping` is a wrapper function.
@@ -1387,6 +1390,7 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
13871390
#[inline]
13881391
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
13891392
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
1393+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13901394
pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
13911395
// SAFETY: the caller must guarantee that `dst` is valid for writes.
13921396
// `dst` cannot overlap `src` because the caller has mutable access
@@ -1460,6 +1464,7 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
14601464
/// ```
14611465
#[inline]
14621466
#[stable(feature = "volatile", since = "1.9.0")]
1467+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
14631468
pub unsafe fn read_volatile<T>(src: *const T) -> T {
14641469
// SAFETY: the caller must uphold the safety contract for `volatile_load`.
14651470
unsafe {
@@ -1530,6 +1535,7 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
15301535
/// ```
15311536
#[inline]
15321537
#[stable(feature = "volatile", since = "1.9.0")]
1538+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
15331539
pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
15341540
// SAFETY: the caller must uphold the safety contract for `volatile_store`.
15351541
unsafe {

library/core/src/ptr/mut_ptr.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@ impl<T: ?Sized> *mut T {
12561256
#[stable(feature = "pointer_methods", since = "1.26.0")]
12571257
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
12581258
#[inline(always)]
1259+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12591260
pub const unsafe fn read(self) -> T
12601261
where
12611262
T: Sized,
@@ -1276,6 +1277,7 @@ impl<T: ?Sized> *mut T {
12761277
/// [`ptr::read_volatile`]: crate::ptr::read_volatile()
12771278
#[stable(feature = "pointer_methods", since = "1.26.0")]
12781279
#[inline(always)]
1280+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12791281
pub unsafe fn read_volatile(self) -> T
12801282
where
12811283
T: Sized,
@@ -1295,6 +1297,7 @@ impl<T: ?Sized> *mut T {
12951297
#[stable(feature = "pointer_methods", since = "1.26.0")]
12961298
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
12971299
#[inline(always)]
1300+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12981301
pub const unsafe fn read_unaligned(self) -> T
12991302
where
13001303
T: Sized,
@@ -1400,6 +1403,7 @@ impl<T: ?Sized> *mut T {
14001403
#[stable(feature = "pointer_methods", since = "1.26.0")]
14011404
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
14021405
#[inline(always)]
1406+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
14031407
pub const unsafe fn write(self, val: T)
14041408
where
14051409
T: Sized,
@@ -1418,6 +1422,7 @@ impl<T: ?Sized> *mut T {
14181422
#[stable(feature = "pointer_methods", since = "1.26.0")]
14191423
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
14201424
#[inline(always)]
1425+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
14211426
pub const unsafe fn write_bytes(self, val: u8, count: usize)
14221427
where
14231428
T: Sized,
@@ -1438,6 +1443,7 @@ impl<T: ?Sized> *mut T {
14381443
/// [`ptr::write_volatile`]: crate::ptr::write_volatile()
14391444
#[stable(feature = "pointer_methods", since = "1.26.0")]
14401445
#[inline(always)]
1446+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
14411447
pub unsafe fn write_volatile(self, val: T)
14421448
where
14431449
T: Sized,
@@ -1457,6 +1463,7 @@ impl<T: ?Sized> *mut T {
14571463
#[stable(feature = "pointer_methods", since = "1.26.0")]
14581464
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
14591465
#[inline(always)]
1466+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
14601467
pub const unsafe fn write_unaligned(self, val: T)
14611468
where
14621469
T: Sized,

0 commit comments

Comments
 (0)