diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | insns.def | 2 | ||||
-rw-r--r-- | test/ruby/test_optimization.rb | 11 |
3 files changed, 18 insertions, 1 deletions
@@ -1,3 +1,9 @@ +Fri Dec 11 17:59:05 2015 Eric Wong <e@80x24.org> + + * insns.def (opt_case_dispatch): avoid converting Infinity + * test/ruby/test_optimization.rb (test_opt_case_dispatch_inf): new + [ruby-dev:49423] [Bug #11804]' + Fri Dec 11 16:48:57 2015 Eric Wong <e@80x24.org> * hash.c (rb_num_hash_start): avoid pathological behavior @@ -1262,7 +1262,7 @@ opt_case_dispatch switch(TYPE(key)) { case T_FLOAT: { double ival; - if (modf(RFLOAT_VALUE(key), &ival) == 0.0) { + if (modf(RFLOAT_VALUE(key), &ival) == 0.0 && !isinf(ival)) { key = FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival); } } diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index 1c50044f7f..3573d1267f 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -362,4 +362,15 @@ class TestRubyOptimization < Test::Unit::TestCase assert_redefine_method(k, '===', "assert_equal(#{v.inspect} === 0, 0)") end end + + def test_opt_case_dispatch_inf + inf = 1.0/0.0 + result = case inf + when 1 then 1 + when 0 then 0 + else + inf.to_i rescue nil + end + assert_nil result, '[ruby-dev:49423] [Bug #11804]' + end end |