Skip to content

Commit 367267c

Browse files
committed
Work around nightly-2025-02-24 rustc regression
See rust-lang/rust#137512 for details. Fixes #208
1 parent 617263b commit 367267c

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

src/imp/interrupt/armv4t.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(crate) mod atomic {
8181
use core::{cell::UnsafeCell, sync::atomic::Ordering};
8282

8383
macro_rules! atomic {
84-
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty, $suffix:tt) => {
84+
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty $(as $cast:ty)?, $suffix:tt) => {
8585
#[repr(transparent)]
8686
pub(crate) struct $atomic_type $(<$($generics)*>)? {
8787
v: UnsafeCell<$value_type>,
@@ -100,7 +100,7 @@ pub(crate) mod atomic {
100100
// SAFETY: any data races are prevented by atomic intrinsics and the raw
101101
// pointer passed in is valid because we got it from a reference.
102102
unsafe {
103-
let out;
103+
let out $(: $cast)?;
104104
// inline asm without nomem/readonly implies compiler fence.
105105
// And compiler fence is fine because the user explicitly declares that
106106
// the system is single-core by using an unsafe cfg.
@@ -110,7 +110,7 @@ pub(crate) mod atomic {
110110
out = lateout(reg) out,
111111
options(nostack, preserves_flags),
112112
);
113-
out
113+
out $(as $cast as $value_type)?
114114
}
115115
}
116116

@@ -126,7 +126,7 @@ pub(crate) mod atomic {
126126
asm!(
127127
concat!("str", $suffix, " {val}, [{dst}]"),
128128
dst = in(reg) dst,
129-
val = in(reg) val,
129+
val = in(reg) val $(as $cast)?,
130130
options(nostack, preserves_flags),
131131
);
132132
}
@@ -143,5 +143,5 @@ pub(crate) mod atomic {
143143
atomic!(AtomicU32, u32, "");
144144
atomic!(AtomicIsize, isize, "");
145145
atomic!(AtomicUsize, usize, "");
146-
atomic!([T] AtomicPtr, *mut T, "");
146+
atomic!([T] AtomicPtr, *mut T as *mut u8, "");
147147
}

src/imp/msp430.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn compiler_fence(order: Ordering) {
6868
}
6969

7070
macro_rules! atomic {
71-
(load_store, $([$($generics:tt)*])? $atomic_type:ident, $value_type:ty, $size:tt) => {
71+
(load_store, $([$($generics:tt)*])? $atomic_type:ident, $value_type:ty $(as $cast:ty)?, $size:tt) => {
7272
#[cfg(not(feature = "critical-section"))]
7373
#[repr(transparent)]
7474
pub(crate) struct $atomic_type $(<$($generics)*>)? {
@@ -93,7 +93,7 @@ macro_rules! atomic {
9393
// SAFETY: any data races are prevented by atomic intrinsics and the raw
9494
// pointer passed in is valid because we got it from a reference.
9595
unsafe {
96-
let out;
96+
let out $(: $cast)?;
9797
#[cfg(not(portable_atomic_no_asm))]
9898
asm!(
9999
concat!("mov.", $size, " @{src}, {out}"), // atomic { out = *src }
@@ -106,7 +106,7 @@ macro_rules! atomic {
106106
concat!("mov.", $size, " $1, $0")
107107
: "=r"(out) : "*m"(src) : "memory" : "volatile"
108108
);
109-
out
109+
out $(as $cast as $value_type)?
110110
}
111111
}
112112

@@ -122,7 +122,7 @@ macro_rules! atomic {
122122
asm!(
123123
concat!("mov.", $size, " {val}, 0({dst})"), // atomic { *dst = val }
124124
dst = in(reg) dst,
125-
val = in(reg) val,
125+
val = in(reg) val $(as $cast)?,
126126
options(nostack, preserves_flags),
127127
);
128128
#[cfg(portable_atomic_no_asm)]
@@ -134,8 +134,8 @@ macro_rules! atomic {
134134
}
135135
}
136136
};
137-
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty, $size:tt) => {
138-
atomic!(load_store, $([$($generics)*])? $atomic_type, $value_type, $size);
137+
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty $(as $cast:ty)?, $size:tt) => {
138+
atomic!(load_store, $([$($generics)*])? $atomic_type, $value_type $(as $cast)?, $size);
139139
#[cfg(not(feature = "critical-section"))]
140140
impl $(<$($generics)*>)? $atomic_type $(<$($generics)*>)? {
141141
#[inline]
@@ -148,7 +148,7 @@ macro_rules! atomic {
148148
asm!(
149149
concat!("add.", $size, " {val}, 0({dst})"), // atomic { *dst += val }
150150
dst = in(reg) dst,
151-
val = in(reg) val,
151+
val = in(reg) val $(as $cast)?,
152152
// Do not use `preserves_flags` because ADD modifies the V, N, Z, and C bits of the status register.
153153
options(nostack),
154154
);
@@ -170,7 +170,7 @@ macro_rules! atomic {
170170
asm!(
171171
concat!("sub.", $size, " {val}, 0({dst})"), // atomic { *dst -= val }
172172
dst = in(reg) dst,
173-
val = in(reg) val,
173+
val = in(reg) val $(as $cast)?,
174174
// Do not use `preserves_flags` because SUB modifies the V, N, Z, and C bits of the status register.
175175
options(nostack),
176176
);
@@ -192,7 +192,7 @@ macro_rules! atomic {
192192
asm!(
193193
concat!("and.", $size, " {val}, 0({dst})"), // atomic { *dst &= val }
194194
dst = in(reg) dst,
195-
val = in(reg) val,
195+
val = in(reg) val $(as $cast)?,
196196
// Do not use `preserves_flags` because AND modifies the V, N, Z, and C bits of the status register.
197197
options(nostack),
198198
);
@@ -214,7 +214,7 @@ macro_rules! atomic {
214214
asm!(
215215
concat!("bis.", $size, " {val}, 0({dst})"), // atomic { *dst |= val }
216216
dst = in(reg) dst,
217-
val = in(reg) val,
217+
val = in(reg) val $(as $cast)?,
218218
options(nostack, preserves_flags),
219219
);
220220
#[cfg(portable_atomic_no_asm)]
@@ -235,7 +235,7 @@ macro_rules! atomic {
235235
asm!(
236236
concat!("xor.", $size, " {val}, 0({dst})"), // atomic { *dst ^= val }
237237
dst = in(reg) dst,
238-
val = in(reg) val,
238+
val = in(reg) val $(as $cast)?,
239239
// Do not use `preserves_flags` because XOR modifies the V, N, Z, and C bits of the status register.
240240
options(nostack),
241241
);
@@ -277,4 +277,4 @@ atomic!(AtomicI16, i16, "w");
277277
atomic!(AtomicU16, u16, "w");
278278
atomic!(AtomicIsize, isize, "w");
279279
atomic!(AtomicUsize, usize, "w");
280-
atomic!(load_store, [T] AtomicPtr, *mut T, "w");
280+
atomic!(load_store, [T] AtomicPtr, *mut T as *mut u8, "w");

src/imp/riscv.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ macro_rules! atomic_rmw_amo_ext {
9191
portable_atomic_target_feature = "zaamo",
9292
))]
9393
macro_rules! atomic_rmw_amo {
94-
($op:ident, $dst:ident, $val:ident, $order:ident, $size:tt) => {{
95-
let out;
94+
($op:ident, $dst:ident, $val:ident $(as $cast:ty)?, $order:ident, $size:tt) => {{
95+
let out $(: $cast)?;
9696
macro_rules! op {
9797
($asm_order:tt) => {
9898
// SAFETY: The user guaranteed that the AMO instruction is available in this
@@ -110,7 +110,7 @@ macro_rules! atomic_rmw_amo {
110110
concat!("amo", stringify!($op), ".", $size, $asm_order, " {out}, {val}, 0({dst})"), // atomic { _x = *dst; *dst = op(_x, val); out = _x }
111111
".option pop",
112112
dst = in(reg) ptr_reg!($dst),
113-
val = in(reg) $val,
113+
val = in(reg) $val $(as $cast)?,
114114
out = lateout(reg) out,
115115
options(nostack, preserves_flags),
116116
)
@@ -178,7 +178,7 @@ macro_rules! srlw {
178178
}
179179

180180
macro_rules! atomic_load_store {
181-
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty, $size:tt) => {
181+
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty $(as $cast:ty)?, $size:tt) => {
182182
#[repr(transparent)]
183183
pub(crate) struct $atomic_type $(<$($generics)*>)? {
184184
v: UnsafeCell<$value_type>,
@@ -217,7 +217,7 @@ macro_rules! atomic_load_store {
217217
// SAFETY: any data races are prevented by atomic intrinsics and the raw
218218
// pointer passed in is valid because we got it from a reference.
219219
unsafe {
220-
let out;
220+
let out $(: $cast)?;
221221
macro_rules! atomic_load {
222222
($acquire:tt, $release:tt) => {
223223
asm!(
@@ -236,7 +236,7 @@ macro_rules! atomic_load_store {
236236
Ordering::SeqCst => atomic_load!("fence r, rw", "fence rw, rw"),
237237
_ => unreachable!(),
238238
}
239-
out
239+
out $(as $cast as $value_type)?
240240
}
241241
}
242242

@@ -255,7 +255,7 @@ macro_rules! atomic_load_store {
255255
concat!("s", $size, " {val}, 0({dst})"), // atomic { *dst = val }
256256
$acquire, // fence
257257
dst = in(reg) ptr_reg!(dst),
258-
val = in(reg) val,
258+
val = in(reg) val $(as $cast)?,
259259
options(nostack, preserves_flags),
260260
)
261261
};
@@ -274,8 +274,8 @@ macro_rules! atomic_load_store {
274274
}
275275

276276
macro_rules! atomic_ptr {
277-
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty, $size:tt) => {
278-
atomic_load_store!($([$($generics)*])? $atomic_type, $value_type, $size);
277+
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty $(as $cast:ty)?, $size:tt) => {
278+
atomic_load_store!($([$($generics)*])? $atomic_type, $value_type $(as $cast)?, $size);
279279
#[cfg(any(
280280
test,
281281
portable_atomic_force_amo,
@@ -288,7 +288,7 @@ macro_rules! atomic_ptr {
288288
let dst = self.v.get();
289289
// SAFETY: any data races are prevented by atomic intrinsics and the raw
290290
// pointer passed in is valid because we got it from a reference.
291-
unsafe { atomic_rmw_amo!(swap, dst, val, order, $size) }
291+
unsafe { atomic_rmw_amo!(swap, dst, val $(as $cast)?, order, $size) $(as $cast as $value_type)? }
292292
}
293293
}
294294
};
@@ -563,13 +563,13 @@ atomic!(AtomicIsize, isize, "w", max, min);
563563
#[cfg(target_pointer_width = "32")]
564564
atomic!(AtomicUsize, usize, "w", maxu, minu);
565565
#[cfg(target_pointer_width = "32")]
566-
atomic_ptr!([T] AtomicPtr, *mut T, "w");
566+
atomic_ptr!([T] AtomicPtr, *mut T as *mut u8, "w");
567567
#[cfg(target_pointer_width = "64")]
568568
atomic!(AtomicIsize, isize, "d", max, min);
569569
#[cfg(target_pointer_width = "64")]
570570
atomic!(AtomicUsize, usize, "d", maxu, minu);
571571
#[cfg(target_pointer_width = "64")]
572-
atomic_ptr!([T] AtomicPtr, *mut T, "d");
572+
atomic_ptr!([T] AtomicPtr, *mut T as *mut u8, "d");
573573

574574
#[cfg(test)]
575575
mod tests {

0 commit comments

Comments
 (0)