@@ -91,8 +91,8 @@ macro_rules! atomic_rmw_amo_ext {
91
91
portable_atomic_target_feature = "zaamo" ,
92
92
) ) ]
93
93
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 ) ? ;
96
96
macro_rules! op {
97
97
( $asm_order: tt) => {
98
98
// SAFETY: The user guaranteed that the AMO instruction is available in this
@@ -110,7 +110,7 @@ macro_rules! atomic_rmw_amo {
110
110
concat!( "amo" , stringify!( $op) , "." , $size, $asm_order, " {out}, {val}, 0({dst})" ) , // atomic { _x = *dst; *dst = op(_x, val); out = _x }
111
111
".option pop" ,
112
112
dst = in( reg) ptr_reg!( $dst) ,
113
- val = in( reg) $val,
113
+ val = in( reg) $val $ ( as $cast ) ? ,
114
114
out = lateout( reg) out,
115
115
options( nostack, preserves_flags) ,
116
116
)
@@ -178,7 +178,7 @@ macro_rules! srlw {
178
178
}
179
179
180
180
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) => {
182
182
#[ repr( transparent) ]
183
183
pub ( crate ) struct $atomic_type $( <$( $generics) * >) ? {
184
184
v: UnsafeCell <$value_type>,
@@ -217,7 +217,7 @@ macro_rules! atomic_load_store {
217
217
// SAFETY: any data races are prevented by atomic intrinsics and the raw
218
218
// pointer passed in is valid because we got it from a reference.
219
219
unsafe {
220
- let out;
220
+ let out $ ( : $cast ) ? ;
221
221
macro_rules! atomic_load {
222
222
( $acquire: tt, $release: tt) => {
223
223
asm!(
@@ -236,7 +236,7 @@ macro_rules! atomic_load_store {
236
236
Ordering :: SeqCst => atomic_load!( "fence r, rw" , "fence rw, rw" ) ,
237
237
_ => unreachable!( ) ,
238
238
}
239
- out
239
+ out $ ( as $cast as $value_type ) ?
240
240
}
241
241
}
242
242
@@ -255,7 +255,7 @@ macro_rules! atomic_load_store {
255
255
concat!( "s" , $size, " {val}, 0({dst})" ) , // atomic { *dst = val }
256
256
$acquire, // fence
257
257
dst = in( reg) ptr_reg!( dst) ,
258
- val = in( reg) val,
258
+ val = in( reg) val $ ( as $cast ) ? ,
259
259
options( nostack, preserves_flags) ,
260
260
)
261
261
} ;
@@ -274,8 +274,8 @@ macro_rules! atomic_load_store {
274
274
}
275
275
276
276
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) ;
279
279
#[ cfg( any(
280
280
test,
281
281
portable_atomic_force_amo,
@@ -288,7 +288,10 @@ macro_rules! atomic_ptr {
288
288
let dst = self . v. get( ) ;
289
289
// SAFETY: any data races are prevented by atomic intrinsics and the raw
290
290
// 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
+ }
292
295
}
293
296
}
294
297
} ;
@@ -563,13 +566,13 @@ atomic!(AtomicIsize, isize, "w", max, min);
563
566
#[ cfg( target_pointer_width = "32" ) ]
564
567
atomic ! ( AtomicUsize , usize , "w" , maxu, minu) ;
565
568
#[ cfg( target_pointer_width = "32" ) ]
566
- atomic_ptr ! ( [ T ] AtomicPtr , * mut T , "w" ) ;
569
+ atomic_ptr ! ( [ T ] AtomicPtr , * mut T as * mut u8 , "w" ) ;
567
570
#[ cfg( target_pointer_width = "64" ) ]
568
571
atomic ! ( AtomicIsize , isize , "d" , max, min) ;
569
572
#[ cfg( target_pointer_width = "64" ) ]
570
573
atomic ! ( AtomicUsize , usize , "d" , maxu, minu) ;
571
574
#[ cfg( target_pointer_width = "64" ) ]
572
- atomic_ptr ! ( [ T ] AtomicPtr , * mut T , "d" ) ;
575
+ atomic_ptr ! ( [ T ] AtomicPtr , * mut T as * mut u8 , "d" ) ;
573
576
574
577
#[ cfg( test) ]
575
578
mod tests {
0 commit comments