I used rustc emit llvm ir. However, the struct type is reordered. After digging into some online posts, it seems that there was an optimization step between MIR and LLVM IR that optimizes the layout of the struct type, and rustc has the flag to tune the optimization level.
My question is which optimization specifically that is responsible for this optimization? According to this post: Optimizing Rust Struct Size: A 6-month Compiler Development Project | Blindly Coding
I should be able to use
rustc source_program.rs --emit=llvm-ir -Z fuel="crate"=0
to turn off the optimization, so that the field in the struct type in the llvm ir is the same as the source code.
If this is not the right way to achieve the alignment of field between llvm ir and the source, are there any other ways?