[PATCH?,4.7,regression] Crash in ira-costs.c with -fschedule-insns -fsched-pressure -fdump-rtl-sched1

Submitted by Ulrich Weigand on Feb. 14, 2012, 5 p.m.

Details

Message ID 201202141700.q1EH07hJ000850@d06av02.portsmouth.uk.ibm.com
State New
Headers show

Commit Message

Ulrich Weigand Feb. 14, 2012, 5 p.m.
Hello,

compiling anything, even just an empty function, with
  -fschedule-insns -fsched-pressure -fdump-rtl-sched1
causes the compiler to crash:

Program received signal SIGSEGV, Segmentation fault.
0x0840d9e0 in REG_N_REFS (regno=58) at ../../gcc-head/gcc/regs.h:75
75        return regstat_n_sets_and_refs[regno].refs;
(gdb) bt
#0  0x0840d9e0 in REG_N_REFS (regno=58) at ../../gcc-head/gcc/regs.h:75
#1  0x08411120 in print_pseudo_costs (f=0x8e3fad0) at ../../gcc-head/gcc/ira-costs.c:1433
#2  0x08412046 in find_costs_and_classes (dump_file=0x8e3fad0) at ../../gcc-head/gcc/ira-costs.c:1806
#3  0x084129f2 in ira_set_pseudo_classes (dump_file=0x8e3fad0) at ../../gcc-head/gcc/ira-costs.c:2067
#4  0x089a9f08 in sched_init () at ../../gcc-head/gcc/haifa-sched.c:4838

This is because sched_init calls ira_set_pseudo_classes without having
called regstat_init_n_sets_and_refs first, but the latter is a prerequisite
for using REG_N_REFS.  All other callers of ira_set_pseudo_classes seem to
initialize the regstat array first.

This is fixed by the following patch.  However, I'm not quite sure if this is
the best way to fix the problem, given that the REG_N_REFS use occurs only for
debug output purposes -- should we actually do the work to compute the regstat
array just for that, or can print_pseudo_costs be changed instead?

Bye,
Ulrich


ChangeLog:

	* haifa-sched.c (sched_init): Call regstat_init_n_sets_and_refs and
	regstat_free_n_sets_and_refs before/after ira_set_pseudo_classes call.

Comments

Vladimir Makarov Feb. 15, 2012, 5:48 p.m.
On 02/14/2012 12:00 PM, Ulrich Weigand wrote:
> Hello,
>
> compiling anything, even just an empty function, with
>    -fschedule-insns -fsched-pressure -fdump-rtl-sched1
> causes the compiler to crash:
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x0840d9e0 in REG_N_REFS (regno=58) at ../../gcc-head/gcc/regs.h:75
> 75        return regstat_n_sets_and_refs[regno].refs;
> (gdb) bt
> #0  0x0840d9e0 in REG_N_REFS (regno=58) at ../../gcc-head/gcc/regs.h:75
> #1  0x08411120 in print_pseudo_costs (f=0x8e3fad0) at ../../gcc-head/gcc/ira-costs.c:1433
> #2  0x08412046 in find_costs_and_classes (dump_file=0x8e3fad0) at ../../gcc-head/gcc/ira-costs.c:1806
> #3  0x084129f2 in ira_set_pseudo_classes (dump_file=0x8e3fad0) at ../../gcc-head/gcc/ira-costs.c:2067
> #4  0x089a9f08 in sched_init () at ../../gcc-head/gcc/haifa-sched.c:4838
>
> This is because sched_init calls ira_set_pseudo_classes without having
> called regstat_init_n_sets_and_refs first, but the latter is a prerequisite
> for using REG_N_REFS.  All other callers of ira_set_pseudo_classes seem to
> initialize the regstat array first.
>
> This is fixed by the following patch.  However, I'm not quite sure if this is
> the best way to fix the problem, given that the REG_N_REFS use occurs only for
> debug output purposes -- should we actually do the work to compute the regstat
> array just for that, or can print_pseudo_costs be changed instead?
>
>
Sorry, Ulrich.  I am afraid that you missed my message about solving 
this PR two week ago.

http://gcc.gnu.org/ml/gcc-patches/2012-02/msg00101.html

> ChangeLog:
>
> 	* haifa-sched.c (sched_init): Call regstat_init_n_sets_and_refs and
> 	regstat_free_n_sets_and_refs before/after ira_set_pseudo_classes call.
>
>
> === modified file 'gcc/haifa-sched.c'
> --- gcc/haifa-sched.c	2012-02-11 01:34:30 +0000
> +++ gcc/haifa-sched.c	2012-02-14 16:41:47 +0000
> @@ -6281,7 +6281,9 @@
>       {
>         int i, max_regno = max_reg_num ();
>
> +      regstat_init_n_sets_and_refs ();
>         ira_set_pseudo_classes (sched_verbose ? sched_dump : NULL);
> +      regstat_free_n_sets_and_refs ();
>         sched_regno_pressure_class
>   	= (enum reg_class *) xmalloc (max_regno * sizeof (enum reg_class));
>         for (i = 0; i<  max_regno; i++)
>
>

Patch hide | download patch | download mbox

=== modified file 'gcc/haifa-sched.c'
--- gcc/haifa-sched.c	2012-02-11 01:34:30 +0000
+++ gcc/haifa-sched.c	2012-02-14 16:41:47 +0000
@@ -6281,7 +6281,9 @@ 
     {
       int i, max_regno = max_reg_num ();
 
+      regstat_init_n_sets_and_refs ();
       ira_set_pseudo_classes (sched_verbose ? sched_dump : NULL);
+      regstat_free_n_sets_and_refs ();
       sched_regno_pressure_class
 	= (enum reg_class *) xmalloc (max_regno * sizeof (enum reg_class));
       for (i = 0; i < max_regno; i++)