This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/33826] New: GCC generates wrong code for infinitely recursive functions


[ forwarded from http://bugs.debian.org/445536 ]

From: Samuel Tardieu <sam@rfc1149.net>

% 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 is
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.


-- 
           Summary: GCC generates wrong code for infinitely recursive
                    functions
           Product: gcc
           Version: 4.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tbm at cyrius dot com
GCC target triplet: x86_64-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33826


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]