public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/43220]  New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault
@ 2010-03-01 14:07 bmei at broadcom dot com
  2010-03-01 15:00 ` [Bug tree-optimization/43220] [4.3/4.4/4.5 Regression] " rguenth at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: bmei at broadcom dot com @ 2010-03-01 14:07 UTC (permalink / raw)
  To: gcc-bugs

I encountered a segmentation fault when executing an unrolled version of
20040811-1.c (tested with -O2)

void *volatile p;

int
main (void)
{
  int n = 0;
 lab:;
  {
  int x[n % 1000 + 1];
  x[0] = 1;
  x[n % 1000] = 2;
  p = x;
  n++;
  }


  {
  int x[n % 1000 + 1];
  x[0] = 1;
  x[n % 1000] = 2;
  p = x;
  n++;
  }

  if (n < 1000000)
    goto lab;

  return 0;
}

The problem is that the first pair of
__builtin_stack_save/__builtin_satck_restore of the unrolled loop is optimized
out in optimize_stack_restore (tree-ssa-ccp.c) of fab pass. Consequently, the
dynamic memory allocated grows bigger and bigger and causes segfault. The
following is from tst.c.139t.optimized


lab:
  saved_stack.1_3 = 0B;
  D.2723_4 = n_1 % 1000;
  D.2724_5 = D.2723_4 + 1;
  D.2728_15 = (long unsigned int) D.2724_5;
  D.2730_16 = D.2728_15 * 4;
  D.2732_17 = __builtin_alloca (D.2730_16);
  x.0_18 = (int[0:D.2727] *) D.2732_17;
  (*x.0_18)[0] = 1;
  (*x.0_18)[D.2723_4] = 2;
  p ={v} x.0_18;
  D.2770_66 = (unsigned int) n_1;
  D.2771_65 = D.2770_66 + 1;
  n_64 = (int) D.2771_65;
  GIMPLE_NOP
  saved_stack.3_21 = __builtin_stack_save ();
  D.2723_22 = n_64 % 1000;
  D.2734_23 = D.2723_22 + 1;
  D.2738_33 = (long unsigned int) D.2734_23;
  D.2740_34 = D.2738_33 * 4;
  D.2742_35 = __builtin_alloca (D.2740_34);
  x.2_36 = (int[0:D.2737] *) D.2742_35;
  (*x.2_36)[0] = 1;
  (*x.2_36)[D.2723_22] = 2;
  p ={v} x.2_36;
  D.2773_62 = D.2770_66 + 2;
  n_61 = (int) D.2773_62;
  __builtin_stack_restore (saved_stack.3_21);
  if (n_61 != 1000000)
    goto <bb 3> (lab);
  else
    goto <bb 4>;


-- 
           Summary: Paritially optimized
                    __builtin_save_stack/__builtin_restore_stack causes
                    segmentation fault
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bmei at broadcom dot com
GCC target triplet: x86_64-unknown-linux-gnu


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tree-optimization/43220] [4.3/4.4/4.5 Regression] Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault
  2010-03-01 14:07 [Bug tree-optimization/43220] New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault bmei at broadcom dot com
@ 2010-03-01 15:00 ` rguenth at gcc dot gnu dot org
  2010-03-01 15:16 ` rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-01 15:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2010-03-01 14:59 -------
Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.3.4 4.4.3 4.5.0
      Known to work|                            |4.2.4
   Last reconfirmed|0000-00-00 00:00:00         |2010-03-01 14:59:56
               date|                            |
            Summary|Paritially optimized        |[4.3/4.4/4.5 Regression]
                   |__builtin_save_stack/__built|Paritially optimized
                   |in_restore_stack causes     |__builtin_save_stack/__built
                   |segmentation fault          |in_restore_stack causes
                   |                            |segmentation fault
   Target Milestone|---                         |4.3.5


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tree-optimization/43220] [4.3/4.4/4.5 Regression] Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault
  2010-03-01 14:07 [Bug tree-optimization/43220] New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault bmei at broadcom dot com
  2010-03-01 15:00 ` [Bug tree-optimization/43220] [4.3/4.4/4.5 Regression] " rguenth at gcc dot gnu dot org
@ 2010-03-01 15:16 ` rguenth at gcc dot gnu dot org
  2010-03-01 16:57 ` [Bug tree-optimization/43220] [4.3/4.4 " rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-01 15:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2010-03-01 15:16 -------
The code doesn't do what it says it does.  I have a patch.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2010-03-01 14:59:56         |2010-03-01 15:16:12
               date|                            |


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tree-optimization/43220] [4.3/4.4 Regression] Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault
  2010-03-01 14:07 [Bug tree-optimization/43220] New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault bmei at broadcom dot com
  2010-03-01 15:00 ` [Bug tree-optimization/43220] [4.3/4.4/4.5 Regression] " rguenth at gcc dot gnu dot org
  2010-03-01 15:16 ` rguenth at gcc dot gnu dot org
@ 2010-03-01 16:57 ` rguenth at gcc dot gnu dot org
  2010-03-01 16:57 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-01 16:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2010-03-01 16:57 -------
Fixed for 4.5 sofar.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|4.3.4 4.4.3 4.5.0           |4.3.4 4.4.3
      Known to work|4.2.4                       |4.2.4 4.5.0
            Summary|[4.3/4.4/4.5 Regression]    |[4.3/4.4 Regression]
                   |Paritially optimized        |Paritially optimized
                   |__builtin_save_stack/__built|__builtin_save_stack/__built
                   |in_restore_stack causes     |in_restore_stack causes
                   |segmentation fault          |segmentation fault


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tree-optimization/43220] [4.3/4.4 Regression] Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault
  2010-03-01 14:07 [Bug tree-optimization/43220] New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault bmei at broadcom dot com
                   ` (2 preceding siblings ...)
  2010-03-01 16:57 ` [Bug tree-optimization/43220] [4.3/4.4 " rguenth at gcc dot gnu dot org
@ 2010-03-01 16:57 ` rguenth at gcc dot gnu dot org
  2010-03-02  7:44 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-03-01 16:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2010-03-01 16:57 -------
