Bug 24225 - [4.1 Regression] ICE: segmentation fault in profile.c:branch_prob
Summary: [4.1 Regression] ICE: segmentation fault in profile.c:branch_prob
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Steven Bosscher
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2005-10-06 08:31 UTC by Richard Biener
Modified: 2005-10-24 21:19 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.2
Known to fail: 4.1.0
Last reconfirmed: 2005-10-06 11:21:00


Attachments
testcase (63.89 KB, text/plain)
2005-10-06 08:32 UTC, Richard Biener
Details
Hack that makes the test case work. Needs testing. (745 bytes, patch)
2005-10-20 21:03 UTC, Steven Bosscher
Details | Diff
Alternate fix (609 bytes, patch)
2005-10-20 21:40 UTC, Steven Bosscher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2005-10-06 08:31:20 UTC
/usr/lib/gcc/i586-suse-linux/4.1.0/cc1 -fpreprocessed builtin.i -quiet -dumpbase builtin.c -march=i586 -mtune=i686 -auxbase-strip builtin.o -O2 -Wall -Wall -version -fmessage-length=0 -fno-strict-aliasing -fprofile-arcs -o builtin.s
builtin.c: In function ‘execbuiltin’:
builtin.c:5173: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://www.suse.de/feedback> for instructions.

(gdb) bt
#0  0x0846db4d in branch_prob () at profile.c:815
#1  0x0852f803 in tree_profiling () at tree-profile.c:246
#2  0x0852f0cd in execute_one_pass (pass=0x8777060) at passes.c:827
#3  0x0852f18c in execute_pass_list (pass=0x8777060) at passes.c:859
#4  0x0852f260 in execute_ipa_pass_list (pass=0x8774a60) at passes.c:881
#5  0x085911d1 in ipa_passes () at cgraphunit.c:1221
#6  0x0859127c in cgraph_optimize () at cgraphunit.c:1255
#7  0x08068379 in c_write_global_declarations () at c-decl.c:7644
#8  0x084df96f in compile_file () at toplev.c:1003
#9  0x084e103c in do_compile () at toplev.c:1933
#10 0x084e10a4 in toplev_main (argc=19, argv=0xbf9bf844) at toplev.c:1965
#11 0x080d9b90 in main (argc=19, argv=0xbf9bf844) at main.c:35
Comment 1 Richard Biener 2005-10-06 08:32:03 UTC
Created attachment 9900 [details]
testcase

Preprocessed testcase
Comment 2 Richard Biener 2005-10-06 11:15:44 UTC
Reducing.
Comment 3 Richard Biener 2005-10-06 11:21:00 UTC
Reduced testcase:

    typedef struct linklist *LinkList;
     typedef struct options *Options;
     typedef struct builtin *Builtin;
     struct options {
   };
     typedef int (*HandlerFunc) (char *, char **, Options, int);
     struct builtin {
       HandlerFunc handlerfunc;
       int funcid;
   };
     enum { XTRACE, OPT_SIZE };
     extern char opts[OPT_SIZE];
     int execbuiltin(LinkList args, Builtin bn) {
       char *pp, *name, *optstr;
       int flags, sense, argc, execop, xtr = (opts[XTRACE]);
       struct options ops;
       if (!bn->handlerfunc) {
   return 1;
      }
       {
   char * (argarr)[argc + 1];
   char **argv;
   return (*(bn->handlerfunc)) (name, argv, &ops, bn->funcid);
      }
   }
Comment 4 Serge Belyshev 2005-10-06 11:47:38 UTC
// smaller testcase, compile with -O1 -fprofile-arcs

int f (int a, int b)
{
  if (a)
    return 1;
  {
    int s [b];
    return 0;
  }
}
Comment 5 Andrew Pinski 2005-10-06 13:51:42 UTC
  saved_stack.3 = __builtin_stack_save ();
  [t.c : 6] b.0 = b;


For last, we don't have a line number associated with it.
Comment 6 janis187 2005-10-07 19:36:49 UTC
A regression hunt on powerpc-linux using the testcase from comment #4
identified this patch from hubicka@gcc.gnu.org:

  http://gcc.gnu.org/ml/gcc-cvs/2005-08/msg00101.html
