Andrew Pinski <quic_apin...@quicinc.com> writes:
> reuse_rtx is not documented nor the format to use it is ever documented.
> So it should not be supported for the .md files.
>
> This also fixes the problem if an invalid index is supplied for reuse_rtx,
> instead of ICEing, put out a real error message.  Note since this code
> still uses atoi, an invalid index can still be used in some cases but that is
> recorded as part of PR 44574.
>
> Note I did a grep of the sources to make sure that this was only used for
> the read rtl in the GCC rather than while reading in .md files.
>
> Bootstrapped and tested on x86_64-linux-gnu.
>
> gcc/ChangeLog:
>
>       * read-md.h (class rtx_reader): Don't include m_reuse_rtx_by_id
>       when GENERATOR_FILE is defined.
>       * read-rtl.cc (rtx_reader::read_rtx_code): Disable reuse_rtx
>       support when GENERATOR_FILE is defined.

OK, thanks.

Richard

>
> Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>
> ---
>  gcc/read-md.h   | 2 ++
>  gcc/read-rtl.cc | 9 +++++++--
>  2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/read-md.h b/gcc/read-md.h
> index 9703551a8fd..e613c42b724 100644
> --- a/gcc/read-md.h
> +++ b/gcc/read-md.h
> @@ -364,8 +364,10 @@ class rtx_reader : public md_reader
>    /* Analogous to rtx_writer's m_in_call_function_usage.  */
>    bool m_in_call_function_usage;
>  
> +#ifndef GENERATOR_FILE
>    /* Support for "reuse_rtx" directives.  */
>    auto_vec<rtx> m_reuse_rtx_by_id;
> +#endif
>  };
>  
>  /* Global singleton; constrast with md_reader_ptr above.  */
> diff --git a/gcc/read-rtl.cc b/gcc/read-rtl.cc
> index bfce806f9d6..630f9c59c37 100644
> --- a/gcc/read-rtl.cc
> +++ b/gcc/read-rtl.cc
> @@ -1672,7 +1672,6 @@ rtx_reader::read_rtx_code (const char *code_name)
>    struct md_name name;
>    rtx return_rtx;
>    int c;
> -  long reuse_id = -1;
>  
>    /* Linked list structure for making RTXs: */
>    struct rtx_list
> @@ -1681,6 +1680,8 @@ rtx_reader::read_rtx_code (const char *code_name)
>        rtx value;             /* Value of this node.  */
>      };
>  
> +#ifndef GENERATOR_FILE
> +  long reuse_id = -1;
>    /* Handle reuse_rtx ids e.g. "(0|scratch:DI)".  */
>    if (ISDIGIT (code_name[0]))
>      {
> @@ -1696,10 +1697,12 @@ rtx_reader::read_rtx_code (const char *code_name)
>        read_name (&name);
>        unsigned idx = atoi (name.string);
>        /* Look it up by ID.  */
> -      gcc_assert (idx < m_reuse_rtx_by_id.length ());
> +      if (idx >= m_reuse_rtx_by_id.length ())
> +     fatal_with_file_and_line ("invalid reuse index %u", idx);
>        return_rtx = m_reuse_rtx_by_id[idx];
>        return return_rtx;
>      }
> +#endif
>  
>    /* Handle "const_double_zero".  */
>    if (strcmp (code_name, "const_double_zero") == 0)
> @@ -1727,12 +1730,14 @@ rtx_reader::read_rtx_code (const char *code_name)
>    memset (return_rtx, 0, RTX_CODE_SIZE (code));
>    PUT_CODE (return_rtx, code);
>  
> +#ifndef GENERATOR_FILE
>    if (reuse_id != -1)
>      {
>        /* Store away for later reuse.  */
>        m_reuse_rtx_by_id.safe_grow_cleared (reuse_id + 1, true);
>        m_reuse_rtx_by_id[reuse_id] = return_rtx;
>      }
> +#endif
>  
>    /* Check for flags. */
>    read_flags (return_rtx);

Reply via email to