From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5314 invoked by alias); 13 Apr 2004 10:11:12 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 5275 invoked by alias); 13 Apr 2004 10:11:11 -0000 Date: Tue, 13 Apr 2004 11:17:00 -0000 From: "gcc-bugzilla at gcc dot gnu dot org" To: gcc-bugs@gcc.gnu.org Message-ID: <20040413101110.14938.bruno@clisp.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug optimization/14938] New: bug with global register variables and function pointer calls X-Bugzilla-Reason: CC X-SW-Source: 2004-04/txt/msg01063.txt.bz2 List-Id: In a function using a global register variable, that calls a function through a function pointer, the -O optimization omits the last update of the register variable before the call. Environment: System: Linux linuix 2.4.21-99-default #1 Wed Sep 24 13:30:51 UTC 2003 i686 athlon i386 GNU/Linux Architecture: i686 host: i586-suse-linux-gnu build: i586-suse-linux-gnu target: i586-suse-linux-gnu configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --disable-checking --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit i586-suse-linux How-To-Repeat: ================================== bug.c =================================== register void** STACK __asm__("%ebx"); extern void** saved_STACK; extern unsigned int func (void); extern unsigned int (*func_pointer) (void); void lisp_completion_indirect () { STACK[0] = (void*)0; STACK++; func_pointer(); saved_STACK = STACK; STACK--; } void lisp_completion_direct () { STACK[0] = (void*)0; STACK++; func(); saved_STACK = STACK; STACK--; } ============================================================================ $ gcc -Wall -O -S bug.c In the resulting bug.s, you see that the increment of %ebx before the call is omitted in the lisp_completion_indirect function. ================================== bug.s =================================== .file "bug.c" .text .globl lisp_completion_indirect .type lisp_completion_indirect, @function lisp_completion_indirect: pushl %ebp movl %esp, %ebp subl $8, %esp movl $0, (%ebx) call *func_pointer movl %ebx, saved_STACK subl $4, %ebx leave ret .size lisp_completion_indirect, .-lisp_completion_indirect .globl lisp_completion_direct .type lisp_completion_direct, @function lisp_completion_direct: pushl %ebp movl %esp, %ebp subl $8, %esp movl $0, (%ebx) addl $4, %ebx call func movl %ebx, saved_STACK subl $4, %ebx leave ret .size lisp_completion_direct, .-lisp_completion_direct .ident "GCC: (GNU) 3.3.1 (SuSE Linux)" ============================================================================ ------- Additional Comments From bruno at clisp dot org 2004-04-13 10:11 ------- Fix: The bug goes away if -O is not passed to gcc. -- Summary: bug with global register variables and function pointer calls Product: gcc Version: 3.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bruno at clisp dot org CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i586-suse-linux-gnu GCC host triplet: i586-suse-linux-gnu GCC target triplet: i586-suse-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14938