From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10927 invoked by alias); 21 Oct 2013 06:47:33 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 10883 invoked by uid 48); 21 Oct 2013 06:47:29 -0000 From: "gonwan at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug inline-asm/58818] New: parameters optimized out using -O2 Date: Mon, 21 Oct 2013 06:47:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: inline-asm X-Bugzilla-Version: 4.8.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gonwan at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-10/txt/msg01433.txt.bz2 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 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.