genattrtab.c problem

Jeffrey A Law law@cygnus.com
Sun Oct 3 23:10:00 GMT 1999


This fixes the genattrtab.c memory corruption problem I pointed out a couple
days ago (sizeof rtvec != sizeof rtunion).

I'll post a patch for the ggc routines which make the same assumption shortly.

	* genattrtab.c (simplify_cond): Make TESTS an array of rtxs, instead
	of rtunions.

Index: genattrtab.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/genattrtab.c,v
retrieving revision 1.66
diff -c -3 -p -r1.66 genattrtab.c
*** genattrtab.c	1999/10/01 10:00:23	1.66
--- genattrtab.c	1999/10/04 06:06:57
*************** simplify_cond (exp, insn_code, insn_inde
*** 2531,2544 ****
    rtx defval = XEXP (exp, 1);
    rtx new_defval = XEXP (exp, 1);
    int len = XVECLEN (exp, 0);
!   rtunion *tests = (rtunion *) alloca (len * sizeof (rtunion));
    int allsame = 1;
    char *first_spacer;
  
    /* This lets us free all storage allocated below, if appropriate.  */
    first_spacer = (char *) obstack_finish (rtl_obstack);
  
!   bcopy ((char *) XVEC (exp, 0)->elem, (char *) tests, len * sizeof 
(rtunion));
  
    /* See if default value needs simplification.  */
    if (GET_CODE (defval) == COND)
--- 2531,2544 ----
    rtx defval = XEXP (exp, 1);
    rtx new_defval = XEXP (exp, 1);
    int len = XVECLEN (exp, 0);
!   rtx *tests = (rtx *) alloca (len * sizeof (rtx));
    int allsame = 1;
    char *first_spacer;
  
    /* This lets us free all storage allocated below, if appropriate.  */
    first_spacer = (char *) obstack_finish (rtl_obstack);
  
!   bcopy ((char *) XVEC (exp, 0)->elem, (char *) tests, len * sizeof (rtx));
  
    /* See if default value needs simplification.  */
    if (GET_CODE (defval) == COND)
*************** simplify_cond (exp, insn_code, insn_inde
*** 2551,2560 ****
        rtx newtest, newval;
  
        /* Simplify this test.  */
!       newtest = SIMPLIFY_TEST_EXP (tests[i].rtx, insn_code, insn_index);
!       tests[i].rtx = newtest;
  
!       newval = tests[i + 1].rtx;
        /* See if this value may need simplification.  */
        if (GET_CODE (newval) == COND)
  	newval = simplify_cond (newval, insn_code, insn_index);
--- 2551,2560 ----
        rtx newtest, newval;
  
        /* Simplify this test.  */
!       newtest = SIMPLIFY_TEST_EXP (tests[i], insn_code, insn_index);
!       tests[i] = newtest;
  
!       newval = tests[i + 1];
        /* See if this value may need simplification.  */
        if (GET_CODE (newval) == COND)
  	newval = simplify_cond (newval, insn_code, insn_index);
*************** simplify_cond (exp, insn_code, insn_inde
*** 2565,2571 ****
  	  /* If test is true, make this value the default
  	     and discard this + any following tests.  */
  	  len = i;
! 	  defval = tests[i + 1].rtx;
  	  new_defval = newval;
  	}
  
--- 2565,2571 ----
  	  /* If test is true, make this value the default
  	     and discard this + any following tests.  */
  	  len = i;
! 	  defval = tests[i + 1];
  	  new_defval = newval;
  	}
  
*************** simplify_cond (exp, insn_code, insn_inde
*** 2573,2605 ****
  	{
  	  /* If test is false, discard it and its value.  */
  	  for (j = i; j < len - 2; j++)
! 	    tests[j].rtx = tests[j + 2].rtx;
  	  len -= 2;
  	}
  
!       else if (i > 0 && attr_equal_p (newval, tests[i - 1].rtx))
  	{
  	  /* If this value and the value for the prev test are the same,
  	     merge the tests.  */
  
! 	  tests[i - 2].rtx
! 	    = insert_right_side (IOR, tests[i - 2].rtx, newtest,
  				 insn_code, insn_index);
  
  	  /* Delete this test/value.  */
  	  for (j = i; j < len - 2; j++)
! 	    tests[j].rtx = tests[j + 2].rtx;
  	  len -= 2;
  	}
  
        else
! 	tests[i + 1].rtx = newval;
      }
  
    /* If the last test in a COND has the same value
       as the default value, that test isn't needed.  */
  
!   while (len > 0 && attr_equal_p (tests[len - 1].rtx, new_defval))
      len -= 2;
  
    /* See if we changed anything.  */
--- 2573,2605 ----
  	{
  	  /* If test is false, discard it and its value.  */
  	  for (j = i; j < len - 2; j++)
! 	    tests[j] = tests[j + 2];
  	  len -= 2;
  	}
  
!       else if (i > 0 && attr_equal_p (newval, tests[i - 1]))
  	{
  	  /* If this value and the value for the prev test are the same,
  	     merge the tests.  */
  
! 	  tests[i - 2]
! 	    = insert_right_side (IOR, tests[i - 2], newtest,
  				 insn_code, insn_index);
  
  	  /* Delete this test/value.  */
  	  for (j = i; j < len - 2; j++)
! 	    tests[j] = tests[j + 2];
  	  len -= 2;
  	}
  
        else
! 	tests[i + 1] = newval;
      }
  
    /* If the last test in a COND has the same value
       as the default value, that test isn't needed.  */
  
!   while (len > 0 && attr_equal_p (tests[len - 1], new_defval))
      len -= 2;
  
    /* See if we changed anything.  */
*************** simplify_cond (exp, insn_code, insn_inde
*** 2607,2613 ****
      allsame = 0;
    else
      for (i = 0; i < len; i++)
!       if (! attr_equal_p (tests[i].rtx, XVECEXP (exp, 0, i)))
  	{
  	  allsame = 0;
  	  break;
--- 2607,2613 ----
      allsame = 0;
    else
      for (i = 0; i < len; i++)
!       if (! attr_equal_p (tests[i], XVECEXP (exp, 0, i)))
  	{
  	  allsame = 0;
  	  break;
*************** simplify_cond (exp, insn_code, insn_inde
*** 2633,2639 ****
  
        XVEC (newexp, 0) = rtvec_alloc (len);
        bcopy ((char *) tests, (char *) XVEC (newexp, 0)->elem,
! 	     len * sizeof (rtunion));
        XEXP (newexp, 1) = new_defval;
        return newexp;
      }
--- 2633,2639 ----
  
        XVEC (newexp, 0) = rtvec_alloc (len);
        bcopy ((char *) tests, (char *) XVEC (newexp, 0)->elem,
! 	     len * sizeof (rtx));
        XEXP (newexp, 1) = new_defval;
        return newexp;
      }



jeff







More information about the Gcc-patches mailing list