On Thu, 21 Nov 2019 at 13:42, Richard Biener <rguent...@suse.de> wrote:
>
> On Thu, 21 Nov 2019, Prathamesh Kulkarni wrote:
>
> > Hi,
> > The issue seems to happen with -O1, because header only contains phi:
> >
> >   <bb 3> [local count: 118111600]:
> >   # iter.12_9 = PHI <0(2), iter.12_10(10)>
> >
> > and thus we hit segfault in following hunk in find_loop_guard:
> >      else
> >         {
> >           cond = dyn_cast <gcond *> (last_stmt (header));
> >           if (! cond)
> >             return NULL;
> >           extract_true_false_edges_from_block (header, &te, &fe);
> >
> > since last_stmt (header) returns NULL.
> >
> > The attached patch, simply punts if last_stmt returns NULL, which
> > avoids the segfault.
> > Does it look OK ?
>
> Please add the testcase from the PR to gcc.dg/torture
> with dg-additional-options -funswitch-loops.
>
>        else
>         {
> -         cond = dyn_cast <gcond *> (last_stmt (header));
> +         gimple *last = last_stmt (header);
> +         if (!last)
> +           return NULL;
> +         cond = dyn_cast <gcond *> (last);
>           if (! cond)
>             return NULL;
>
> Please simply use safe_dyn_cast <gcond *> (last_stmt (header))
> which appropriately deals with a NULL input.
>
> OK with those changes.
Thanks for the suggestions, I committed the patch in r278598 with the
above changes
and verifying bootstrap+test passes on x86_64-unknown-linux-gnu.

Thanks,
Prathamesh
> Richard.

Reply via email to