http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58818
Bug ID: 58818 Summary: parameters optimized out using -O2 Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: inline-asm Assignee: unassigned at gcc dot gnu.org Reporter: gonwan at gmail dot com # cat testasm2.c #include <stdio.h> int add3(int a, int b) { int res; __asm__ __volatile__ ("movl 12(%%ebp), %%eax\n\t" "addl 8(%%ebp), %%eax" : "=a" (res) ); return res; } int main() { int ret; ret = add3(5, 6); printf("ret3=%d\n", ret); return 0; } # gcc testasm2.c -o testasm2 # ./testasm2 ret3=11 # gcc -O2 testasm2.c -o testasm2 # ./testasm2 ret3=-1078224411 Output of gcc -S -O2: main: .LFB23: .cfi_startproc pushl %ebp .cfi_def_cfa_offset 8 .cfi_offset 5, -8 movl %esp, %ebp .cfi_def_cfa_register 5 andl $-16, %esp subl $16, %esp # <-- no parameter is passed after sub %esp. #APP # 6 "testasm2.c" 1 movl 12(%ebp), %eax addl 8(%ebp), %eax # 0 "" 2 #NO_APP movl %eax, 8(%esp) movl $.LC0, 4(%esp) movl $1, (%esp) call __printf_chk xorl %eax, %eax leave .cfi_restore 5 .cfi_def_cfa 4, 4 ret .cfi_endproc No parameter is passed after sub %esp. gcc 4.6/4.7/4.8 can reproduce this.