recog_data bug in regclass found by SunOS4 build

Jim Wilson wilsonATcygnus.com
Tue Sep 14 13:30:00 GMT 1999


An attempt to build a native SunOS4 compiler failed with a segfault while
building the eh module in libgcc2.c.

The problem is that recog_data.n_operands was zero.  It is an unsigned char,
so subtracting one gives a large positive number, and we eventually try to
dereference a null pointer.
	
Casting to int solves this problem, but you might want to check to see if
the same problem exists elsewhere.

Tue Sep 14 13:25:30 1999  Jim Wilson  <wilson@cygnus.com>

	* regclass.c (scan_one_insn): Cast recog_data.n_operands to int
	before subtracting one from it.

Index: regclass.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/regclass.c,v
retrieving revision 1.58
diff -p -r1.58 regclass.c
*** regclass.c	1999/09/12 01:51:01	1.58
--- regclass.c	1999/09/14 20:25:24
*************** scan_one_insn (insn, pass)
*** 899,907 ****
  
    /* Check for commutative in a separate loop so everything will
       have been initialized.  We must do this even if one operand
!      is a constant--see addsi3 in m68k.md.  */
  
!   for (i = 0; i < recog_data.n_operands - 1; i++)
      if (constraints[i][0] == '%')
        {
  	const char *xconstraints[MAX_RECOG_OPERANDS];
--- 899,910 ----
  
    /* Check for commutative in a separate loop so everything will
       have been initialized.  We must do this even if one operand
!      is a constant--see addsi3 in m68k.md.
  
!      recog_data.n_operands is unsigned char, so we cast to int so that 0 - 1
!      gives -1 instead of a very large positive integer.  */
! 
!   for (i = 0; i < (int) recog_data.n_operands - 1; i++)
      if (constraints[i][0] == '%')
        {
  	const char *xconstraints[MAX_RECOG_OPERANDS];


More information about the Gcc-bugs mailing list