@@ -103,13 +103,24 @@ impl Local {
103
103
self . epoch . store ( Epoch :: starting ( ) , Ordering :: Release ) ;
104
104
}
105
105
106
+ /// `#[inline(never)]` is used to reduce the chances for misoptimizations.
107
+ ///
108
+ /// In Rust, there is no concept of functions that return multiple times, like `setjmp`, so
109
+ /// it's easy to imagine that Rust might generate incorrect code around such a function.
110
+ ///
111
+ /// Rust uses LLVM during compilation, which needs to be made aware of functions that return
112
+ /// multiple times by using the `returns_twice` attribute; but Rust has no way to propagate
113
+ /// that attribute to LLVM.
114
+ ///
115
+ /// Reference:
116
+ /// * https://github.com/rust-lang/rfcs/issues/2625#issuecomment-460849462
117
+ /// * https://github.com/jeff-davis/setjmp.rs#problems
106
118
#[ cfg( not( sanitize = "address" ) ) ]
107
- #[ inline( always ) ]
119
+ #[ inline( never ) ]
108
120
unsafe fn pin < F > ( & mut self , mut body : F )
109
121
where
110
122
F : FnMut ( & mut EpochGuard ) ,
111
123
{
112
- compiler_fence ( Ordering :: SeqCst ) ;
113
124
{
114
125
// Makes a checkpoint and create a `RecoveryGuard`.
115
126
let guard = recovery:: guard!( ) ;
@@ -133,16 +144,14 @@ impl Local {
133
144
// We are now out of the critical(crashable) section.
134
145
// Unpin the local epoch to help reclaimers to freely collect bags.
135
146
self . unpin_inner ( ) ;
136
- compiler_fence ( Ordering :: SeqCst ) ;
137
147
}
138
148
139
149
#[ cfg( sanitize = "address" ) ]
140
- #[ inline( always ) ]
150
+ #[ inline( never ) ]
141
151
unsafe fn pin < F > ( & mut self , mut body : F )
142
152
where
143
153
F : FnMut ( & mut EpochGuard ) ,
144
154
{
145
- compiler_fence ( Ordering :: SeqCst ) ;
146
155
// A dummy loop to bypass a false stack overflow from AdressSanitizer.
147
156
//
148
157
// # HACK: A dummy loop and `blackbox`
@@ -187,7 +196,6 @@ impl Local {
187
196
break ;
188
197
}
189
198
}
190
- compiler_fence ( Ordering :: SeqCst ) ;
191
199
}
192
200
193
201
#[ inline]
0 commit comments