Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
codegen.c: should not loop_push() before constant folding.
Otherwise, the following code will crash:

```ruby
1.times{{}until 1; break}
```
  • Loading branch information
matz committed Sep 26, 2021
1 parent 89ea41f commit 368e8ce
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions mrbgems/mruby-compiler/core/codegen.c
Expand Up @@ -2263,11 +2263,6 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_WHILE:
case NODE_UNTIL:
{
struct loopinfo *lp = loop_push(s, LOOP_NORMAL);
uint32_t pos = JMPLINK_START;

if (!val) lp->reg = -1;
lp->pc0 = new_label(s);
if (true_always(tree->car)) {
if (nt == NODE_UNTIL) {
if (val) {
Expand All @@ -2286,6 +2281,12 @@ codegen(codegen_scope *s, node *tree, int val)
goto exit;
}
}

uint32_t pos = JMPLINK_START;
struct loopinfo *lp = loop_push(s, LOOP_NORMAL);

if (!val) lp->reg = -1;
lp->pc0 = new_label(s);
codegen(s, tree->car, VAL);
pop();
if (nt == NODE_WHILE) {
Expand Down

0 comments on commit 368e8ce

Please sign in to comment.