1 /// NOTE: We don't have a proper black box in stable Rust. This is
2 /// a workaround implementation, that may have a too big performance overhead,
3 /// depending on operation, or it may fail to properly avoid having code
4 /// optimized out. It is good enough that it is used by default.
5 ///
6 /// A function that is opaque to the optimizer, to allow benchmarks to
7 /// pretend to use outputs to assist in avoiding dead-code
8 /// elimination.
9 // copied from https://docs.rs/bencher/0.1.5/src/bencher/lib.rs.html#590-596
10 #[cfg(feature = "__dead_code_marker")]
black_box<T>(dummy: T) -> T11 pub fn black_box<T>(dummy: T) -> T {
12     unsafe {
13         let ret = core::ptr::read_volatile(&dummy);
14         core::mem::forget(dummy);
15         ret
16     }
17 }
18 
19 /// If the block of code which contains this macro doesn't get dead code
20 /// eliminated, this macro ensures that the resulting binary contains a
21 /// easy-to-find static string with the format `"<$feature,$ctx>"`.
22 ///
23 /// In `gdbstub`, this macro makes it easy to see if the Rust compiler was able
24 /// to dead-code-eliminate the packet parsing / handling code associated with
25 /// unimplemented protocol extensions.
26 ///
27 /// e.g: if the target didn't implement the `MonitorCmd` extension, then running
28 /// the unix command `strings <finalbinary> | grep "<qRcmd,"` should return no
29 /// results.
30 #[doc(hidden)]
31 #[macro_export]
32 macro_rules! __dead_code_marker {
33     ($feature:literal, $ctx:literal) => {
34         #[cfg(feature = "__dead_code_marker")]
35         crate::internal::dead_code_marker::black_box(concat!("<", $feature, ",", $ctx, ">"));
36     };
37 }
38