Bug 18718 - [4.0 Regression] ICE: Segmentation fault in in schedule_region (rgn=0) at sched-rgn.c:2325
Summary: [4.0 Regression] ICE: Segmentation fault in in schedule_region (rgn=0) at sch...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Alan Modra
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2004-11-29 15:46 UTC by Michael Cieslinski
Modified: 2004-12-03 23:55 UTC (History)
1 user (show)

See Also:
Host: powerpc-unknown-linux-gnu
Target: powerpc-unknown-linux-gnu
Build: powerpc-unknown-linux-gnu
Known to work: 3.3.2 3.4.4
Known to fail: 4.0.0
Last reconfirmed: 2004-11-29 16:20:23


Attachments
preprocessed source (70.30 KB, text/plain)
2004-11-29 15:48 UTC, Michael Cieslinski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Cieslinski 2004-11-29 15:46:29 UTC
I compiled ACE 5.4.2 with the actual snapshot and got a segfault.

GCC was compiled with CFLAGS="-pipe -g -O3 -mcpu=G5 -maltivec -mabi=altivec -
fmessage-length=0 -falign-loops=16 -falign-jumps=16 -falign-functions=32 -
fstrict-aliasing -fsched-interblock -ffast-math -funroll-all-loops -funit-at-a-
time -fpeel-loops -ftracer -funswitch-loops -floop-optimize2 -fmove-loop-
invariants -fgcse-after-reload -frename-registers -fmodulo-sched --param max-
gcse-passes=5 --param max-unrolled-insns=600 --param inline-unit-growth=300 --
param large-function-growth=400"

Michael Cieslinski



g++40 -pipe -O2 -funroll-all-loops -ftracer -c -o SAXPrint_Handler.o 
SAXPrint_Handler.ii -v
Reading specs from /usr/local/gcc40b/lib/gcc/powerpc-unknown-linux-
gnu/4.0.0/specs
Configured with: ../gcc40/configure --prefix=/usr/local/gcc40b --program-
suffix=40b --with-cpu=G5 --enable-altivec --enable-languages=c,c++ --enable-
checking
Thread model: posix
gcc version 4.0.0 20041128 (experimental)
 /usr/local/gcc40b/libexec/gcc/powerpc-unknown-linux-gnu/4.0.0/cc1plus -
fpreprocessed SAXPrint_Handler.ii -quiet -dumpbase SAXPrint_Handler.ii -
mcpu=G5 -auxbase-strip SAXPrint_Handler.o -O2 -version -funroll-all-loops -
ftracer -o - |
 as -mpower4 -maltivec -many -V -Qy -o SAXPrint_Handler.o -
GNU assembler version 2.15.90 (ppc-redhat-linux) using BFD version 2.15.90 
20040225
GNU C++ version 4.0.0 20041128 (experimental) (powerpc-unknown-linux-gnu)
        compiled by GNU C version 4.0.0 20041128 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
SAXPrint_Handler.cpp: In member function 'void 
ACEXML_SAXPrint_Handler::print_indent()':
SAXPrint_Handler.cpp:244: internal compiler error: Segmentation fault
Please submit a full bug report, with preprocessed source if appropriate.


Running cc1plus in GDB:

Program received signal SIGSEGV, Segmentation fault.
0x105218b0 in schedule_region (rgn=0) at ../../gcc40/gcc/sched-rgn.c:2325
2325              for (note = REG_NOTES (head); note; note = XEXP (note, 1))

