• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![cfg_attr(feature = "used_linker", feature(used_with_arg))]
2 
3 use linkme::distributed_slice;
4 
5 #[distributed_slice]
6 static ITEMS: [&'static str];
7 
8 #[distributed_slice(ITEMS)]
9 static ITEM1: &'static str = "item1";
10 
11 // Regression test for https://github.com/dtolnay/linkme/issues/67.
12 //
13 // Must be run with `--release`.
14 #[test]
win_status_access_violation()15 fn win_status_access_violation() {
16     let mut last_address = None;
17     for item in ITEMS {
18         // Do some busy work to push the compiler into optimizing the code in a
19         // particularly "bad" way. This is derived from experimentation.
20         let address = item as *const &str as usize;
21         if let Some(last) = last_address {
22             assert_eq!(address - last, std::mem::size_of::<&str>());
23         }
24         last_address = Some(address);
25 
26         // Should not cause STATUS_ACCESS_VIOLATION.
27         println!("{} {:?}", item.len(), item.as_bytes());
28     }
29 }
30