public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: lucho@haemimont.bg
To: gcc-gnats@gcc.gnu.org
Subject: optimization/6398: faulty code when inlining in a var-arged function
Date: Sun, 21 Apr 2002 13:16:00 -0000	[thread overview]
Message-ID: <20020421201107.8785.qmail@sources.redhat.com> (raw)


>Number:         6398
>Category:       optimization
>Synopsis:       faulty code when inlining in a var-arged function
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 21 13:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Luchezar Belev
>Release:        gcc-3.0
>Organization:
>Environment:
pentium III; linux-2.4.6; glibc-2.2 (does it matter?)
>Description:
This is some combination of:
 1) function inlining (-O3)
 2) no frame pointer (-fomit-frame-pointer)
 2) var-args
and it seems like this is somehow confusing GCC 3.0
so it generates incorrect code
(haven't tested other GCC versions)
>How-To-Repeat:
compile this source with -O3 and -fomit-frame-pointer
and see the comment

----begin----
#include <stdarg.h>
#include <stdio.h>

/*
	compile with these options: -O3 -fomit-frame-pointer
	to let the bug to appear
	
	The expected output of this code is "AAAAxyz\n" printed out on the console
	and it does so when compiled with -O2 (or lower) or without -fomit-frami-pointer

	One fact i've discovered that may be a hint:
	in the assembly output, near the beginning of f2() function
	one can notice that %ebp is used for addressing ("movl 4(%ebp), %ecx")
	before it is loaded with some meaningful value for this purpose
*/

static void f1(unsigned p, char *fmt, va_list args)
{
	char *h[2] = {"AAAA", "BBBB"};
	char buf[128];
	int l;
	
	if (p > 1) return;
	l = strlen(h[p]);
	memcpy(buf, h[p], l);
	vsnprintf(buf + l, 128 - l, fmt, args);
	puts(buf);
}

void f2(int p, char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	f1(p, fmt, args);
	va_end(args);
}

int main()
{
	f2(0, "xyz\n");
	return 0;
}
----end----
>Fix:
don't know how to fix, but found a clue that may help: see the comment in the source
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-04-21 20:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-21 13:16 lucho [this message]
2002-04-21 13:46 Andrew Pinski
2002-04-21 14:45 jakub
2002-04-22  9:46 lucho
2002-12-06 15:30 reichelt

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=20020421201107.8785.qmail@sources.redhat.com \
    --to=lucho@haemimont.bg \
    --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).