{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/27060","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/27060/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/27060/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/27060/events","html_url":"https://github.com/rust-lang/rust/issues/27060","id":95338985,"number":27060,"title":"repr(packed) allows invalid unaligned loads","user":{"login":"huonw","id":1203825,"avatar_url":"https://avatars.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-crash","name":"I-crash","color":"e10c02"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/P-high","name":"P-high","color":"eb6420"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/T-compiler","name":"T-compiler","color":"bfd4f2"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/T-lang","name":"T-lang","color":"bfd4f2"}],"state":"open","locked":false,"assignee":{"login":"huonw","id":1203825,"avatar_url":"https://avatars.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"milestone":null,"comments":20,"created_at":"2015-07-16T03:15:21Z","updated_at":"2015-07-25T21:51:44Z","closed_at":null,"body":"```rust\r\n#![feature(simd, test)]\r\n\r\nextern crate test;\r\n\r\n// simd types require high alignment or the CPU faults\r\n#[simd]\r\n#[derive(Debug, Copy, Clone)]\r\nstruct f32x4(f32, f32, f32, f32);\r\n\r\n#[repr(packed)]\r\n#[derive(Copy, Clone)]\r\nstruct Unalign<T>(T);\r\n\r\nstruct Breakit {\r\n    x: u8,\r\n    y: Unalign<f32x4>\r\n}\r\n\r\nfn main() {\r\n    let val = Breakit { x: 0, y: Unalign(f32x4(0.0, 0.0, 0.0, 0.0)) };\r\n    \r\n    test::black_box(&val);\r\n    \r\n    println!(\"before\");\r\n    \r\n    let ok = val.y;\r\n    test::black_box(ok.0);\r\n    \r\n    println!(\"middle\");\r\n    \r\n    let bad = val.y.0;\r\n    test::black_box(bad);\r\n    \r\n    println!(\"after\");\r\n}\r\n```\r\n\r\nWill print, on playpen:\r\n\r\n```\r\nbefore\r\nmiddle\r\nplaypen: application terminated abnormally with signal 4 (Illegal instruction)\r\n```\r\n\r\nThe assembly for the `ok` load is:\r\n\r\n```asm\r\n\tmovups\t49(%rsp), %xmm0\r\n\tmovaps\t%xmm0, (%rsp)\r\n\t#APP\r\n\t#NO_APP\r\n```\r\n\r\nBut for the `bad` one, it is\r\n\r\n```asm\r\n\tmovaps\t49(%rsp), %xmm0\r\n\tmovaps\t%xmm0, (%rsp)\r\n\t#APP\r\n\t#NO_APP\r\n```\r\n\r\nSpecifically, the `movups` (unaligned) became a `movaps` (aligned), but the pointer isn't actually aligned, hence the CPU faults."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/124901652","html_url":"https://github.com/rust-lang/rust/issues/27060#issuecomment-124901652","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/27060","id":124901652,"user":{"login":"retep998","id":666308,"avatar_url":"https://avatars.githubusercontent.com/u/666308?v=3","gravatar_id":"","url":"https://api.github.com/users/retep998","html_url":"https://github.com/retep998","followers_url":"https://api.github.com/users/retep998/followers","following_url":"https://api.github.com/users/retep998/following{/other_user}","gists_url":"https://api.github.com/users/retep998/gists{/gist_id}","starred_url":"https://api.github.com/users/retep998/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/retep998/subscriptions","organizations_url":"https://api.github.com/users/retep998/orgs","repos_url":"https://api.github.com/users/retep998/repos","events_url":"https://api.github.com/users/retep998/events{/privacy}","received_events_url":"https://api.github.com/users/retep998/received_events","type":"User","site_admin":false},"created_at":"2015-07-25T21:51:44Z","updated_at":"2015-07-25T21:51:44Z","body":"I use and need `repr(packed)` for one of my libraries, because I do memory mapping tricks. I'm fine with it being unsafe, just as long as I can continue to use it from within stable Rust."}}