This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix ICE in tree_estimate_probability (PR tree-optimization/37879)


On Mon, Oct 27, 2008 at 8:58 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> This is ICE on undefined code, if the source is lying about noreturn,
> then an edge to exit block might have no statements at all.  Most other
> passes verify that last_stmt returned non-NULL before actually using it
> and I think that's a good thing in this case as well.
>
> Ok for trunk?

Ok.

Thanks,
Richard.

> 2008-10-27  Jakub Jelinek  <jakub@redhat.com>
>
>        PR tree-optimization/37879
>        * predict.c (tree_estimate_probability): Check if last_stmt is
>        non-NULL before dereferencing it.
>
>        * gcc.dg/pr37879.c: New test.
>
> --- gcc/predict.c.jj    2008-10-23 13:21:40.000000000 +0200
> +++ gcc/predict.c       2008-10-27 08:40:41.000000000 +0100
> @@ -1599,6 +1599,7 @@ tree_estimate_probability (void)
>     {
>       edge e;
>       edge_iterator ei;
> +      gimple last;
>
>       FOR_EACH_EDGE (e, ei, bb->succs)
>        {
> @@ -1621,7 +1622,8 @@ tree_estimate_probability (void)
>              && e->dest != EXIT_BLOCK_PTR
>              && single_succ_p (e->dest)
>              && single_succ_edge (e->dest)->dest == EXIT_BLOCK_PTR
> -             && gimple_code (last_stmt (e->dest)) == GIMPLE_RETURN)
> +             && (last = last_stmt (e->dest)) != NULL
> +             && gimple_code (last) == GIMPLE_RETURN)
>            {
>              edge e1;
>              edge_iterator ei1;
> --- gcc/testsuite/gcc.dg/pr37879.c.jj   2008-10-27 08:42:01.000000000 +0100
> +++ gcc/testsuite/gcc.dg/pr37879.c      2008-10-27 08:39:56.000000000 +0100
> @@ -0,0 +1,28 @@
> +/* PR tree-optimization/37879 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +
> +static inline void bar (int) __attribute__ ((noreturn));
> +void baz () __attribute__ ((noreturn));
> +
> +inline int
> +foo (int i)
> +{
> +  return i;
> +}
> +
> +int i = 23;
> +static inline void
> +bar (int j)
> +{
> +  if (j)
> +    asm ("");
> +}              /* { dg-warning "does return" } */
> +
> +void
> +baz ()
> +{
> +  int j;
> +  bar (foo (j = i++));
> +  asm ("");
> +}
>
>        Jakub
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]