File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -152,23 +152,19 @@ pub fn spin_loop() {
152
152
/// backend used. Programs cannot rely on `black_box` for *correctness* in any way.
153
153
///
154
154
/// [`std::convert::identity`]: crate::convert::identity
155
- #[ cfg_attr( not( miri) , inline) ]
156
- #[ cfg_attr( miri, inline( never) ) ]
155
+ #[ inline]
157
156
#[ unstable( feature = "bench_black_box" , issue = "64102" ) ]
158
- #[ cfg_attr( miri , allow( unused_mut) ) ]
157
+ #[ cfg_attr( not ( bootstrap ) , allow( unused_mut) ) ]
159
158
pub fn black_box < T > ( mut dummy : T ) -> T {
160
- // We need to "use" the argument in some way LLVM can't introspect, and on
161
- // targets that support it we can typically leverage inline assembly to do
162
- // this. LLVM's interpretation of inline assembly is that it's, well, a black
163
- // box. This isn't the greatest implementation since it probably deoptimizes
164
- // more than we want, but it's so far good enough.
165
-
166
- #[ cfg( not( miri) ) ] // This is just a hint, so it is fine to skip in Miri.
159
+ #[ cfg( bootstrap) ]
167
160
// SAFETY: the inline assembly is a no-op.
168
161
unsafe {
169
- // FIXME: Cannot use `asm!` because it doesn't support MIPS and other architectures.
170
162
llvm_asm ! ( "" : : "r" ( & mut dummy) : "memory" : "volatile" ) ;
163
+ dummy
171
164
}
172
165
173
- dummy
166
+ #[ cfg( not( bootstrap) ) ]
167
+ {
168
+ crate :: intrinsics:: black_box ( dummy)
169
+ }
174
170
}
Original file line number Diff line number Diff line change @@ -1933,6 +1933,12 @@ extern "rust-intrinsic" {
1933
1933
/// which is UB if any of their inputs are `undef`.)
1934
1934
#[ rustc_const_unstable( feature = "const_intrinsic_raw_eq" , issue = "none" ) ]
1935
1935
pub fn raw_eq < T > ( a : & T , b : & T ) -> bool ;
1936
+
1937
+ /// See documentation of [`std::hint::black_box`] for details.
1938
+ ///
1939
+ /// [`std::hint::black_box`]: crate::hint::black_box
1940
+ #[ cfg( not( bootstrap) ) ]
1941
+ pub fn black_box < T > ( dummy : T ) -> T ;
1936
1942
}
1937
1943
1938
1944
// Some functions are defined here because they accidentally got made
You can’t perform that action at this time.
0 commit comments