Comment 7 Richard Biener 2005-10-20 09:16:39 UTC
Honza, can you have a look at this (now that you appear to be back)?
Comment 8 Steven Bosscher 2005-10-20 21:03:42 UTC
Created attachment 10035 [details]
Hack that makes the test case work.  Needs testing.
Comment 9 Steven Bosscher 2005-10-20 21:40:48 UTC
Created attachment 10036 [details]
Alternate fix

As suggested by Andrew Pinski...

Put loci on the stack save and restore operations.

This gives:

f (a, b)
{
  intD.0 sD.1611[0:D.1616];
  voidD.35 * saved_stack.2D.1623;
  voidD.35 * D.1622;
  intD.0[0:D.1616] * s.1D.1621;
  long unsigned intD.4 D.1620;
  bit_size_type D.1619;
  bit_size_type D.1618;
  long unsigned intD.4 D.1617;
  long unsigned intD.4 D.1616;
  long intD.2 D.1615;
  long intD.2 D.1614;
  intD.0 b.0D.1613;
  intD.0 D.1612;

  # BLOCK 0, starting at line 5
  # PRED: ENTRY
  [t.c : 5] if ([t.c : 5] aD.1607 != 0) goto <L0>; else  goto <L1>;
  # SUCC: 1 2

  # BLOCK 1, starting at line 6
  # PRED: 0
<L0>:;
  [t.c : 6] D.1612 = 1;
  [t.c : 6] goto <bb 3> (<L3>);
  # SUCC: 3

  # BLOCK 2, starting at line 8
  # PRED: 0
<L1>:;
  [t.c : 8] saved_stack.2D.1623 = __builtin_stack_save ();
  [t.c : 8] b.0D.1613 = bD.1608;
  [t.c : 8] D.1614 = (long intD.2) b.0D.1613;
  [t.c : 8] D.1615 = D.1614 - 1;
  [t.c : 8] D.1616 = (long unsigned intD.4) D.1615;
  [t.c : 8] D.1617 = (long unsigned intD.4) b.0D.1613;
  [t.c : 8] D.1618 = (bit_size_type) D.1617;
  [t.c : 8] D.1619 = D.1618 * 32;
  [t.c : 8] D.1617 = (long unsigned intD.4) b.0D.1613;
  [t.c : 8] D.1620 = D.1617 * 4;
  [t.c : 8] D.1617 = (long unsigned intD.4) b.0D.1613;
  [t.c : 8] D.1618 = (bit_size_type) D.1617;
  [t.c : 8] D.1619 = D.1618 * 32;
  [t.c : 8] D.1617 = (long unsigned intD.4) b.0D.1613;
  [t.c : 8] D.1620 = D.1617 * 4;
  [t.c : 8] D.1622 = [t.c : 8] __builtin_alloca (D.1620);
  [t.c : 8] s.1D.1621 = (intD.0[0:D.1616] *) D.1622;
  [t.c : 9] D.1612 = 0;
  [t.c : 9] __builtin_stack_restore (saved_stack.2D.1623);
  # SUCC: 3

  # BLOCK 3
  # PRED: 1 2
<L3>:;
  return D.1612;
  # SUCC: EXIT

}
Comment 10 Steven Bosscher 2005-10-20 22:45:04 UTC
The second fix boostraps the compiler proper and it builds libstdc++ and libgfortran without problems.  But it fails on cp-demangle.c for some reason.  That's probably another case where we don't put a locus on statements in a gimplified statement list.  Fixing that, who knows where else we'll discover similar problems...

Therefore, at least for GCC 4.1 I'm more comfortable with my first patch.  I'll bootstrap+test and profilebootstrap that patch and post it for comment if it doesn't cause any regressions.

Comment 11 GCC Commits 2005-10-24 19:21:00 UTC
Subject: Bug 24225

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	steven@gcc.gnu.org	2005-10-24 19:20:38

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc            : ChangeLog profile.c 
Added files:
	gcc/testsuite/gcc.dg: pr24225.c 

Log message:
	PR tree-optimization/24225
	
	gcc/
	* profile.c (branch_prob): Look from end to start through a
	basic block when looking for a locus.
	
	testsuite/
	* gcc.dg/pr24225.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr24225.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6242&r2=1.6243
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.10210&r2=2.10211
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/profile.c.diff?cvsroot=gcc&r1=1.164&r2=1.165

Comment 12 Steven Bosscher 2005-10-24 21:19:46 UTC
.