diff mbox

FIx a valgrind reported issue in build tools (PR other/58712)

Message ID 20140128224823.GR892@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Jan. 28, 2014, 10:48 p.m. UTC
Hi!

I've started an --enable-checking=valgrind bootstrap during the weekend,
but only on Sunday afternoon and thus killed it on Monday morning, so it
didn't get very far, but still reported a problem where the build tools
had uninitialized memory use in copy_rtx:
    case CLOBBER:
      /* Share clobbers of hard registers (like cc0), but do not share
       * pseudo reg
         clobbers or clobbers of hard registers that originated as pseudos.
         This is needed to allow safe register renaming.  */
      if (REG_P (XEXP (orig, 0)) && REGNO (XEXP (orig, 0)) < FIRST_PSEUDO_REGISTER
          && ORIGINAL_REGNO (XEXP (orig, 0)) == REGNO (XEXP (orig, 0)))
        return orig;
- ORIGINAL_REGNO was uninitialized.  The problem is that read_rtx_code uses
rtx_alloc, which clears only the first int in the structure (header), and
then ignores the fields with 0 format character.  For ORIGINAL_REGNO, we
want to set it to REGNO, for others IMHO it is best to just clear those
fields.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2014-01-28  Jakub Jelinek  <jakub@redhat.com>

	PR other/58712
	* read-rtl.c (read_rtx_code): Clear all of RTX_CODE_SIZE (code).
	For REGs set ORIGINAL_REGNO.


	Jakub

Comments

Richard Biener Jan. 29, 2014, 9:49 a.m. UTC | #1
On Tue, Jan 28, 2014 at 11:48 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> I've started an --enable-checking=valgrind bootstrap during the weekend,
> but only on Sunday afternoon and thus killed it on Monday morning, so it
> didn't get very far, but still reported a problem where the build tools
> had uninitialized memory use in copy_rtx:
>     case CLOBBER:
>       /* Share clobbers of hard registers (like cc0), but do not share
>        * pseudo reg
>          clobbers or clobbers of hard registers that originated as pseudos.
>          This is needed to allow safe register renaming.  */
>       if (REG_P (XEXP (orig, 0)) && REGNO (XEXP (orig, 0)) < FIRST_PSEUDO_REGISTER
>           && ORIGINAL_REGNO (XEXP (orig, 0)) == REGNO (XEXP (orig, 0)))
>         return orig;
> - ORIGINAL_REGNO was uninitialized.  The problem is that read_rtx_code uses
> rtx_alloc, which clears only the first int in the structure (header), and
> then ignores the fields with 0 format character.  For ORIGINAL_REGNO, we
> want to set it to REGNO, for others IMHO it is best to just clear those
> fields.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

Ok.

Thanks,
Richard.

> 2014-01-28  Jakub Jelinek  <jakub@redhat.com>
>
>         PR other/58712
>         * read-rtl.c (read_rtx_code): Clear all of RTX_CODE_SIZE (code).
>         For REGs set ORIGINAL_REGNO.
>
> --- gcc/read-rtl.c.jj   2014-01-03 11:40:57.000000000 +0100
> +++ gcc/read-rtl.c      2014-01-27 10:01:44.154527266 +0100
> @@ -1131,6 +1131,7 @@ read_rtx_code (const char *code_name)
>    /* If we end up with an insn expression then we free this space below.  */
>    return_rtx = rtx_alloc (code);
>    format_ptr = GET_RTX_FORMAT (code);
> +  memset (return_rtx, 0, RTX_CODE_SIZE (code));
>    PUT_CODE (return_rtx, code);
>
>    if (iterator)
> @@ -1154,6 +1155,8 @@ read_rtx_code (const char *code_name)
>         /* 0 means a field for internal use only.
>            Don't expect it to be present in the input.  */
>        case '0':
> +       if (code == REG)
> +         ORIGINAL_REGNO (return_rtx) = REGNO (return_rtx);
>         break;
>
>        case 'e':
>
>         Jakub
diff mbox

Patch

--- gcc/read-rtl.c.jj	2014-01-03 11:40:57.000000000 +0100
+++ gcc/read-rtl.c	2014-01-27 10:01:44.154527266 +0100
@@ -1131,6 +1131,7 @@  read_rtx_code (const char *code_name)
   /* If we end up with an insn expression then we free this space below.  */
   return_rtx = rtx_alloc (code);
   format_ptr = GET_RTX_FORMAT (code);
+  memset (return_rtx, 0, RTX_CODE_SIZE (code));
   PUT_CODE (return_rtx, code);
 
   if (iterator)
@@ -1154,6 +1155,8 @@  read_rtx_code (const char *code_name)
 	/* 0 means a field for internal use only.
 	   Don't expect it to be present in the input.  */
       case '0':
+	if (code == REG)
+	  ORIGINAL_REGNO (return_rtx) = REGNO (return_rtx);
 	break;
 
       case 'e':