--- Begin Message ---
- To: Debian Bug Tracking System <submit@bugs.debian.org>
- Subject: GCC generate wrong code for infinitely recursive functions
- From: Samuel Tardieu <sam@rfc1149.net>
- Date: Sat, 06 Oct 2007 18:07:21 +0200
- Message-id: <20071006160721.27413.54706.reportbug@willow.rfc1149.net>
Package: gcc-4.2
Version: 4.2.1-5
Severity: normal
% cat > t.c << EOF
void foo()
{ foo(); }
EOF
% gcc -O -S -o - -fomit-frame-pointer -Wall t.c
.file "t.c"
.text
.globl foo
.type foo, @function
foo:
rep ; ret
.size foo, .-foo
.ident "GCC: (GNU) 4.2.1 (Debian 4.2.1-5)"
.section .note.GNU-stack,"",@progbits
As far as I know, there are two acceptable behaviours for function foo():
- loop indefinitely (if tail recursion is used)
- overflow the stack (if tail recursion is not used)
As soon as -O is used on x86-32, GCC generates code that just returns
("rep ; ret").
Note that the bug is also present with the following Ada program:
procedure U
begin
U;
end U;
although the Ada front-end warns about a possibly infinite recursion. The
very same code gets generated.
This may be platform-specific and generates bogus code with any non-O0
optimization level.
-- System Information:
Debian Release: lenny/sid
APT prefers unstable
APT policy: (990, 'unstable'), (500, 'testing'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.22-rc5
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to en_US.UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages gcc-4.2 depends on:
ii binutils 2.18-1 The GNU assembler, linker and bina
ii cpp-4.2 4.2.1-5 The GNU C preprocessor
ii gcc-4.2-base 4.2.1-5 The GNU Compiler Collection (base
ii libc6 2.6.1-5 GNU C Library: Shared libraries
ii libgcc1 1:4.2.1-5 GCC support library
ii libgomp1 4.2.1-5 GCC OpenMP (GOMP) support library
Versions of packages gcc-4.2 recommends:
ii libc6-dev 2.6.1-5 GNU C Library: Development Librari
ii libmudflap0-4.2-dev 4.2.1-5 GCC mudflap support libraries (dev
-- no debconf information
--- End Message ---