Logo
Explore Help
Register Sign In
rust-lang/rust
1
0
Fork 0
You've already forked rust
Code Issues Pull Requests Actions 1 Packages Projects Releases Wiki Activity
Files
1fc3a00c90e7d4ba53a8fb7464a7f8cbfa8470a2
rust/tests/compile-fail/reference_to_packed.rs

17 lines
282 B
Rust
Raw Normal View History

fix some unaligned reads
2017-01-31 10:36:46 +01:00
#![allow(dead_code, unused_variables)]
#[repr(packed)]
struct Foo {
x: i32,
y: i32,
}
fn main() {
let foo = Foo {
x: 42,
y: 99,
};
No longer check aligment and non-NULLness on `&` This breaks creating unaligned raw pointers via `&packed.field as *const _`, which needs to be legal. Also it doesn't seem like LLVM still relies on this, see * https://github.com/solson/miri/issues/244#issuecomment-315563640 * https://internals.rust-lang.org/t/rules-for-alignment-and-non-nullness-of-references/5430/16 We probably want to handle this invariant like the others that validation is concerned with, and only check it on function boundaries for now.
2017-07-19 11:28:35 -07:00
let p = &foo.x;
let i = *p; //~ ERROR tried to access memory with alignment 1, but alignment 4 is required
check alignment of pointers on Ref
2017-06-22 21:01:24 -07:00
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.24.6 Page: 176ms Template: 3ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API