(gdb) bt
#0  0x105218b0 in schedule_region (rgn=0) at ../../gcc40/gcc/sched-rgn.c:2325
#1  0x105236fc in schedule_insns (dump_file=Variable "dump_file" is not 
available.
) at ../../gcc40/gcc/sched-rgn.c:2493
#2  0x1046dac4 in rest_of_compilation () at ../../gcc40/gcc/passes.c:651
#3  0x1018460c in execute_pass_list (pass=0x106fce80) at ../../gcc40/gcc/tree-
optimize.c:511
#4  0x101849f8 in tree_rest_of_compilation (fndecl=0x30b99000) 
at ../../gcc40/gcc/tree-optimize.c:647
#5  0x100f72fc in expand_body (fn=0x30b99000) 
at ../../gcc40/gcc/cp/semantics.c:2895
#6  0x104995e0 in cgraph_expand_function (node=0x30ba8200) 
at ../../gcc40/gcc/cgraphunit.c:822
#7  0x1049a684 in cgraph_optimize () at ../../gcc40/gcc/cgraphunit.c:1689
#8  0x10092af0 in cp_finish_file () at ../../gcc40/gcc/cp/decl2.c:3070
#9  0x100017a0 in finish_file () at ../../gcc40/gcc/cp/cp-lang.c:113
#10 0x101547f4 in c_common_parse_file (set_yydebug=Variable "set_yydebug" is 
not available.
) at ../../gcc40/gcc/c-opts.c:1093
#11 0x1043a4f8 in toplev_main (argc=Variable "argc" is not available.
) at ../../gcc40/gcc/toplev.c:992
#12 0x10160be0 in main (argc=Variable "argc" is not available.
) at ../../gcc40/gcc/main.c:35
Comment 1 Michael Cieslinski 2004-11-29 15:48:08 UTC
Created attachment 7632 [details]
preprocessed source
Comment 2 Andrew Pinski 2004-11-29 16:14:39 UTC
Reduced to:
typedef long unsigned int size_t;
struct ACEXML_SAXPrint_Handler
{
  void print_indent ();
  size_t indent_;
};
int f();
void
ACEXML_SAXPrint_Handler::print_indent (void)
{
  for (size_t i = 0; i < this->indent_; ++i)
      f ();
}
Comment 3 Andrew Pinski 2004-11-29 16:20:23 UTC
g++ pr18718.cc -O3 -funroll-all-loops -ftracer

Confirmed.
Comment 4 Andrew Pinski 2004-11-29 16:55:14 UTC
hmm, the loop looks right:
	  for (note = REG_NOTES (head); note; note = XEXP (note, 1))
	    if (REG_NOTE_KIND (note) == REG_SAVE_NOTE)

Maybe we are miscompiling sched-regn.c.
Comment 5 Andrew Pinski 2004-11-29 18:11:22 UTC
No we get this even when the compiler is compiled with -O0.
There is only one reg note which is causing this seg fault:
(expr_list:REG_SAVE_NOTE (const_int -94 [0xffffffffffffffa2])
        (nil))
Comment 6 Alan Modra 2004-11-30 03:25:30 UTC
Obviously, the loop expects REG_SAVE_NOTEs in pairs, which it isn't getting,
hence the segfault.

This is because the function that adds these notes, sched_analyze, is being
called on basic blocks, and the NOTE_INSN_LOOP_BEG/END pair isn't in the same
basic block.  Smell like bit rot.

;; End of basic block 2, registers live:
 1 [1] 31 [31] 67 [ap] 123 124

(note:HI 48 22 23 NOTE_INSN_LOOP_BEG)

;; Start of basic block 3, registers live: 1 [1] 31 [31] 67 [ap] 123 124
(code_label:HI 23 48 24 3 4 "" [1 uses])

[snip]

;; Start of basic block 4, registers live: 1 [1] 31 [31] 67 [ap] 122 124
[snip]

(note:HI 49 34 63 4 NOTE_INSN_LOOP_END)

[snip]
Comment 7 Alan Modra 2004-11-30 03:57:06 UTC
Hmm, no, that's not quite right.  It's nothing to do with the loop begin/end
note needing to be recognized in the same analysis pass, but rather that older
code emitted two REG_SAVE_NOTEs on each occurence of various other notes.  See
the corresponding code in gcc-3.4.
Comment 8 Andrew Pinski 2004-11-30 04:47:55 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-11/msg02654.html>.
Comment 9 Steven Bosscher 2004-11-30 12:44:37 UTC
My bad, I guess.  See http://gcc.gnu.org/ml/gcc-patches/2004-11/msg01357.html.
Comment 10 Steven Bosscher 2004-12-03 11:42:55 UTC
The same problem exists in sched-ebb.c, see
http://gcc.gnu.org/ml/gcc-patches/2004-12/msg00260.html
Comment 11 Alan Modra 2004-12-03 23:05:54 UTC
Fixed both sched-ebb.c and sched-rgn.c
Comment 12 Alan Modra 2004-12-03 23:55:28 UTC
Um, middle-end spelled wrongly in the log, so adding this by hand

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	amodra@gcc.gnu.org	2004-12-03 23:02:33

Modified files:
	gcc            : ChangeLog sched-rgn.c sched-ebb.c 

Log message:
	PR middle end/18718
	* sched-rgn.c (schedule_region): Don't assume REG_SAVE_NOTEs are
	in pairs.
	* sched-ebb.c (schedule_ebb): Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6705&r2=2.6706
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/sched-rgn.c.diff?cvsroot=gcc&r1=1.87&r2=1.88
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/sched-ebb.c.diff?cvsroot=gcc&r1=1.41&r2=1.42