This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug inline-asm/58819] New: return value ignored using -O2
- From: "gonwan at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 21 Oct 2013 06:58:46 +0000
- Subject: [Bug inline-asm/58819] New: return value ignored using -O2
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58819
Bug ID: 58819
Summary: return value ignored 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 testasm.c
#include <stdio.h>
int add1(int a, int b)
{
__asm__ __volatile__ ("movl 12(%ebp), %eax\n\t"
"addl 8(%ebp), %eax"
);
}
int add2(int a, int b)
{
__asm__ __volatile__ ("movl 12(%%ebp), %%eax\n\t"
"addl 8(%%ebp), %%eax"
: : : "%eax"
);
}
int main()
{
int ret;
ret = add1(1, 2);
printf("ret1=%d\n", ret);
ret = add2(3, 4);
printf("ret2=%d\n", ret);
return 0;
}
# gcc testasm.c -o testasm
# ./testasm
ret1=3
ret2=7
# gcc -O2 testasm.c -o testasm
# ./testasm
ret1=0
ret2=0
Output of gcc -S -O2:
main:
.LFB24:
.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
#APP
# 5 "testasm.c" 1
movl 12(%ebp), %eax
addl 8(%ebp), %eax
# 0 "" 2
#NO_APP
movl $0, 8(%esp) # <-- 0 is passed to print
movl $.LC0, 4(%esp)
movl $1, (%esp)
call __printf_chk
#APP
# 12 "testasm.c" 1
movl 12(%ebp), %eax
addl 8(%ebp), %eax
# 0 "" 2
#NO_APP
movl $0, 8(%esp) # <-- 0 is passed to print
movl $.LC1, 4(%esp)
movl $1, (%esp)
call __printf_chk
xorl %eax, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
0 is passed to print, even %eax is added to clobber list. gcc 4.6/4.7/4.8 can
reproduce this.