Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Prove that the compiler is doing pointer operations
- * for references.
- */
- struct integer {
- i: u32,
- }
- fn main() {
- /*
- * Note: generated asm is not-optimized.
- *
- * Because of compiler alignment preferences,
- * 4 + 8 + 4 (=16) sized locals are given 24 bytes.
- */
- /*
- * i1 goes on the stack at 4(rsp)
- * movl $1, 4(rsp)
- */
- let i1: integer = integer { i: 1 };
- /*
- * pointer copy
- * the address of i1 goes on the stack
- * at 8(rsp).
- * leaq 4(rsp), rax)
- * movq rax, 8(rsp)
- */
- let i2: &integer = &i1;
- /*
- * value copy
- * the 'long' value on the stack at
- * 4(rsp) gets copied to 12(rsp).
- * movl 4(rsp), ecx
- * movl ecx, 20(rsp)
- */
- let i3: integer = i1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement