]> git.lizzy.rs Git - rust.git/commit
Emit correct alignment information for loads/store of small aggregates
authorBjörn Steinbrink <bsteinbr@gmail.com>
Wed, 15 Apr 2015 18:14:54 +0000 (20:14 +0200)
committerBjörn Steinbrink <bsteinbr@gmail.com>
Sat, 18 Apr 2015 16:32:14 +0000 (18:32 +0200)
commit78745a4afe90fc5f24b9fa3af6a31551859419f8
tree48bd308ab7f04a46b62217c3f0067cc10e07cd8d
parentfcf637b19f1a94dcf1748b8b29fca100f150eb0a
Emit correct alignment information for loads/store of small aggregates

Loading from and storing to small aggregates happens by casting the
aggregate pointer to an appropriately sized integer pointer to avoid
the usage of first class aggregates which would lead to less optimized
code.

But this means that, for example, a tuple of type (i16, i16) will be
loading through an i32 pointer and because we currently don't provide
alignment information LLVM assumes that the load should use the ABI
alignment for i32 which would usually be 4 byte alignment. But the
alignment requirement for the (i16, i16) tuple will usually be just 2
bytes, so we're overestimating alignment, which invokes undefined
behaviour.

Therefore we must emit appropriate alignment information for
stores/loads through such casted pointers.

Fixes #23431
src/librustc_trans/trans/adt.rs
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/build.rs
src/librustc_trans/trans/builder.rs
src/librustc_trans/trans/foreign.rs
src/librustc_trans/trans/intrinsic.rs