Description
I've noticed some code will miscompile and produce unexpected results depending on the alignment of members in a struct. I'm compiling from LLVM IR output by the Rust compiler.
The following test case IR fails to work properly when run through emcc: main.ll (original source)
It should end in an exit code of 2 (to signify the enum being of value Enum::B), but instead exits with 1, as the object's contents are corrupt after the two clones. Various other targets using this same IR (lli
, llc -filetype=obj
, NaCl compilation to pexe/nexe, etc.) all produce the expected result. Changing the first field of the Test struct to u32 hides the issue and returns 2 as expected.
I have tried this on both incoming and merge-pnacl-mar-13-2015. I can provide more info or some other versions compiled at different optimization levels if needed. Unfortunately I don't know enough about LLVM IR and Emscripten to follow along what's actually happening here... It seems to be that stores into fields on a new copy of the object can sometimes just fail in strange ways.