public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: wlux@uni-muenster.de
To: gcc-gnats@gcc.gnu.org
Subject: optimization/6692: Tail call optimization does not work for function pointers
Date: Fri, 17 May 2002 04:26:00 -0000	[thread overview]
Message-ID: <20020517112107.15169.qmail@sources.redhat.com> (raw)


>Number:         6692
>Category:       optimization
>Synopsis:       Tail call optimization does not work for function pointers
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Fri May 17 04:26:05 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Wolfgang Lux
>Release:        gcc version 3.1
>Organization:
>Environment:
Sparc Solaris 2.8
gcc configured with: --program-suffix=-3.1 --enable-languages=c
>Description:
The tail call optimization introduced in Gnu C version 3
does not work if the tail call is made through a function
pointer, e.g.

int exec(int (*f)(int), int n)
{
    return (*f)(n);
}

The code generated for this function calls the function
passed via f recursively in a new stack frame instead of
releasing exec's stack frame and jumping to f's entry-point.
>How-To-Repeat:
Compile bug.c with -O2 and run the executable. It crashes
with a Segmentation Fault due to a stack overflow (can be
confirmed with gdb).
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="bug.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug.c"

aW50IGYxKGludCksIGYyKGludCk7CQkvKiBmdW5jdGlvbiBwcm90b3R5cGVzICovCmludCBnMShp
bnQpLCBnMihpbnQpOwppbnQgZXhlYyhpbnQgKCopKGludCksIGludCk7CgovKiBkaXJlY3QgY2Fs
bCAqLwppbnQgZjEoaW50IG4pCnsKICAgIHJldHVybiBmMihuICsgMSk7Cn0KCmludCBmMihpbnQg
bikKewogICAgcmV0dXJuIGYxKG4gKyAxKTsKfQoKLyogaW5kaXJlY3QgY2FsbHMgKi8KaW50IGcx
KGludCBuKQp7CiAgICByZXR1cm4gZXhlYyhnMiwgbiArIDEpOwp9CgppbnQgZzIoaW50IG4pCnsK
ICAgIHJldHVybiBleGVjKGcxLCBuICsgMSk7Cn0KCmludCBleGVjKGludCAoKmYpKGludCksIGlu
dCBuKQp7CiAgICByZXR1cm4gKCpmKShuKTsKfQoKCi8qIG1haW4gZnVuY3Rpb24gKi8KaW50IG1h
aW4oKQp7CiNpZmRlZiBJTkZJTklURQogICAgLyogdGhpcyBlbnRlcnMgYW4gaW5maW5pdGUgbG9v
cCAqLwogICAgZjEoMCk7CgojZWxzZQogICAgLyogdGhpcyBjYWxsIGNyYXNoZXMgd2l0aCBhIHN0
YWNrIG92ZXJmbG93ICovCiAgICBnMSgwKTsKI2VuZGlmCn0K


             reply	other threads:[~2002-05-17 11:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-17  4:26 wlux [this message]
2003-02-19 10:18 ebotcazou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020517112107.15169.qmail@sources.redhat.com \
    --to=wlux@uni-muenster.de \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).