Subject: Bug 43220

Author: rguenth
Date: Mon Mar  1 16:57:02 2010
New Revision: 157149

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157149
Log:
2010-03-01  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/43220
        * tree-ssa-ccp.c (optimize_stack_restore): Do not optimize
        BUILT_IN_STACK_{SAVE,RESTORE} around alloca.

        * gcc.c-torture/execute/pr43220.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr43220.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-ccp.c


-- 


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tree-optimization/43220] [4.3/4.4 Regression] Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault
  2010-03-01 14:07 [Bug tree-optimization/43220] New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault bmei at broadcom dot com
                   ` (3 preceding siblings ...)
  2010-03-01 16:57 ` rguenth at gcc dot gnu dot org
@ 2010-03-02  7:44 ` jakub at gcc dot gnu dot org
  2010-03-02  7:47 ` [Bug tree-optimization/43220] [4.3 " jakub at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-03-02  7:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jakub at gcc dot gnu dot org  2010-03-02 07:44 -------
Subject: Bug 43220

Author: jakub
Date: Tue Mar  2 07:44:03 2010
New Revision: 157160

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=157160
Log:
        Backport from mainline:
        2010-03-01  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/43220
        * tree-ssa-ccp.c (optimize_stack_restore): Do not optimize
        BUILT_IN_STACK_{SAVE,RESTORE} around alloca.

        * gcc.c-torture/execute/pr43220.c: New testcase.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/execute/pr43220.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/tree-ssa-ccp.c


-- 


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tree-optimization/43220] [4.3 Regression] Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault
  2010-03-01 14:07 [Bug tree-optimization/43220] New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault bmei at broadcom dot com
                   ` (4 preceding siblings ...)
  2010-03-02  7:44 ` jakub at gcc dot gnu dot org
@ 2010-03-02  7:47 ` jakub at gcc dot gnu dot org
  2010-04-20 14:25 ` rguenth at gcc dot gnu dot org
  2010-04-20 14:25 ` rguenth at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-03-02  7:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2010-03-02 07:47 -------
Fixed also on 4.4 branch.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|4.2.4 4.5.0                 |4.2.4 4.4.4 4.5.0
            Summary|[4.3/4.4 Regression]        |[4.3 Regression] Paritially
                   |Paritially optimized        |optimized
                   |__builtin_save_stack/__built|__builtin_save_stack/__built
                   |in_restore_stack causes     |in_restore_stack causes
                   |segmentation fault          |segmentation fault


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tree-optimization/43220] [4.3 Regression] Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault
  2010-03-01 14:07 [Bug tree-optimization/43220] New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault bmei at broadcom dot com
                   ` (5 preceding siblings ...)
  2010-03-02  7:47 ` [Bug tree-optimization/43220] [4.3 " jakub at gcc dot gnu dot org
@ 2010-04-20 14:25 ` rguenth at gcc dot gnu dot org
  2010-04-20 14:25 ` rguenth at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-04-20 14:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2010-04-20 14:25 -------
Subject: Bug 43220

Author: rguenth
Date: Tue Apr 20 14:24:39 2010
New Revision: 158561

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158561
Log:
2010-04-20  Richard Guenther  <rguenther@suse.de>

        Backport from mainline:
        2010-03-01  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/43220
        * tree-ssa-ccp.c (optimize_stack_restore): Do not optimize
        BUILT_IN_STACK_{SAVE,RESTORE} around alloca.

        * gcc.c-torture/execute/pr43220.c: New testcase.

        2008-12-03  Jakub Jelinek  <jakub@redhat.com>

        PR middle-end/38360
        * tree-ssa-ccp.c (ccp_fold_builtin): Bail out if the builtin doesn't
        have the right number of arguments.

        * gcc.c-torture/compile/pr38360.c: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/compile/pr38360.c
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/execute/pr43220.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/tree-ssa-ccp.c


-- 


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug tree-optimization/43220] [4.3 Regression] Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault
  2010-03-01 14:07 [Bug tree-optimization/43220] New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault bmei at broadcom dot com
                   ` (6 preceding siblings ...)
  2010-04-20 14:25 ` rguenth at gcc dot gnu dot org
@ 2010-04-20 14:25 ` rguenth at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-04-20 14:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2010-04-20 14:24 -------
Fixed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-04-20 14:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-01 14:07 [Bug tree-optimization/43220] New: Paritially optimized __builtin_save_stack/__builtin_restore_stack causes segmentation fault bmei at broadcom dot com
2010-03-01 15:00 ` [Bug tree-optimization/43220] [4.3/4.4/4.5 Regression] " rguenth at gcc dot gnu dot org
2010-03-01 15:16 ` rguenth at gcc dot gnu dot org
2010-03-01 16:57 ` [Bug tree-optimization/43220] [4.3/4.4 " rguenth at gcc dot gnu dot org
2010-03-01 16:57 ` rguenth at gcc dot gnu dot org
2010-03-02  7:44 ` jakub at gcc dot gnu dot org
2010-03-02  7:47 ` [Bug tree-optimization/43220] [4.3 " jakub at gcc dot gnu dot org
2010-04-20 14:25 ` rguenth at gcc dot gnu dot org
2010-04-20 14:25 ` rguenth at gcc dot gnu dot org

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).