Permalink
Browse files

Fix unsafe peephole optimization

  • Loading branch information...
fbogsany authored and bouk committed Nov 17, 2016
1 parent a630c4f commit 964427f82c5a8556daf4448b47cc65fb6d2a94b8
Showing with 15 additions and 2 deletions.
  1. +4 −2 mrbgems/mruby-compiler/core/codegen.c
  2. +11 −0 test/t/codegen.rb
@@ -1798,8 +1798,10 @@ codegen(codegen_scope *s, node *tree, int val)
int pos;
pop();
if (val && vsp >= 0) {
genop(s, MKOP_AB(OP_MOVE, vsp, cursp()));
if (val) {
if (vsp >= 0) {
genop(s, MKOP_AB(OP_MOVE, vsp, cursp()));
}
pos = genop(s, MKOP_AsBx(name[0]=='|'?OP_JMPIF:OP_JMPNOT, cursp(), 0));
}
else {
View
@@ -0,0 +1,11 @@
##
# Codegen tests
assert('peephole optimization does not eliminate move whose result is reused') do
assert_raise LocalJumpError do
def method
yield
end
method(&a &&= 0)
end
end

0 comments on commit 964427f

Please sign in to comment.