diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-26 16:58:40 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-09-26 16:58:40 +0900 |
| commit | 368e8ce3d5fc117081316aefa25a40b3b1f7a5a9 (patch) | |
| tree | 2c2b2a362ee3bdad59f6837e0f3b5176b90bddd9 | |
| parent | 89ea41f15e92006051d443b29b6e8e32f11c68bc (diff) | |
| download | mruby-368e8ce3d5fc117081316aefa25a40b3b1f7a5a9.tar.gz mruby-368e8ce3d5fc117081316aefa25a40b3b1f7a5a9.zip | |
codegen.c: should not `loop_push()` before constant folding.
Otherwise, the following code will crash:
```ruby
1.times{{}until 1; break}
```
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index c04c408ed..42c93debf 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -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) { @@ -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) { |
