User account creation filtered due to spam.

Bug 8750 - Cygwin prolog generation erroneously emitting __alloca as regular function call
Summary: Cygwin prolog generation erroneously emitting __alloca as regular function call
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: 3.3
Assignee: Danny Smith
URL:
Keywords:
: 8437 9185 9647 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-11-28 13:26 UTC by fish
Modified: 2004-07-17 01:35 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
fish2.zip (6.59 KB, application/x-zip )
2003-05-21 15:17 UTC, fish
Details

Note You need to log in before you can comment on or make changes to this bug.
Description fish 2002-11-28 13:26:00 UTC
(Note: please ignore my prior email to gcc-bugs@gcc.gnu.org as this bug report replaces it. The .zip file included in my priot email didn't include the -save-temps .i output, whereas the .zip file attached to this report does)

Dr. Ulrich Weigand (weigand@informatik.uni-erlangen.de) has analyzed this bug as follows:

"This would appear to be a gcc bug.  Specifically, what appears to happen here is that instruction scheduling moves the leal across the call to __alloca.  This in turn is caused by a bug in the cygwin prolog generation code that emits the __alloca call as a regular function call."
  
"As regular function calls do not change the stack pointer, the instruction scheduling pass concluded that it was safe to move the leal 16(%esp),%edi across the call (%edi is preserved across calls as well)."
  
"Instead, the __alloca call should have been annotated to express the fact that it changes %esp in a special way. How to best fix this I'd leave to the i386 backend maintainers; please report this bug (with testcase and explanation) to the gcc bug-tracking system."
  
"(From what I can see, the same bug exists unchanged in gcc 3.2.1 and the current pre-3.3 sources. As this particular code path is only used for cygwin, it probably wasn't noticed earlier ...)"

Release:
gcc version 3.2 20020927 (prerelease)

Environment:
PIII 800MHz
Windows 2000 Pro SP3
Cygwin 1.3.16-1
gcc 3.2-3

$ uname -a
CYGWIN_NT-5.0 (censored) 1.3.16(0.65/3/2) 2002-11-22 22:18 i686 unknown

How-To-Repeat:
fish@foobar ~/fishtest
$ cat fish.c
#include <stdio.h>
#include <string.h>

void foo ()
{
    char a[15000];
    a[0]=0;
    printf("String length=%d\n",strlen(a));
    memset( &a[0], 0xCD, 13371 );
    a[13371]=0;
    printf("String length=%d\n",strlen(a));
}

int main ( int argc, char* argv[] )
{
    foo();
    return 0;
}

fish@foobar ~/fishtest
$ gcc -march=i686 -g -O2 -fomit-frame-pointer -c fish.c
-Wa,-adhln=fish.c.listing.txt

fish@foobar ~/fishtest
$ gcc -march=i686 -g -O2 -fomit-frame-pointer -o fish.exe fish.o

fish@foobar ~/fishtest
$ fish
String length=2
Comment 1 fish 2002-11-28 13:26:00 UTC
Fix:
1. -O0 or -O1, or...
2. -fno-omit-frame-pointer, or...
3. use memset len < 13371, or...
4. don't use largish local stack vars so as to prevent __alloca from being called/used.
Comment 2 danny_r_smith_2001 2002-12-20 06:06:43 UTC
From: =?iso-8859-1?q?Danny=20Smith?= <danny_r_smith_2001@yahoo.co.nz>
To: hercules-390@yahoogroups.com, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org,
  zHercules@yahoogroups.com, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org,
  fish@infidels.org
Cc:  
Subject: Re: optimization/8750: Cygwin prolog generation erroneously emitting __alloca as regular function call
Date: Fri, 20 Dec 2002 06:06:43 +1100 (EST)

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8750
 
 The followin fixes PR optimization/8750, a serious regression from 2.95
 on W32 targets (which set TARGET_STACK_PROBE) 
 
 Tested on 3.2 and 3.3 branches with i386-pc-mingw32.
 
 Can someone with more knowledge of 1386 backend please review and
 perhaps suggest less naive fix.
 
 ChangeLog
 
 2002-12-19  Danny Smith  <dannysmith@users.sourceforge.net>
 
 	PR optimization/8750
 	* config/i386/i386.c (ix86_expand_prologue): Don't allow
 	scheduling pass to move insns across __alloca call.
 
 
 Index: i386.c
 ===================================================================
 RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
 retrieving revision 1.495
 diff -c -3 -p -r1.495 i386.c
 *** i386.c	9 Dec 2002 23:53:59 -0000	1.495
 --- i386.c	19 Dec 2002 10:44:08 -0000
 *************** ix86_expand_prologue ()
 *** 4516,4521 ****
 --- 4516,4525 ----
         CALL_INSN_FUNCTION_USAGE (insn)
   	= gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, arg0),
   			     CALL_INSN_FUNCTION_USAGE (insn));
 + 
 +       /* Don't allow scheduling pass to move insns across __alloca
 +          call.  */
 +       emit_insn (gen_blockage (const0_rtx));
       }
     if (use_mov)
       {
 
 http://greetings.yahoo.com.au - Yahoo! Greetings
 - Send your seasons greetings online this year!

Comment 3 Richard Henderson 2003-01-09 02:34:52 UTC
From: rth@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/8750
Date: 9 Jan 2003 02:34:52 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	rth@gcc.gnu.org	2003-01-08 18:34:52
 
 Modified files:
 	gcc            : ChangeLog 
 	gcc/config/i386: i386.c 
 
 Log message:
 	PR optimization/8750
 	* config/i386/i386.c (ix86_expand_prologue): Don't allow
 	scheduling pass to move insns across __alloca call.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.16298&r2=1.16299
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&r1=1.506&r2=1.507
 

Comment 4 Richard Henderson 2003-01-09 02:35:48 UTC
From: rth@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/8750
Date: 9 Jan 2003 02:35:48 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_3-branch
 Changes by:	rth@gcc.gnu.org	2003-01-08 18:35:48
 
 Modified files:
 	gcc            : ChangeLog 
 	gcc/config/i386: i386.c 
 
 Log message:
 	PR optimization/8750
 	* config/i386/i386.c (ix86_expand_prologue): Don't allow
 	scheduling pass to move insns across __alloca call.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.46&r2=1.16114.2.47
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.495.2.2&r2=1.495.2.3
 

Comment 5 Danny Smith 2003-01-09 03:07:46 UTC
From: dannysmith@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/8750
Date: 9 Jan 2003 03:07:46 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	cygwin-mingw-v2-branch
 Changes by:	dannysmith@gcc.gnu.org	2003-01-08 19:07:46
 
 Modified files:
 	gcc            : ChangeLog.cygwin-mingw 
 	gcc/config/i386: i386.c 
 
 Log message:
 	Backport from 3.3
 	PR optimization/8750
 	* config/i386/i386.c (ix86_expand_prologue): Don't allow
 	scheduling pass to move insns across __alloca call.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.cygwin-mingw.diff?cvsroot=gcc&only_with_tag=cygwin-mingw-v2-branch&r1=1.1.4.1&r2=1.1.4.2
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&only_with_tag=cygwin-mingw-v2-branch&r1=1.368.2.19.2.8.2.1&r2=1.368.2.19.2.8.2.2
 
Comment 6 Eric Botcazou 2003-02-18 13:48:54 UTC
Responsible-Changed-From-To: unassigned->dannysmith
Responsible-Changed-Why: Submitter of the fix.
Comment 7 Eric Botcazou 2003-02-18 13:48:54 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Do you plan to backport the patch to the 3.2 branch? If no, please close the bug.
Comment 8 Danny Smith 2003-02-23 21:50:15 UTC
From: Danny Smith <dannysmith@clear.net.nz>
To: gcc-gnats@gcc.gnu.org, zHercules@yahoogroups.com, gcc-bugs@gcc.gnu.org,
 dannysmith@sources.redhat.com, gcc-prs@gcc.gnu.org, fish@infidels.org,
 hercules-390@yahoogroups.com
Cc:  
Subject: Re: optimization/8750: Cygwin prolog generation erroneously emitting
 __alloca as regular function call
Date: Sun, 23 Feb 2003 21:50:15 +0000

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=g
 cc&pr=8750
 
 Patch for 3_2-branch is at:
 http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01482.html
 
Comment 9 Danny Smith 2003-04-29 00:50:47 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed in 3.3
Comment 10 Andrew Pinski 2003-05-28 13:07:30 UTC
*** Bug 9185 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2003-05-28 13:12:46 UTC
*** Bug 8437 has been marked as a duplicate of this bug. ***
Comment 12 CVS Commits 2003-10-12 17:10:14 UTC
Subject: Bug 8750

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	kcook@gcc.gnu.org	2003-10-12 17:10:12

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20031012-1.c 

Log message:
	PR optimization/8750
	* gcc.c-torture/execute/20031012-1.c: New Test Case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3115&r2=1.3116
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20031012-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1