@@ -68,7 +68,7 @@ pub fn compiler_fence(order: Ordering) {
68
68
}
69
69
70
70
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) => {
72
72
#[ cfg( not( feature = "critical-section" ) ) ]
73
73
#[ repr( transparent) ]
74
74
pub ( crate ) struct $atomic_type $( <$( $generics) * >) ? {
@@ -93,7 +93,7 @@ macro_rules! atomic {
93
93
// SAFETY: any data races are prevented by atomic intrinsics and the raw
94
94
// pointer passed in is valid because we got it from a reference.
95
95
unsafe {
96
- let out;
96
+ let out $ ( : $cast ) ? ;
97
97
#[ cfg( not( portable_atomic_no_asm) ) ]
98
98
asm!(
99
99
concat!( "mov." , $size, " @{src}, {out}" ) , // atomic { out = *src }
@@ -106,7 +106,7 @@ macro_rules! atomic {
106
106
concat!( "mov." , $size, " $1, $0" )
107
107
: "=r" ( out) : "*m" ( src) : "memory" : "volatile"
108
108
) ;
109
- out
109
+ out $ ( as $cast as $value_type ) ?
110
110
}
111
111
}
112
112
@@ -122,7 +122,7 @@ macro_rules! atomic {
122
122
asm!(
123
123
concat!( "mov." , $size, " {val}, 0({dst})" ) , // atomic { *dst = val }
124
124
dst = in( reg) dst,
125
- val = in( reg) val,
125
+ val = in( reg) val $ ( as $cast ) ? ,
126
126
options( nostack, preserves_flags) ,
127
127
) ;
128
128
#[ cfg( portable_atomic_no_asm) ]
@@ -134,8 +134,8 @@ macro_rules! atomic {
134
134
}
135
135
}
136
136
} ;
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) ;
139
139
#[ cfg( not( feature = "critical-section" ) ) ]
140
140
impl $( <$( $generics) * >) ? $atomic_type $( <$( $generics) * >) ? {
141
141
#[ inline]
@@ -148,7 +148,7 @@ macro_rules! atomic {
148
148
asm!(
149
149
concat!( "add." , $size, " {val}, 0({dst})" ) , // atomic { *dst += val }
150
150
dst = in( reg) dst,
151
- val = in( reg) val,
151
+ val = in( reg) val $ ( as $cast ) ? ,
152
152
// Do not use `preserves_flags` because ADD modifies the V, N, Z, and C bits of the status register.
153
153
options( nostack) ,
154
154
) ;
@@ -170,7 +170,7 @@ macro_rules! atomic {
170
170
asm!(
171
171
concat!( "sub." , $size, " {val}, 0({dst})" ) , // atomic { *dst -= val }
172
172
dst = in( reg) dst,
173
- val = in( reg) val,
173
+ val = in( reg) val $ ( as $cast ) ? ,
174
174
// Do not use `preserves_flags` because SUB modifies the V, N, Z, and C bits of the status register.
175
175
options( nostack) ,
176
176
) ;
@@ -192,7 +192,7 @@ macro_rules! atomic {
192
192
asm!(
193
193
concat!( "and." , $size, " {val}, 0({dst})" ) , // atomic { *dst &= val }
194
194
dst = in( reg) dst,
195
- val = in( reg) val,
195
+ val = in( reg) val $ ( as $cast ) ? ,
196
196
// Do not use `preserves_flags` because AND modifies the V, N, Z, and C bits of the status register.
197
197
options( nostack) ,
198
198
) ;
@@ -214,7 +214,7 @@ macro_rules! atomic {
214
214
asm!(
215
215
concat!( "bis." , $size, " {val}, 0({dst})" ) , // atomic { *dst |= val }
216
216
dst = in( reg) dst,
217
- val = in( reg) val,
217
+ val = in( reg) val $ ( as $cast ) ? ,
218
218
options( nostack, preserves_flags) ,
219
219
) ;
220
220
#[ cfg( portable_atomic_no_asm) ]
@@ -235,7 +235,7 @@ macro_rules! atomic {
235
235
asm!(
236
236
concat!( "xor." , $size, " {val}, 0({dst})" ) , // atomic { *dst ^= val }
237
237
dst = in( reg) dst,
238
- val = in( reg) val,
238
+ val = in( reg) val $ ( as $cast ) ? ,
239
239
// Do not use `preserves_flags` because XOR modifies the V, N, Z, and C bits of the status register.
240
240
options( nostack) ,
241
241
) ;
@@ -277,4 +277,4 @@ atomic!(AtomicI16, i16, "w");
277
277
atomic ! ( AtomicU16 , u16 , "w" ) ;
278
278
atomic ! ( AtomicIsize , isize , "w" ) ;
279
279
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" ) ;
0 commit comments