1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* compile.c (compile_array_): modify wrong optimization.

A script "[print(1)]; print(2)" should output "12".
  However, the compiler had eliminted "[print(1)]" expression
  because it is void expression (unused array).
  Of course, side-effect should be remained.
  This issue is reported by Masaya Tarui.
* bootstraptest/test_literal.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2013-01-09 18:38:41 +00:00
parent 62efc6f305
commit a5e2f3221a
3 changed files with 21 additions and 0 deletions

View file

@ -1,3 +1,14 @@
Thu Jan 10 03:29:55 2013 Koichi Sasada <ko1@atdot.net>
* compile.c (compile_array_): modify wrong optimization.
A script "[print(1)]; print(2)" should output "12".
However, the compiler had eliminted "[print(1)]" expression
because it is void expression (unused array).
Of course, side-effect should be remained.
This issue is reported by Masaya Tarui.
* bootstraptest/test_literal.rb: add a test.
Wed Jan 9 22:07:42 2013 Masaki Matsushita <glass.saga@gmail.com> Wed Jan 9 22:07:42 2013 Masaki Matsushita <glass.saga@gmail.com>
* load.c (load_lock): if thread shield is destroyed and there is no * load.c (load_lock): if thread shield is destroyed and there is no

View file

@ -224,3 +224,8 @@ assert_equal 'ok', %q{ # long hash literal (optimized)
eval "a = {#{(1..10_000).map{|n| "#{n} => #{n}"}.join(', ')}}" eval "a = {#{(1..10_000).map{|n| "#{n} => #{n}"}.join(', ')}}"
:ok :ok
} }
assert_equal 'ok', %q{
[print(:ok), exit] # void literal with side-effect
:dummy
}

View file

@ -2435,6 +2435,7 @@ compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
else { else {
ADD_INSN(anchor, line, concatarray); ADD_INSN(anchor, line, concatarray);
} }
APPEND_LIST(ret, anchor); APPEND_LIST(ret, anchor);
break; break;
case COMPILE_ARRAY_TYPE_HASH: case COMPILE_ARRAY_TYPE_HASH:
@ -2461,6 +2462,10 @@ compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
break; break;
} }
} }
else {
/* poped */
APPEND_LIST(ret, anchor);
}
} }
} }
} }