1 #![cfg_attr(feature = "used_linker", feature(used_with_arg))] 2 3 use linkme::distributed_slice; 4 5 pub struct Item { 6 pub name: &'static str, 7 } 8 9 impl Item { 10 #[inline(never)] len(&self) -> usize11 fn len(&self) -> usize { 12 self.name.len() 13 } 14 } 15 16 #[distributed_slice] 17 static ITEMS: [Item]; 18 19 #[distributed_slice(ITEMS)] 20 static ITEM1: Item = Item { name: "item1" }; 21 22 // Regression test for https://github.com/dtolnay/linkme/issues/67. 23 // 24 // Must be run with `--release`. 25 #[test] win_status_illegal_instruction()26fn win_status_illegal_instruction() { 27 let mut last_address = None; 28 for item in ITEMS { 29 // Do some busy work to push the compiler into optimizing the code in a 30 // particularly "bad" way. This is derived from experimentation. 31 let address = item as *const Item as usize; 32 if let Some(last) = last_address { 33 assert_eq!(address - last, std::mem::size_of::<Item>()); 34 } 35 last_address = Some(address); 36 println!("{} {:?}", item.len(), item.name); 37 38 // Should not cause STATUS_ILLEGAL_INSTRUCTION. 39 assert_eq!(item.len(), 5); 40 } 41 } 42