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.
Richard.