On Sat, Mar 6, 2021 at 7:59 AM Henrik Grubbström (Lysator) @ Pike (-)
developers forum <10353(a)lyskom.lysator.liu.se> wrote:
>
> > Playing around with generators, and have come across a strange oddity.
> > This code works fine:
> [...]
> > But remove any of the 'if' guards, and the function terminates prematurely.
> >
> > continue int gen(int x)
> > {
> > if (x == 1) continue return 1;
> > continue return 2;
> > if (x == 1) continue return 3;
> > return 4;
> > }
> >
> > This will print out 1, 2, 0, and then halt. It appears that perhaps an
> > unconditional 'continue return' causes subsequent code to be
> > eliminated as if following a hard 'return' statement?
>
> Indeed. Looks like it is probably a bug in treeopt, where there's
> likely some rule that doesn't know about continue return.
Thanks for the pointer! Found it, I think. I've pushed it to the
branch rosuav/deoptimize-continue-return - would appreciate a second
opinion on this!
-F_COMMA_EXPR(0 = F_COMMA_EXPR(*, F_RETURN), +[!($$->tree_info & OPT_CASE)]):
+// Code after a return statement can be eliminated, as long as
+// it's not a 'continue return' statement.
+F_COMMA_EXPR(0 = F_COMMA_EXPR(*, F_RETURN(*,
F_CONSTANT[!($$->u.sval.u.integer)])),
+ +[!($$->tree_info & OPT_CASE)]):
$0;
ChrisA