public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/58818] New: parameters optimized out using -O2
@ 2013-10-21  6:47 gonwan at gmail dot com
  2013-10-21  6:50 ` [Bug inline-asm/58818] " pinskia at gcc dot gnu.org
  2013-10-21  7:12 ` jakub at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: gonwan at gmail dot com @ 2013-10-21  6:47 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-10-21  7:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-21  6:47 [Bug inline-asm/58818] New: parameters optimized out using -O2 gonwan at gmail dot com
2013-10-21  6:50 ` [Bug inline-asm/58818] " pinskia at gcc dot gnu.org
2013-10-21  7:12 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).