Skip to content

Commit a368389

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

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

src/imp/interrupt/armv4t.rs

+5-5
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

+14-12
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ 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,
72+
$([$($generics:tt)*])? $atomic_type:ident, $value_type:ty $(as $cast:ty)?, $size:tt
73+
) => {
7274
#[cfg(not(feature = "critical-section"))]
7375
#[repr(transparent)]
7476
pub(crate) struct $atomic_type $(<$($generics)*>)? {
@@ -93,7 +95,7 @@ macro_rules! atomic {
9395
// SAFETY: any data races are prevented by atomic intrinsics and the raw
9496
// pointer passed in is valid because we got it from a reference.
9597
unsafe {
96-
let out;
98+
let out $(: $cast)?;
9799
#[cfg(not(portable_atomic_no_asm))]
98100
asm!(
99101
concat!("mov.", $size, " @{src}, {out}"), // atomic { out = *src }
@@ -106,7 +108,7 @@ macro_rules! atomic {
106108
concat!("mov.", $size, " $1, $0")
107109
: "=r"(out) : "*m"(src) : "memory" : "volatile"
108110
);
109-
out
111+
out $(as $cast as $value_type)?
110112
}
111113
}
112114

@@ -122,7 +124,7 @@ macro_rules! atomic {
122124
asm!(
123125
concat!("mov.", $size, " {val}, 0({dst})"), // atomic { *dst = val }
124126
dst = in(reg) dst,
125-
val = in(reg) val,
127+
val = in(reg) val $(as $cast)?,
126128
options(nostack, preserves_flags),
127129
);
128130
#[cfg(portable_atomic_no_asm)]
@@ -134,8 +136,8 @@ macro_rules! atomic {
134136
}
135137
}
136138
};
137-
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty, $size:tt) => {
138-
atomic!(load_store, $([$($generics)*])? $atomic_type, $value_type, $size);
139+
($([$($generics:tt)*])? $atomic_type:ident, $value_type:ty $(as $cast:ty)?, $size:tt) => {
140+
atomic!(load_store, $([$($generics)*])? $atomic_type, $value_type $(as $cast)?, $size);
139141
#[cfg(not(feature = "critical-section"))]
140142
impl $(<$($generics)*>)? $atomic_type $(<$($generics)*>)? {
141143
#[inline]
@@ -148,7 +150,7 @@ macro_rules! atomic {
148150
asm!(
149151
concat!("add.", $size, " {val}, 0({dst})"), // atomic { *dst += val }
150152
dst = in(reg) dst,
151-
val = in(reg) val,
153+
val = in(reg) val $(as $cast)?,
152154
// Do not use `preserves_flags` because ADD modifies the V, N, Z, and C bits of the status register.
153155
options(nostack),
154156
);
@@ -170,7 +172,7 @@ macro_rules! atomic {
170172
asm!(
171173
concat!("sub.", $size, " {val}, 0({dst})"), // atomic { *dst -= val }
172174
dst = in(reg) dst,
173-
val = in(reg) val,
175+
val = in(reg) val $(as $cast)?,
174176
// Do not use `preserves_flags` because SUB modifies the V, N, Z, and C bits of the status register.
175177
options(nostack),
176178
);
@@ -192,7 +194,7 @@ macro_rules! atomic {
192194
asm!(
193195
concat!("and.", $size, " {val}, 0({dst})"), // atomic { *dst &= val }
194196
dst = in(reg) dst,
195-
val = in(reg) val,
197+
val = in(reg) val $(as $cast)?,
196198
// Do not use `preserves_flags` because AND modifies the V, N, Z, and C bits of the status register.
197199
options(nostack),
198200
);
@@ -214,7 +216,7 @@ macro_rules! atomic {
214216
asm!(
215217
concat!("bis.", $size, " {val}, 0({dst})"), // atomic { *dst |= val }
216218
dst = in(reg) dst,
217-
val = in(reg) val,
219+
val = in(reg) val $(as $cast)?,
218220
options(nostack, preserves_flags),
219221
);
220222
#[cfg(portable_atomic_no_asm)]
@@ -235,7 +237,7 @@ macro_rules! atomic {
235237
asm!(
236238
concat!("xor.", $size, " {val}, 0({dst})"), // atomic { *dst ^= val }
237239
dst = in(reg) dst,
238-
val = in(reg) val,
240+
val = in(reg) val $(as $cast)?,
239241
// Do not use `preserves_flags` because XOR modifies the V, N, Z, and C bits of the status register.
240242
options(nostack),
241243
);
@@ -277,4 +279,4 @@ atomic!(AtomicI16, i16, "w");
277279
atomic!(AtomicU16, u16, "w");
278280
atomic!(AtomicIsize, isize, "w");
279281
atomic!(AtomicUsize, usize, "w");
280-
atomic!(load_store, [T] AtomicPtr, *mut T, "w");
282+
atomic!(load_store, [T] AtomicPtr, *mut T as *mut u8, "w");

src/imp/riscv.rs

+15-12
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,10 @@ 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 {
292+
atomic_rmw_amo!(swap, dst, val $(as $cast)?, order, $size)
293+
$(as $cast as $value_type)?
294+
}
292295
}
293296
}
294297
};
@@ -563,13 +566,13 @@ atomic!(AtomicIsize, isize, "w", max, min);
563566
#[cfg(target_pointer_width = "32")]
564567
atomic!(AtomicUsize, usize, "w", maxu, minu);
565568
#[cfg(target_pointer_width = "32")]
566-
atomic_ptr!([T] AtomicPtr, *mut T, "w");
569+
atomic_ptr!([T] AtomicPtr, *mut T as *mut u8, "w");
567570
#[cfg(target_pointer_width = "64")]
568571
atomic!(AtomicIsize, isize, "d", max, min);
569572
#[cfg(target_pointer_width = "64")]
570573
atomic!(AtomicUsize, usize, "d", maxu, minu);
571574
#[cfg(target_pointer_width = "64")]
572-
atomic_ptr!([T] AtomicPtr, *mut T, "d");
575+
atomic_ptr!([T] AtomicPtr, *mut T as *mut u8, "d");
573576

574577
#[cfg(test)]
575578
mod tests {

0 commit comments

Comments
 (0)